python-3.x - 使用 pyvmomi 从关闭状态启动 VM

标签 python-3.x vmware vsphere pyvmomi

因此,我尝试使用 pyvmomi 制作一个 Python 脚本来控制在 ESXi 服务器上运行的虚拟机的状态。基本上,我尝试使用 connection.content.searchIndex.FindByIp(ip="the ip of the VM", vmSearch=True) 来获取我的虚拟机,然后打开它的电源,但我当然无法获取VM 关闭时的 IP。所以,我想知道是否有任何方法可以通过名称或 ID 获取虚拟机?我进行了相当多的搜索,但找不到真正的解决方案。不管怎样,到目前为止,这是我的代码:

from pyVim import connect
# Connect to ESXi host
connection = connect.Connect("192.168.182.130", 443, "root", "password")

# Get a searchIndex object
searcher = connection.content.searchIndex

# Find a VM
vm = searcher.FindByIp(ip="192.168.182.134", vmSearch=True)

# Print out vm name
print (vm.config.name)

# Disconnect from cluster or host
connect.Disconnect(connection)

最佳答案

searchindex 没有任何方法来执行“findbyname”,因此您可能不得不撤回所有虚拟机并在客户端进行过滤。

以下是返回所有虚拟机的示例:https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/getallvms.py

另一个选择是,如果您使用的是 vCenter 6.5+,则可以使用适用于 Python 的 vSphere Automation SDK,您可以在其中与 REST API 交互以执行服务器端筛选。更多信息:https://github.com/vmware/vsphere-automation-sdk-python

关于python-3.x - 使用 pyvmomi 从关闭状态启动 VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52581228/

相关文章:

python - 怎样才能做出完美的释义?

python-3.x - 将 button_press_event 添加到 Gtk.Image?

vmware - 无法将 ovf 加载到使用 vmware vphrere 导出创建的 virtualbox?

linux - 使用 Citrix XenServer 设置 NAS

linux - ESX 主机/硬件是什么意思

Python程序随机挂起

python-3.x - 如何停止在 Python 中的命名管道上阻塞的线程?

java - 六、JAVA : Getting Custom Fields (Names and Values) from Virtual Machines

go - vSphere,通过 API (govmomi) 将现有 HDD 添加到 VM

VMware ESXi6.5u1 客户端支持