I’ve recently been digging into Cisco’s Unified Computing System (UCS). I wanted a report showing which ESXi host was in each chassis. I don’t have a lot of blades (yet) so making this list by hand wouldn’t have been a lot of work. However, I had heard about the UCS PowerTool (http://developer.cisco.com/web/unifiedcomputing/pshell-download) and thought this would be a perfect chance to kick the tires. What I had in mind was something that would look like this:
VMHostName UCSProfileName UCSBladeSlot ---------- -------------- ------------ esxbl51.bwuch.local esxbl5-1 sys/chassis-1/blade-8 esxbl52.bwuch.local esxbl5-2 sys/chassis-2/blade-8 esxbl53.bwuch.local esxbl5-3 sys/chassis-1/blade-7 esxbl54.bwuch.local esxbl5-4 sys/chassis-2/blade-7 esxbl55.bwuch.local esxbl5-5 sys/chassis-1/blade-6 esxbl56.bwuch.local esxbl5-6 sys/chassis-2/blade-6
Unfortunately the ESXi host name I wanted could not be found in the UCS interface. I was able to find the UUID of the service profile, which maps directly to the UUID in the system.hardware section of Get-View cmdlet for PowerCLI. Since both of the tools are powershell based it isn’t very tough to use them together. (The following code may look long, but that’s because of a lot of comments.)
[cc lang=”Powershell” width=”565″ height=”1200″]
# Author: Brian Wuchner
# Date: 2012/03/03
# Description: This is a sample inventory report combining information from Cisco UCS Manager with information from VMware vCenter
# The report uses Windows PowerShell and the following modules available from each vendor:
# Cisco UCS PowerTool: http://developer.cisco.com/web/unifiedcomputing/pshell-download
# VMware PowerCLI: http://vmware.com/go/powercli
# Define UCS connection details
$ucsSysName = “ucs.bwuch.local”
$ucsUserName = “admin”
$ucsPassword = “ucsadminpassword”
# Define vCenter connection info
$vcSysName = “vcenter.bwuch.local”
# Import the UCS PowerTool module and the VMware PowerCLI snapin
Import-Module “C:\Program Files (x86)\Cisco\Cisco UCS PowerTool\CiscoUcsPS.psd1”
Add-PSSnapin vmware.VimAutomation.core
# The UCSM connection requires a PSCredential to login, so we must convert our plain text password to make an object
$ucsPassword = ConvertTo-SecureString -String $ucsPassword -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $ucsUserName, $ucsPassword
# Create connection to UCS system
$ucsConnection = Connect-Ucs $ucsSysName -Credential $cred
# Collect the deployed service profiles and convert them to a hash table for easy reference
$serviceProfiles = Get-UcsServiceProfile | where {$_.AssignState -eq “assigned”} | select name, PnDn, SrcTemplName, Uuid
$spHT = $serviceProfiles | Group-Object uuid -AsHashTable -AsString
# Thats all we need from UCS, lets go ahead and logout
$ucsConnection = Disconnect-Ucs
# Connect to vCenter
$vcConnection = Connect-VIServer $vcSysName # if needed the -user and -password parameters can be passed here, otherwise SSPI is used (current windows credentials)
# Collect vCenter information on Cisco hardware
$hs = Get-View -ViewType HostSystem -Property Name, Summary.Hardware, Config.Product -Filter @{“Summary.Hardware.Vendor”=”Cisco Systems Inc”}
# We are done with vCenter, lets go ahead and logout
$vcConnection = Disconnect-VIServer * -Confirm:$false
# Put the to lists of information together
$myReport = @() # collection to store all the results
$hs | %{ # loop through the host system vCenter information
# create a variable to store the specific Cisco UCS record by UUID
$thisCiscoDevice = $spHT[$_.Summary.Hardware.Uuid][0]
# populate an object using all the applicable fields needed
$myReport += New-Object -Type PSObject -Property @{
VMHostName = $_.Name
VMHostVersion = $_.Config.Product.FullName
CpuModel = $_.Summary.Hardware.CpuModel
CpuMhz = $_.Summary.Hardware.CpuMhz
NumCpuPkgs = $_.Summary.Hardware.NumCpuPkgs
NumCpuCores = $_.Summary.Hardware.NumCpuCores
UCSBladeSlot = $thisCiscoDevice.PnDn
UCSProfileName = $thisCiscoDevice.Name
UCSProfileTemplate = $thisCiscoDevice.SrcTemplName
} # end new-object
} # end foreach-object
# Select a few of the columns in the order we want to see them…display to screen
$myReport | Select VMHostName, UCSProfileName, UCSBladeSlot
[/cc]
For my report needs, I only needed three columns. I added a handful of additional properties to the $myReport variable for demonstration purposes, but there are many more properties available.
CpuModel : Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz NumCpuCores : 20 UCSProfileTemplate : VMware_Blade_5x UCSBladeSlot : sys/chassis-1/blade-8 CpuMhz : 1997 UCSProfileName : esxbl5-1 NumCpuPkgs : 2 VMHostVersion : VMware ESXi 5.0.0 build-515841 VMHostName : esxbl51.bwuch.local
Nice one, BWuch! I’ll be interested to see what the final UCS module looks like.