Refactor `driver.NewDriver`

`driver.NewDriver` used to construct a govnomi client on its own while
the same work can be done by calling `govmomi.NewClient`.
This commit is contained in:
Andrey Tonkikh 2017-10-12 08:19:23 +03:00
parent 04d1820eb3
commit f05b1e1e4b
1 changed files with 3 additions and 17 deletions

View File

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