Skip to content

Instantly share code, notes, and snippets.

@mkuzmin
Created August 21, 2016 12:25
Show Gist options
  • Save mkuzmin/7b6345e9693e18d0fa4fc681da90912a to your computer and use it in GitHub Desktop.
Save mkuzmin/7b6345e9693e18d0fa4fc681da90912a to your computer and use it in GitHub Desktop.
package main
import (
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
"net/url"
"golang.org/x/net/context"
"os"
"fmt"
)
func main() {
ctx := context.TODO()
url, _ := url.Parse("https://user:password@server/sdk")
client, _ := govmomi.NewClient(ctx, url, true)
finder := find.NewFinder(client.Client, true)
dc, _ := finder.DefaultDatacenter(ctx)
finder.SetDatacenter(dc)
hosts, err := finder.HostSystemList(ctx, "*")
if err != nil {
fmt.Printf("[ERROR] Error reading host list: %s\n", err)
os.Exit(1)
}
fmt.Println(len(hosts))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment