@@ -103,7 +103,6 @@ var getversion, debug, test bool
103
103
var stdlog , errlog * log.Logger
104
104
var version = "master"
105
105
106
-
107
106
// Connect to the actual vCenter connection used to query data
108
107
func (vcenter * VCenter ) Connect () error {
109
108
ctx , cancel := context .WithCancel (context .Background ())
@@ -377,6 +376,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
377
376
// Initialize the map that will hold the host MOR to cluster reference
378
377
hostToCluster := make (map [types.ManagedObjectReference ]string )
379
378
379
+ // Initialize the map that will hold the vDisk UUID per VM MOR to datastore reference
380
+ vDiskToDatastore := make (map [types.ManagedObjectReference ]map [string ]string )
381
+
380
382
// Retrieve properties for clusters, if any
381
383
if len (clusterRefs ) > 0 {
382
384
if debug {
@@ -452,6 +454,18 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
452
454
fmt .Println (err )
453
455
}
454
456
vmSummary [vm .Self ]["datastore" ] = strings .Replace (strings .Replace (re .FindString (fmt .Sprintln (vm .Summary .Config )), "[" , "" , - 1 ), "]" , "" , - 1 )
457
+
458
+ // List all devices to get vDisks
459
+ for _ , device := range vm .Config .Hardware .Device {
460
+ // Hacky way to check if it's a vDisk and if it's datastore is different than the main one for VM
461
+ if device .Backing .FileName != nil && device .Backing .Datastore .Name != vmSummary [vm .Self ]["datastore" ] {
462
+ if vDiskToDatastore [vm .Self ] == nil {
463
+ vDiskToDatastore [vm .Self ] = make (map [string ]string )
464
+ }
465
+ vDiskToDatastore [vm.Self ][device.diskObjectId ] = device .Backing .Datastore .Name
466
+ }
467
+ }
468
+
455
469
if vmToCluster [vm .Self ] != "" {
456
470
vmSummary [vm .Self ]["cluster" ] = vmToCluster [vm .Self ]
457
471
}
@@ -813,7 +827,7 @@ func main() {
813
827
flag .Parse ()
814
828
815
829
if getversion {
816
- stdlog .Println ("Version:" ,version )
830
+ fmt .Println ("Version:" , version )
817
831
os .Exit (0 )
818
832
}
819
833
0 commit comments