我一直在尝试使用 pyvmomi 模块在 Python 中使用来自 ESX 主机的现有 vm 的 .vmx 和 .vmdk 文件来创建一个新的 vm。我是 pyvmomi 的新手,没有太多可用于 pyvmomi 的在线帮助。我已经检查了 github 中的示例代码(https://github.com/vmware/pyvmomi-community-samples/tree/298bf74446f3fcc5743d6435763ff6dc16ab4cbc/samples),但没有找到相关的东西。请给我指点。
问问题
3047 次
2 回答
1
假设 Virtualachine 名称是:1001-web1.myhost.com
那么你要装的HostSystem是:host1.myesxhost.com
主机有一个名为:Local1的数据存储
主机住在一个名为:Prod的文件夹中
您需要将文件从 VM 获取到 Local1 数据存储。我会让你弄清楚那部分。它们需要被放入一个名为:1001-web1.myhost.com的文件夹中
接下来,您需要在清单中找到文件夹Prod和 HostSystem host1.myesxhost.com,以便为它们提供 ManagedObjectRef。您可以使用 searchIndex.FindByDnsName 查找主机,并使用 searchIndex.FindByInventoryPath 查找文件夹(或其他一些方法..)
找到文件夹Prod后,您可以使用RegisterVM_Task来注册 vm。
si = connect.SmartConnect(xxx)
host = si.content.searchIndex.FindByDnsName(None,"host1.myesxhost.com", False)
folder = si.content.searchIndex.FindByInventoryPath(xxx)
task = folder.RegisterVM_Task(path="[Local1] 1001-web1.myhost.com/1001-web1.myhost.com.vmx", name="new vm name", asTemplate=False, pool=None, host=host)
从这里您应该能够在任务成功完成后监控任务的进程,task.info.result 将包含新 VM 的 MOREF。
这是伪代码,因此语法可能不正确,但这是您必须遵循的过程。
于 2015-03-23T18:01:25.243 回答
0
如果您知道 vmx 文件的数据存储路径,则可以使用以下命令:
from pyVim import folder
folder.Register("[datastore]TestVM/TestVM.vmx")
于 2015-09-07T07:45:47.980 回答