Skip to content

Instantly share code, notes, and snippets.

@codegold79
Created October 2, 2020 02:21
Show Gist options
  • Select an option

  • Save codegold79/c8e83ea92bdce9278d373806db91600f to your computer and use it in GitHub Desktop.

Select an option

Save codegold79/c8e83ea92bdce9278d373806db91600f to your computer and use it in GitHub Desktop.
func newClient(ctx context.Context, cfg *vcConfig) (*vsClient, error) {
u := url.URL{
Scheme: "https",
Host: cfg.VCenter.Server,
Path: "sdk",
}
u.User = url.UserPassword(cfg.VCenter.User, cfg.VCenter.Password)
insecure := cfg.VCenter.Insecure
gc, err := govmomi.NewClient(ctx, &u, insecure)
if err != nil {
return nil, fmt.Errorf("connecting to vSphere API: %w", err)
}
rc := rest.NewClient(gc.Client)
tm := tags.NewManager(rc)
vsc := vsClient{
govmomi: gc,
rest: rc,
tagMgr: tm,
}
err = vsc.rest.Login(ctx, u.User)
if err != nil {
return nil, fmt.Errorf("logging into rest api: %w", err)
}
return &vsc, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment