02 October 2012

VMHost Logical Drive Info from CIM Provider with PowerCLI

Joe at filippello.com was grabbing some Logical Volume info for local disks on VMware hosts he was building in his post "Frustrated with fast booting hardware?".  He realized that, rather than going to the RAID controller setup and viewing the logical volume info, the CIM provider is nice enough to provide that info, and vCenter displays it on the Hardware Status tab for the host.

We wanted to get that info for lots of hosts instead of one at a time in the vSphere client, so I checked into the properties of the HostSystem. The CIM provider tells about the logical volumes.  vSphere presents this in the Runtime.HealthSystemRuntime.HardwareStatusInfo.StorageStatusInfo property.  For the HP hosts I used, this property also holds info about each individual local disk, the array controller(s), and their battery.  So, if you are looking for such info, this is a good property to explore.  But, back to the topic at hand.

The function:
<# .Description
    Get logical volume info for HP VMHosts from StorageStatusInfo of their managed objects. Depends on CIM provider being installed and in good health (responsive and whatnot), presumably
    Author:  vNugglets.com -- Aug 2012
#>
function Get-VNVMHostLogicalVolumeInfo {
    param(
        ## name of VMHost to check; if none, queries all hosts
        [string]$VMHostName_str
    ) ## end param

    ## make the Get-View expression to invoke
    $strGetViewExpr = 'Get-View -ViewType HostSystem -Property Name,Runtime.HealthSystemRuntime.HardwareStatusInfo.StorageStatusInfo'
    if ($VMHostName_str) {$strGetViewExpr += " -Filter @{'Name' = '$VMHostName_str'}"}
    Invoke-Expression $strGetViewExpr | Select name,
        @{n="logicalVol"; 
        e={($_.Runtime.HealthSystemRuntime.HardwareStatusInfo.StorageStatusInfo | `
            ?{$_.Name -like "Logical*"} | %{$_.Name}) -join ", "}}
} ## end function

Some example usage:
## for one host
PS vNuggs:> Get-VNVMHostLogicalVolumeInfo.ps1 -VMHostName devhost0323.mydomain.com

Name                        logicalVol
----                        ----------
devhost0323.mydomain.com    Logical Volume 1 on HPSA1 : RAID 1 : 136GB : Disk 1,2,3


## for all hosts, call with no parameter
PS vNuggs:> Get-VNVMHostLogicalVolumeInfo.ps1

Name                        logicalVol
----                        ----------
devhost0323.mydomain.com    Logical Volume 1 on HPSA1 : RAID 1 : 136GB : Disk 1,2,3
devhost4323.mydomain.com    Logical Volume 1 on HPSA1 : RAID 1 : 136GB : Disk 1,2,3
devhost1.mydomain.com       Logical Volume 1 on HPSA1 : RAID 1 : 136GB : Disk 1,2,3
devhost27.our.domain.com    Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost2.our.domain.com     Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost743.our.domain.com   Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost31111.our.domain.com Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost21.our.domain.com    Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost431.our.domain.com   Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost3.mydomain.com       Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost30.mydomain.com      Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2
devhost.mydomain.com        Logical Volume 1 on HPSA1 : RAID 1 : 68GB : Disk 1,2, Logical Volume 2 on HPSA1 : RAID 1 : 68GB : Disk 3,4
devhost122.mydomain.com     Logical Volume 1 on HPSA1 : RAID 1 : 136GB : Disk 1,2
...

And, an example of using some of the other info returned by the CIM provider:  if you were to change the ?{$_.Name -like "Logical*"} in the above function (line 17) to ?{$_.Name -like "Disk*"}, you could get just the local disks' info (instead of info on the logical volumes):
...
Disk 1 on HPSA1 : Port 1I Box 1 Bay 1 : 136GB : Data Disk, Disk 2 on HPSA1 : Port 1I Box 1 Bay 2 : 136GB : Data Disk, Disk 3 on HPSA1 : Port 1I Box 1 Bay 3 : 136GB : Spare Disk
...
Enjoy.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.