How to get VmWare Workstation VM using Python PySphere
Update: The problem still exists even if I try to create Shared VMs and change the location of these VMs.
I am stuck trying to get to a virtual machine located in D:\VMs\CentOS-Backup\CentOS-Secondary-Server.vmx
using PySphere .
Could you help me?
Everything I have tried so far:
from pysphere import VIServer
server = VIServer()
server.connect("127.0.0.1", "my_system_login", "my_system_password")
# prints 'VMware Workstation'
print server.get_server_type()
# prints '5.1'
print server.get_api_version()
# Exception
vm = server.get_vm_by_path(r"D:\VMs\CentOS-Backup\CentOS-Secondary-Server.vmx")
vm.power_on()
The mentioned exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7\helpers\pydev\pydevd.py", line 1473, in <module>
debugger.run(setup['file'], None, None)
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7\helpers\pydev\pydevd.py", line 1117, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "D:/Projects/PyUnitTesting/pyunittest/launcher.py", line 13, in <module>
vm = server.get_vm_by_path(r"D:\VMs\CentOS-Backup\CentOS-Secondary-Server.vmx")
File "C:\dev\Python27\lib\site-packages\pysphere\vi_server.py", line 291, in get_vm_by_path
FaultTypes.OBJECT_NOT_FOUND)
pysphere.resources.vi_exception.VIException: [Object Not Found]: Could not find a VM with path 'D:\VMs\CentOS-Backup\CentOS-Secondary-Server.vmx'
Please note that I have installed the VIX API . But didn't do any specific PATH additions. Could you give me a hint if I really need to do this?
Thank!
+3
source to share
2 answers
According to the docs, I don't think you should be supplying the raw file path to the VM. I think there is an internal meaning to the path:
http://code.google.com/p/pysphere/wiki/GettingStarted#Getting_VM_properties
- get_vm_by_path: get the virtual machine from the path to the virtual machine configuration file. To get this value through the VMWare VI client:
- Right click on the vm icon in the resource tree and select "Change Settings ..."
- Click the Options tab.
- The value is specified in the "Virtual machine configuration file" field
Their example code shows this:
vm1 = server.get_vm_by_path("[DataStore1] Ubuntu/Ubuntu-10.vmx")
0
source to share