python-2.7 - 需要 python 接口(interface)将机器移动到另一个文件夹

标签 python-2.7 virtual-machine vsphere pyvmomi pysphere

我试图在 python 中找到代码支持,以便在 Datacenter 的文件夹之间移动机器但没有成功,我在 pysphere 中看到您可以在克隆阶段,而不是在机器已经克隆之后。

This似乎是我的问题的解决方案,但它在 powershell 中,有没有人知道在 python 中对它的包装支持

最佳答案

您可以使用 pyVmomi 来做到这一点。我会避免使用 pysphere,因为 pyVmomi 由 VMWare 维护,并且 pysphere 已经 4 年或更长时间没有更新了。

这里说的是一些使用 pyVmomi 的示例代码

service_instance = connect.SmartConnect(host=args.host,
                                        user=args.user,
                                        pwd=args.password,
                                        port=int(args.port))

search_index = service_instance.content.searchIndex
folder = search_index.FindByInventoryPath("LivingRoom/vm/new_folder")
vm_to_move = search_index.FindByInventoryPath("LivingRoom/vm/test-vm")
move_task = folder.MoveInto([vm_to_move])

在此示例中,我通过连接到 vCenter 创建了一个 ServiceInstance,接下来我获取了一个 SearchIndex 实例。 SearchIndex 有几种方法可用于定位您的托管对象。在此示例中,我决定使用 FindByInventoryPath 方法,但您可以使用任何适合您的方法。首先,我找到名为 new_folderFolder 实例,我想将我的 VirtualMachine 移到其中。接下来,我找到要移动的 VirtualMachine。最后,我执行将为我移动虚拟机的 Task。该任务采用要移动到文件夹中的对象列表的参数,在本例中,它是一个仅包含我要移动的虚拟机的单个项目列表。如果需要,您可以从这里监控任务。

请记住,如果您使用 FindByInventoryPath,则有许多隐藏文件夹在 GUI 中是不可见的。我发现使用 ManagedObjectBrowser有时非常有帮助。

有用的文档链接:

关于python-2.7 - 需要 python 接口(interface)将机器移动到另一个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41956255/

相关文章:

mysql - 虚拟化服务器上​​的 MySQL 性能要慢得多

go - 使用 govc 查找附加到 vm 的磁盘

python - 如何获取当前用户和其他用户之间的最后一条消息?

python - 如何将备用列表项更改为大写?

python - 如何使用 Python 2.7 在 Tkinter 中设计 GUI 序列

python - 选择具有最大值的条目并删除指定日期的其他条目

azure - 当我的服务作为 VMSS 的一部分时,在 VM 上运行的服务不再记录 App Insights

Vagrant 无法为 box 分配静态 ip

virtual-machine - Virtualbox 无法打开 - 错误 VERR_VD_IMAGE_READ_ONLY

c# - vsphere api 更改虚拟机的 IP 地址