我正在尝试寻找代码支持python
为了在数据中心的文件夹之间移动机器但没有成功,我看到pysphere
您可以在克隆阶段定义文件夹,而不是在机器克隆之后定义文件夹。
This https://jackiechen.org/2011/11/01/moving-vm-to-folder-in-vcenter/似乎是我的问题的解决方案,但它是在 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])
在这个例子中我创建了一个ServiceInstance
通过连接到 vCenter,接下来我获取一个实例SearchIndex
. The SearchIndex
有多种方法可用于定位您的托管对象。在这个例子中我决定使用FindByInventoryPath
方法,但您可以使用任何适合您的方法。首先我找到的实例Folder
named new_folder
我想移动我的VirtualMachine
进入。接下来我找到VirtualMachine
我想搬家。最后我执行Task
这将为我移动虚拟机。该任务需要一个要移动到文件夹中的对象列表的参数,在本例中,它是一个仅包含我要移动的一个虚拟机的单个项目列表。如果需要,您可以从这里监视任务。
请记住,如果您使用FindByInventoryPath
有许多隐藏文件夹在 GUI 中不可见。我发现使用托管对象浏览器 https://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.pg.doc_50%2FPG_ChB_Using_MOB.20.2.html有时非常有帮助。
有用的文档链接:
- https://github.com/vmware/pyvmomi/blob/master/docs/vim/SearchIndex.rst https://github.com/vmware/pyvmomi/blob/master/docs/vim/SearchIndex.rst
- https://github.com/vmware/pyvmomi/blob/master/docs/vim/Folder.rst https://github.com/vmware/pyvmomi/blob/master/docs/vim/Folder.rst
- https://github.com/vmware/pyvmomi/blob/master/docs/vim/Task.rst https://github.com/vmware/pyvmomi/blob/master/docs/vim/Task.rst
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)