govspheregovmomi

govmomi Missing Cluster name ClusterComputeResource?


Have been using the following code from the issue

How to retrieve all clusters? https://github.com/vmware/govmomi/issues/1674

To retrieve cluster information, though the cluster name appears not to be returned,

does anyone know how i would retrieve the cluster names ?

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
    })

Solution

  • Adding name to Retrieve fixed the issues.

    https://github.com/vmware/govmomi/issues/2008

    err = v.Retrieve(ctx, []string{"ClusterComputeResource"}, []string{"summary", "name"}, &clusters)