govmomi 缺少集群名称 ClusterComputeResource?
govmomi Missing Cluster name ClusterComputeResource?
一直在使用问题中的以下代码
如何检索所有簇? 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
})
将名称添加到 Retrieve 解决了问题。
https://github.com/vmware/govmomi/issues/2008
err = v.Retrieve(ctx, []string{"ClusterComputeResource"}, []string{"summary", "name"}, &clusters)
一直在使用问题中的以下代码
如何检索所有簇? 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
})
将名称添加到 Retrieve 解决了问题。
https://github.com/vmware/govmomi/issues/2008
err = v.Retrieve(ctx, []string{"ClusterComputeResource"}, []string{"summary", "name"}, &clusters)