Merge pull request #32 from jetbrains-infra/keep-alive

Keep vSphere connection alive
This commit is contained in:
Michael Kuzmin 2017-08-16 20:24:38 +03:00 committed by GitHub
commit 1ca3571e03
1 changed files with 19 additions and 2 deletions

View File

@ -11,6 +11,9 @@ import (
"github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/mo"
"errors" "errors"
"time" "time"
"github.com/vmware/govmomi/session"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25"
) )
type Driver struct { type Driver struct {
@ -27,8 +30,22 @@ func NewDriver(config *ConnectConfig) (*Driver, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
vcenter_url.User = url.UserPassword(config.Username, config.Password) credentials := url.UserPassword(config.Username, config.Password)
client, err := govmomi.NewClient(ctx, vcenter_url, config.InsecureConnection) vcenter_url.User = credentials
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 { if err != nil {
return nil, err return nil, err
} }