This commit is contained in:
44
main.go
44
main.go
@@ -141,7 +141,7 @@ func getScsiBusSharingVMs(client *govmomi.Client) error {
|
||||
// Determine cluster based on runtime host of VM based on https://github.com/vmware/govmomi/issues/1242#issuecomment-427671990
|
||||
for _, host := range hsList {
|
||||
if host.Reference() == *vm.Summary.Runtime.Host {
|
||||
fmt.Printf("host %s matches with parent %s\n", host.Name, host.Parent)
|
||||
fmt.Printf("host %s matches, host parent %s\n", host.Name, host.Parent)
|
||||
|
||||
var cluster mo.ManagedEntity
|
||||
err = pc.RetrieveOne(ctx, *host.Parent, []string{"name"}, &cluster)
|
||||
@@ -156,27 +156,33 @@ func getScsiBusSharingVMs(client *govmomi.Client) error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(vm.Config.Hardware.Device) > 0 {
|
||||
for _, device := range vm.Config.Hardware.Device {
|
||||
//fmt.Printf("device: %v\n", 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 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)
|
||||
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" {
|
||||
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" {
|
||||
result := BusSharingResults{
|
||||
VmName: vm.Name,
|
||||
ClusterName: clusterName,
|
||||
ControllerName: device.GetVirtualDevice().DeviceInfo.GetDescription().Label,
|
||||
SharingType: sharedBusToString(controller.SharedBus),
|
||||
}
|
||||
busSharingResults = append(busSharingResults, result)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -261,6 +267,10 @@ func main() {
|
||||
//begin := flag.Duration("b", time.Hour, "Begin time") // default BeginTime is 1h ago
|
||||
flag.Parse()
|
||||
|
||||
if len(*vURL) == 0 {
|
||||
panic("Unable to connect to empty vCenter URL")
|
||||
}
|
||||
|
||||
// Print logs to file
|
||||
f, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user