Python how to operate VMware Workstation/Esxi

In the process of automated testing, use the command line operation of virtual machine is it is quite common for things, want to say here is to use Python language to operate the virtual machine, in order to achieve the purpose of automation.

As we all know, the official VMware vmrun.exe tools on the command line, we can run in vmrun such as the clone command, which reminds us to run the CMD command in Python, call vmrun to complete the virtual machine operating related. On the vmrun operating instructions can reference VMware official VIX API document.

PySphere: PySphere is platform independent and works with python, PySphere can interact with ESX, ESXi, Virtual Center, Virtual Server, And it should work with any other VMWare product exposing the vSphere Web Services SDK. (download here)

The process of installation and other three party Python style is consistent, do not know can refer to the. Due to the work of the main utility Esxi, so the focus here on the use of PySphere, we define a class, here and share, I post code: