This commit is contained in:
62
main.go
62
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
_ "time/tzdata"
|
_ "time/tzdata"
|
||||||
@@ -142,39 +143,40 @@ func processVMs(client *govmomi.Client) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if vm.Config != nil && vm.Config.Hardware.Device != nil {
|
if vm.Config != nil && len(vm.Config.Hardware.Device) > 0 {
|
||||||
if len(vm.Config.Hardware.Device) > 0 {
|
for _, device := range vm.Config.Hardware.Device {
|
||||||
for _, device := range vm.Config.Hardware.Device {
|
//fmt.Printf("device: %v\n", device)
|
||||||
//fmt.Printf("device: %v\n", device)
|
//fmt.Println("Type of variable1:", reflect.TypeOf(device))
|
||||||
//fmt.Println("Type of variable1:", reflect.TypeOf(device))
|
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
|
||||||
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
|
//fmt.Printf("scsi: %v\n", scsi)
|
||||||
//fmt.Printf("scsi: %v\n", scsi)
|
controller := scsi.GetVirtualSCSIController()
|
||||||
controller := scsi.GetVirtualSCSIController()
|
//fmt.Printf("controller: %s\n", device.GetVirtualDevice().DeviceInfo.GetDescription().Label)
|
||||||
//fmt.Printf("controller: %s\n", device.GetVirtualDevice().DeviceInfo.GetDescription().Label)
|
//fmt.Printf("VM %s is using SCSI bus sharing mode: %s\n", vm.Name, string(controller.SharedBus))
|
||||||
//fmt.Printf("VM %s is using SCSI bus sharing mode: %s\n", vm.Name, string(controller.SharedBus))
|
|
||||||
|
|
||||||
if controller.SharedBus != "noSharing" {
|
|
||||||
fmt.Printf("VM %s is using SCSI bus sharing mode: %s\n", vm.Name, string(controller.SharedBus))
|
|
||||||
result := BusSharingResults{
|
|
||||||
VmName: vm.Name,
|
|
||||||
ClusterName: clusterName,
|
|
||||||
ControllerName: device.GetVirtualDevice().DeviceInfo.GetDescription().Label,
|
|
||||||
SharingType: sharedBusToString(controller.SharedBus),
|
|
||||||
}
|
|
||||||
busSharingResults = append(busSharingResults, result)
|
|
||||||
|
|
||||||
|
if controller.SharedBus != "noSharing" {
|
||||||
|
fmt.Printf("VM %s is using SCSI bus sharing mode: %s\n", vm.Name, string(controller.SharedBus))
|
||||||
|
result := BusSharingResults{
|
||||||
|
VmName: vm.Name,
|
||||||
|
ClusterName: clusterName,
|
||||||
|
ControllerName: device.GetVirtualDevice().DeviceInfo.GetDescription().Label,
|
||||||
|
SharingType: sharedBusToString(controller.SharedBus),
|
||||||
}
|
}
|
||||||
} else if vdisk, ok := device.(*types.VirtualDisk); ok {
|
busSharingResults = append(busSharingResults, result)
|
||||||
//fmt.Printf("vdisk: %v\n", vdisk)
|
|
||||||
|
|
||||||
// See https://github.com/vmware/govmomi/blob/main/object/virtual_device_list_test.go for info
|
}
|
||||||
|
} else if vdisk, ok := device.(*types.VirtualDisk); ok {
|
||||||
|
//fmt.Printf("vdisk: %v\n", vdisk)
|
||||||
|
|
||||||
diskLabel := vdisk.VirtualDevice.DeviceInfo.GetDescription().Label
|
// See https://github.com/vmware/govmomi/blob/main/object/virtual_device_list_test.go for info
|
||||||
|
|
||||||
// See https://github.com/vmware/govmomi/blob/main/vim25/types/enum.go#L7538
|
diskLabel := vdisk.VirtualDevice.DeviceInfo.GetDescription().Label
|
||||||
// Sharing can be sharingNone or sharingMultiWriter
|
|
||||||
backing := vdisk.VirtualDevice.Backing
|
// See https://github.com/vmware/govmomi/blob/main/vim25/types/enum.go#L7538
|
||||||
sharingType := backing.(*types.VirtualDiskFlatVer2BackingInfo).Sharing
|
// Sharing can be sharingNone or sharingMultiWriter
|
||||||
|
backing := vdisk.VirtualDevice.Backing
|
||||||
|
fmt.Println("Type of backing:", reflect.TypeOf(backing))
|
||||||
|
if info, ok := backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
|
||||||
|
sharingType := info.Sharing
|
||||||
|
|
||||||
if sharingType == "sharingMultiWriter" {
|
if sharingType == "sharingMultiWriter" {
|
||||||
fmt.Printf("VM %s is using MultiWriter on disk %ss\n", vm.Name, diskLabel)
|
fmt.Printf("VM %s is using MultiWriter on disk %ss\n", vm.Name, diskLabel)
|
||||||
@@ -192,8 +194,8 @@ func processVMs(client *govmomi.Client) error {
|
|||||||
}
|
}
|
||||||
} else if vm.Config == nil {
|
} else if vm.Config == nil {
|
||||||
fmt.Printf("vm %s has no config\n", vm.Name)
|
fmt.Printf("vm %s has no config\n", vm.Name)
|
||||||
} else if vm.Config.Hardware.Device == nil {
|
} else {
|
||||||
fmt.Printf("vm %s has no hardware device\n", vm.Name)
|
fmt.Printf("vm %s is something strange\n", vm.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user