Created
October 20, 2014 19:11
-
-
Save michaelrice/6ca760effdce7965b080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| List buildRDMInformation(Inventory inventory) { | |
| // To store the RDM information | |
| List rdmInfos = [] | |
| // For each VM in the inventory | |
| inventory.vms.each { vm -> | |
| // Get the host | |
| Host h = (Host) vm.host | |
| // Find all Virtual Disks | |
| VirtualDevice[] virtualDisks = vm.device.virtualDevice.findAll { it instanceof VirtualDisk } | |
| // Find if any raw disk mapping is present | |
| VirtualDevice[] vdsSorted = vm.device.virtualDevice.findAll { | |
| it instanceof VirtualDisk && it.backing instanceof VirtualDiskRawDiskMappingVer1BackingInfo | |
| } | |
| // Find all the virtual disks that are not RDM | |
| virtualDisks = virtualDisks.findAll { !vdsSorted*.key.contains(it.key) } | |
| // Get all the Virtual SCSI Controllers | |
| VirtualDevice[] vdsWithScsi = vm.device.virtualDevice.findAll { it instanceof VirtualController }.findAll { | |
| it instanceof VirtualSCSIController | |
| } | |
| // If no RDM, return | |
| if (!vdsSorted) { | |
| return rdmInfos | |
| } | |
| // Get the storage info extension for the Runtime Name | |
| HostStorageDeviceInfoEx storageDeviceInfoEx = new HostStorageDeviceInfoEx(h.storageDeviceInfo) | |
| // Get the scsi Luns on this host | |
| ScsiLun[] scsiLuns = h.scsiLun.scsiLun | |
| // Collect RDM info | |
| scsiLuns.each { scsiLun -> | |
| vdsSorted.each { vd -> | |
| if (vd.backing.lunUuid.contains(scsiLun.uuid)) { | |
| // Get the SCSI controller for this VirtualDisk | |
| VirtualSCSIController vsc = (VirtualSCSIController) vdsWithScsi.find { it.device.contains(vd.key) } | |
| // Collect RDM information | |
| Map rdmInfo = [ | |
| rdm : 'Yes', | |
| vmName : vm.name, | |
| hostedOn : h.name, | |
| diskName : vd.deviceInfo.label, | |
| capacity : Math.round((vd.capacityInKB) / (1024 * 1024)), | |
| fileName : vd.backing.fileName, | |
| naa : scsiLun.canonicalName, | |
| compatibility: vd.backing.compatibilityMode, | |
| scsiMode : vsc.sharedBus, | |
| scsiId : "${vsc.busNumber} : ${vd.unitNumber}", | |
| provisioned : 'Thick', | |
| pathing : h?.multipathInfo?.lun?.find { it.id == scsiLun.uuid }?.policy?.policy, | |
| runtimeName : storageDeviceInfoEx.getScsiRuntimeName(scsiLun) | |
| ] | |
| rdmInfos.add(rdmInfo) | |
| } | |
| } | |
| } | |
| // Collect the Virtual Disk info | |
| virtualDisks.each { vd -> | |
| // Get the SCSI controller for this VirtualDisk | |
| VirtualSCSIController vsc = (VirtualSCSIController) vdsWithScsi.find { it.device.contains(vd.key) } | |
| // Collect virtual disk information | |
| Map rdmInfo = [ | |
| vmName : vm.name, | |
| hostedOn : h.name, | |
| diskName : vd.deviceInfo.label, | |
| capacity : Math.round((vd.capacityInKB) / (1024 * 1024)), | |
| fileName : vd.backing.fileName, | |
| scsiMode : vsc.sharedBus, | |
| scsiId : "${vsc.busNumber} : ${vd.unitNumber}", | |
| provisioned: vd?.backing?.thinProvisioned ? 'Thin' : 'Thick' | |
| ] | |
| rdmInfos.add(rdmInfo) | |
| } | |
| } | |
| // To make debugging easy | |
| List result = rdmInfos.sort { it.diskName } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment