Highlighted
Contributor
Contributor

Get-EsxCli in pyvmomi

Jump to solution

Hello,

I'm porting in Python a powershell script.

 

This is the snippet:

   $DSs = $VMHost | Get-Datastore
   $esxcli = Get-EsxCli -VMhost $VMHost
   foreach ($DS in $DSs){
      $tempview = $DS | Get-View
      $diskname = $tempview.Info.vmfs.Extent.Diskname
      $accSup = $esxcli.storage.core.device.vaai.status.get() | Where-Object -Property Device -In ($diskname)
      $ATSst = $accSup.ATSStatus
      $Clonest = $accSup.CloneStatus
      $Delst = $accSup.DeleteStatus
      $Zerost = $accSup.ZeroStatus
      $DSName = $tempview.Name
      $FSType = $tempview.Info.vmfs.type
      $FSver = $tempview.Info.vmfs.version
      $Esxiname = $VMHost.Name

 

I don't know in pyvmomi how to code Get-EsxCli and get those esxi parameters. 

I need help

Riccardo

1 Solution

Accepted Solutions
Highlighted
Contributor
Contributor

However I solved in this way

Installed locally

https://code.vmware.com/web/tool/6.7u2/esxcli

And then used a system call to execute the call

 

from subprocess import check_output, CalledProcessError, STDOUT

full_command_array = ["env", "VI_USERNAME=" + decodeduser, "VI_PASSWORD=" + decodedpass,
                      "esxcli" + "-" + _vcenter_node["version"],
                      "--server=" + _vcenter_node["host"],
                      "--vihost=" + _vihost,
                      "--thumbprint="+ _vcenter_node["thumbprint"],
                      "--formatter=" + _formatter,
                      command ]

output = check_output(full_command_array, stderr=STDOUT).decode()

 

View solution in original post

5 Replies
Highlighted
VMware Employee
VMware Employee

Moderator: Moved to PowerCLI Discussions, although this may need to go into one of the {code} forums


Forum Usage Guidelines: https://communities.vmware.com/docs/DOC-12286
VMware Training & Certification blog: http://vmwaretraining.blogspot.com
0 Kudos
Highlighted
User Moderator
User Moderator

This belongs in the Phyton community


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Enthusiast
Enthusiast

Does the silence mean there's no `vSphere Web Services` coverage for `esxcli` ?

0 Kudos
Highlighted
User Moderator
User Moderator

No, it means your Python question was located in the PowerCLI community.
Where there aren't many Python users present I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Contributor
Contributor

However I solved in this way

Installed locally

https://code.vmware.com/web/tool/6.7u2/esxcli

And then used a system call to execute the call

 

from subprocess import check_output, CalledProcessError, STDOUT

full_command_array = ["env", "VI_USERNAME=" + decodeduser, "VI_PASSWORD=" + decodedpass,
                      "esxcli" + "-" + _vcenter_node["version"],
                      "--server=" + _vcenter_node["host"],
                      "--vihost=" + _vihost,
                      "--thumbprint="+ _vcenter_node["thumbprint"],
                      "--formatter=" + _formatter,
                      command ]

output = check_output(full_command_array, stderr=STDOUT).decode()

 

View solution in original post