This commit is contained in:
62
main.go
62
main.go
@@ -9,6 +9,7 @@ import (
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
@@ -142,39 +143,40 @@ func processVMs(client *govmomi.Client) error {
|
||||
}
|
||||
}
|
||||
|
||||
if vm.Config != nil && vm.Config.Hardware.Device != nil {
|
||||
if len(vm.Config.Hardware.Device) > 0 {
|
||||
for _, device := range vm.Config.Hardware.Device {
|
||||
//fmt.Printf("device: %v\n", device)
|
||||
//fmt.Println("Type of variable1:", reflect.TypeOf(device))
|
||||
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
|
||||
//fmt.Printf("scsi: %v\n", scsi)
|
||||
controller := scsi.GetVirtualSCSIController()
|
||||
//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))
|
||||
|
||||
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 vm.Config != nil && len(vm.Config.Hardware.Device) > 0 {
|
||||
for _, device := range vm.Config.Hardware.Device {
|
||||
//fmt.Printf("device: %v\n", device)
|
||||
//fmt.Println("Type of variable1:", reflect.TypeOf(device))
|
||||
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
|
||||
//fmt.Printf("scsi: %v\n", scsi)
|
||||
controller := scsi.GetVirtualSCSIController()
|
||||
//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))
|
||||
|
||||
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 {
|
||||
//fmt.Printf("vdisk: %v\n", vdisk)
|
||||
busSharingResults = append(busSharingResults, result)
|
||||
|
||||
// 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
|
||||
// Sharing can be sharingNone or sharingMultiWriter
|
||||
backing := vdisk.VirtualDevice.Backing
|
||||
sharingType := backing.(*types.VirtualDiskFlatVer2BackingInfo).Sharing
|
||||
diskLabel := vdisk.VirtualDevice.DeviceInfo.GetDescription().Label
|
||||
|
||||
// See https://github.com/vmware/govmomi/blob/main/vim25/types/enum.go#L7538
|
||||
// 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" {
|
||||
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 {
|
||||
fmt.Printf("vm %s has no config\n", vm.Name)
|
||||
} else if vm.Config.Hardware.Device == nil {
|
||||
fmt.Printf("vm %s has no hardware device\n", vm.Name)
|
||||
} else {
|
||||
fmt.Printf("vm %s is something strange\n", vm.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user