gpt4 book ai didi

go - govmomi缺少群集名称ClusterComputeResource?

转载 作者:行者123 更新时间:2023-12-01 22:22:34 24 4
gpt4 key购买 nike

从问题开始一直使用以下代码

如何检索所有集群? https://github.com/vmware/govmomi/issues/1674

要检索群集信息,尽管似乎没有返回群集名称,

有谁知道我将如何检索群集名称?

package main

import (
"context"
"fmt"

"github.com/vmware/govmomi/examples"
"github.com/vmware/govmomi/view"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/mo"
)

func main() {
examples.Run(func(ctx context.Context, c *vim25.Client) error {
// Create a view of Datastore objects
m := view.NewManager(c)

v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"ClusterComputeResource"}, true)
if err != nil {
fmt.Println(err)
return err
}

var clusters []mo.ClusterComputeResource
err = v.Retrieve(ctx, []string{"ClusterComputeResource"}, []string{"summary"}, &clusters)
if err != nil {
fmt.Println("ERROR")
fmt.Println(err)
return err
}
fmt.Println(clusters)
defer v.Destroy(ctx)
return nil
})

最佳答案

在检索中添加名称可解决此问题。

https://github.com/vmware/govmomi/issues/2008
err = v.Retrieve(ctx, []string{"ClusterComputeResource"}, []string{"summary", "name"}, &clusters)

关于go - govmomi缺少群集名称ClusterComputeResource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62245128/

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