gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:14:56 25 4
gpt4 key购买 nike

我试图在 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/

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