Created
October 2, 2020 02:21
-
-
Save codegold79/c8e83ea92bdce9278d373806db91600f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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