gpt4 book ai didi

python - 如何使用 Python 的 PySphere 获取 VmWare Workstation VM

转载 作者:太空宇宙 更新时间:2023-11-03 15:21:03 25 4
gpt4 key购买 nike

更新:即使我尝试创建共享 VM 并更改该 VM 的位置,问题仍然存在。

我在尝试使用 PySphere 访问位于 D:\VMs\CentOS-Backup\CentOS-Secondary-Server.vmx 的虚拟机时遇到了困难| .

你能帮帮我吗?

到目前为止我所尝试的是:

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

提到的异常(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'

请注意,我也安装了 VIX API。但没有执行任何与系统 PATH 添加相关的特定操作。如果我真的需要这样做,你能给我一个提示吗?

谢谢!

最佳答案

我终于明白了!您需要确保虚拟机是共享的。 VM->管理->共享...

然后它们将出现在 server.get_registered_vms() 下,然后您可以使用 get_vm_by_name。

关于python - 如何使用 Python 的 PySphere 获取 VmWare Workstation VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14789425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com