Skip to content

Commit

Permalink
check if there are clusters before retrieving configuration; don't ge…
Browse files Browse the repository at this point in the history
…t respool config twice
  • Loading branch information
sofixa committed Nov 12, 2017
1 parent b47e66d commit 9508bf0
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions vsphere-influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,22 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.

//Retrieve properties for Cluster(s)
var clmo []mo.ClusterComputeResource
err = pc.Retrieve(ctx, clusterRefs, []string{"name", "configuration", "host"}, &clmo)
if err != nil {
fmt.Println(err)
return
if len(clusterRefs) > 0 {
err = pc.Retrieve(ctx, clusterRefs, []string{"name", "configuration", "host"}, &clmo)
if err != nil {
fmt.Println(err)
return
}
}

//Retrieve properties for ResourcePool
var rpmo []mo.ResourcePool
err = pc.Retrieve(ctx, respoolRefs, []string{"summary"}, &rpmo)
if err != nil {
fmt.Println(err)
return
if len(respoolRefs) > 0 {
err = pc.Retrieve(ctx, respoolRefs, []string{"summary"}, &rpmo)
if err != nil {
fmt.Println(err)
return
}
}

// Retrieve summary property for all datastores
Expand All @@ -322,12 +326,12 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
// Initialize the map that will hold the VM MOR to ResourcePool reference
vmToPool := make(map[types.ManagedObjectReference]string)

var respool []mo.ResourcePool
// Retrieve properties for ResourcePools
if len(respoolRefs) > 0 {
if debug == true {
stdlog.Println("going inside ResourcePools")
}
var respool []mo.ResourcePool
err = pc.Retrieve(ctx, respoolRefs, []string{"name", "config", "vm"}, &respool)
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -631,12 +635,12 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
}
}

var respool []mo.ResourcePool
err = pc.Retrieve(ctx, respoolRefs, []string{"name", "config", "vm"}, &respool)
if err != nil {
errlog.Println(err)
continue
}
// var respool []mo.ResourcePool
// err = pc.Retrieve(ctx, respoolRefs, []string{"name", "config", "vm"}, &respool)
// if err != nil {
// errlog.Println(err)
// continue
// }

for _, pool := range respool {
respoolFields := map[string]interface{}{
Expand Down

0 comments on commit 9508bf0

Please sign in to comment.