mirror of
https://github.com/Oxalide/vsphere-influxdb-go.git
synced 2023-10-10 13:36:51 +02:00
Only defer client.Logout if client has been successfully returned.
This commit is contained in:
parent
482da3d2b9
commit
50c45f7d2a
@ -131,12 +131,12 @@ func (vcenter *VCenter) Init(config Configuration) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
client, err := vcenter.Connect()
|
client, err := vcenter.Connect()
|
||||||
defer client.Logout(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
|
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
|
||||||
errlog.Println("Error: ", err)
|
errlog.Println("Error: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer client.Logout(ctx)
|
||||||
var perfmanager mo.PerformanceManager
|
var perfmanager mo.PerformanceManager
|
||||||
err = client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
|
err = client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -182,12 +182,12 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
|
|||||||
|
|
||||||
// Get the client
|
// Get the client
|
||||||
client, err := vcenter.Connect()
|
client, err := vcenter.Connect()
|
||||||
defer client.Logout(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
|
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
|
||||||
errlog.Println("Error: ", err)
|
errlog.Println("Error: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer client.Logout(ctx)
|
||||||
|
|
||||||
// Create the view manager
|
// Create the view manager
|
||||||
var viewManager mo.ViewManager
|
var viewManager mo.ViewManager
|
||||||
|
Loading…
Reference in New Issue
Block a user