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:
parent
04d1820eb3
commit
f05b1e1e4b
|
@ -9,8 +9,6 @@ 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 {
|
||||
|
@ -35,25 +33,13 @@ func NewDriver(config *ConnectConfig) (*Driver, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
credentials := url.UserPassword(config.Username, config.Password)
|
||||
vcenter_url.User = credentials
|
||||
vcenter_url.User = url.UserPassword(config.Username, config.Password)
|
||||
|
||||
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)
|
||||
client, err := govmomi.NewClient(ctx, vcenter_url, config.InsecureConnection)
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue