Pregunta

Update: the problem is still here even if I try to create Shared VMs and change location of that VMs.

I got stuck trying to get to the virtual machine located in D:\VMs\CentOS-Backup\CentOS-Secondary-Server.vmx using PySphere.

Could you please help me?

All I tried so far is:

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

Mentioned exception is:

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, I installed VIX API as well. But didn't perform any specific actions related to system PATH additions. Could you give me a hint if I really need to do this?

Thanks!

¿Fue útil?

Solución

I finally figured it out! You need to make sure the VMs are shared. VM->Manage->Share...

Then they'll show up under server.get_registered_vms() and you can then use get_vm_by_name.

Otros consejos

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 path value:

http://code.google.com/p/pysphere/wiki/GettingStarted#Getting_VM_properties

  1. get_vm_by_path: retrieve a virtual machine by its virtual machine configuration file path. To get this value via the VMWare VI Client:
    1. Right click on the vm icon from the resources tree and select "Edit settings..."
    2. Go to the "Options" tab.
    3. The value is on the "Virtual Machine Configuration File" field

Their example code shows this:

vm1 = server.get_vm_by_path("[DataStore1] Ubuntu/Ubuntu-10.vmx")
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top