Revert f05b1e1. That commit introcude a regression from #30

This commit is contained in:
Andrei Tonkikh 2017-11-14 00:08:32 +03:00
parent 6e3e92e356
commit 991e1f8fdb
1 changed files with 17 additions and 3 deletions

View File

@ -9,6 +9,8 @@ import (
"github.com/vmware/govmomi/object"
"time"
"github.com/vmware/govmomi/session"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25"
)
type Driver struct {
@ -33,13 +35,25 @@ func NewDriver(config *ConnectConfig) (*Driver, error) {
if err != nil {
return nil, err
}
vcenter_url.User = url.UserPassword(config.Username, config.Password)
credentials := url.UserPassword(config.Username, config.Password)
vcenter_url.User = credentials
client, err := govmomi.NewClient(ctx, vcenter_url, config.InsecureConnection)
soapClient := soap.NewClient(vcenter_url, config.InsecureConnection)
vimClient, err := vim25.NewClient(ctx, soapClient)
if err != nil {
return nil, err
}
vimClient.RoundTripper = session.KeepAlive(vimClient.RoundTripper, 10*time.Minute)
client := &govmomi.Client{
Client: vimClient,
SessionManager: session.NewManager(vimClient),
}
err = client.SessionManager.Login(ctx, credentials)
if err != nil {
return nil, err
}
client.RoundTripper = session.KeepAlive(client.RoundTripper, 10*time.Minute)
finder := find.NewFinder(client.Client, false)
datacenter, err := finder.DatacenterOrDefault(ctx, config.Datacenter)