如何从数据存储添加或注册.vmtx文件到主机清单?

时间:2019-04-30 05:21:23

标签: python pyvmomi

我已经在nfs数据存储上创建了vm模板。现在,通过自动化,我将该数据存储添加到独立的ESX主机,然后将.vmtx文件注册到ESX主机。通过脚本将数据存储添加到主机后,我无法将.vmtx文件注册到主机。

我尝试了以下代码-

app.Use(async (HttpContext context, Func<Task> next) => {
    await next.Invoke(); //execute the request pipeline

    if (context.Response.StatusCode == StatusCodes.Status302Found && context.Response.Headers.TryGetValue("Location", out var redirect)) {
        var v = redirect.ToString();
        if (v.StartsWith($"{context.Request.Scheme}://{context.Request.Host}/Account/Login")) {
            context.Response.Headers["Location"] = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.Path}";
            context.Response.StatusCode = 401;
        }
    }
});

我遇到错误-

'''失败-该对象不支持该操作。 '''

1 个答案:

答案 0 :(得分:0)

找到了答案。我给pool和asTemplate参数提供了错误的值。

si = connect()  # connect method connects to the standalone ESX host. It is NOT part of any VCenter
    content = si.RetrieveContent()
    # nfs_datastore = add_nfsdatastore(content, 'esx-ip', 'nfs-ip', 'nfs-path', 'nfs-name')
    # print("nfs datastore added successfully")
    # print(nfs_datastore)
    host = content.rootFolder.childEntity[0]
    host_folder  = host.vmFolder
    print(host_folder)
    hostobj = content.searchIndex.FindByIp(None, "esx-ip",vmSearch=False)
    resource_pool = hostobj.vm[0].resourcePool
    host_folder.RegisterVM_Task(path="[nfs-datastore-name]/my-template/ubuntu-temp-1.vmtx", name="automation-template-1", asTemplate=False, pool=resource_pool, host=hostobj)