VMware {code} Community
RiccardoR1979
Contributor
Contributor
Jump to solution

Get-EsxCli in pyvmomi

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
RiccardoR1979
Contributor
Contributor
Jump to solution

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
scott28tt
VMware Employee
VMware Employee
Jump to solution

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


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

This belongs in the Phyton community


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

Reply
0 Kudos
evilensky
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
RiccardoR1979
Contributor
Contributor
Jump to solution

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()