ensure we logout, fix aggregations
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -36,6 +36,15 @@ type VmProperties struct {
|
||||
ResourcePool string
|
||||
}
|
||||
|
||||
var clientUserAgent = "vCTP"
|
||||
|
||||
// SetUserAgent customizes the User-Agent used when talking to vCenter.
|
||||
func SetUserAgent(ua string) {
|
||||
if strings.TrimSpace(ua) != "" {
|
||||
clientUserAgent = ua
|
||||
}
|
||||
}
|
||||
|
||||
type HostLookup struct {
|
||||
Cluster string
|
||||
Datacenter string
|
||||
@@ -87,6 +96,9 @@ func (v *Vcenter) Login(vUrl string) error {
|
||||
v.Logger.Error("Unable to connect to vCenter", "error", err)
|
||||
return fmt.Errorf("unable to connect to vCenter : %s", err)
|
||||
}
|
||||
if clientUserAgent != "" {
|
||||
c.Client.UserAgent = clientUserAgent
|
||||
}
|
||||
|
||||
//defer c.Logout(v.ctx)
|
||||
|
||||
@@ -97,22 +109,19 @@ func (v *Vcenter) Login(vUrl string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Vcenter) Logout() error {
|
||||
//v.Logger.Debug("vcenter logging out")
|
||||
|
||||
if v.ctx == nil {
|
||||
func (v *Vcenter) Logout(ctx context.Context) error {
|
||||
if ctx == nil {
|
||||
ctx = v.ctx
|
||||
}
|
||||
if ctx == nil {
|
||||
v.Logger.Warn("Nil context, unable to logout")
|
||||
return nil
|
||||
}
|
||||
|
||||
if v.client.Valid() {
|
||||
//v.Logger.Debug("vcenter client is valid. Logging out")
|
||||
return v.client.Logout(v.ctx)
|
||||
} else {
|
||||
v.Logger.Debug("vcenter client is not valid")
|
||||
return nil
|
||||
return v.client.Logout(ctx)
|
||||
}
|
||||
|
||||
v.Logger.Debug("vcenter client is not valid")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Vcenter) GetAllVmReferences() ([]*object.VirtualMachine, error) {
|
||||
|
||||
Reference in New Issue
Block a user