RSS

PS1: Mashing UCS host to MAC address via vlookup

21 Sep

This post is more a note to self, but is useful for folks using Cisco UCS enclosure when you need to general a list of hosts against its MAC address on eth0 NIC.

Cisco UCS is notoriously flexible yet complex. If you want a list of physical host names against its MAC address, there is no direct means of exporting that list. You need to get the source from two exports, one from the server export and one from the MAC Identity Management tab in the LAN tab. Then you need perform a vlookup to match each host to its MAC address using “Assigned To” field in th MAC export and “Name” field in the server export.

The macs.csv file looks like this. Notice that all NICs are listed, but you really only want eth0 which is the first NIC used when booting up in PXE

ID,Assigned,Assigned To
00:25:B5:22:00:A6,true,org-root/ls-SP_CLUS08_0108009/ether-eth6
00:25:B5:22:00:B7,true,org-root/ls-SP_CLUS07_0108012/ether-eth4
00:25:B5:22:00:18,true,org-root/ls-SP_CLUS06_0108015/ether-eth2
00:25:B5:22:00:49,true,org-root/ls-SP_CLUS06_0108002/ether-eth0
00:25:B5:22:00:AA,true,org-root/ls-SP_CLUS05_0108005/ether-eth0
00:25:B5:22:00:2B,true,org-root/ls-SP_CLUS04_0108009/ether-eth8
00:25:B5:22:00:8C,true,org-root/ls-SP_CLUS03_0108012/ether-eth6

This is the hosts.csv file exported from UCS

Name,User Label,Overall Status,Assoc State,Server
org-root/ls-SP_CLUS06_0108004,host02,ok,associated,sys/chassis-12/blade-5
org-root/ls-SP_CLUS01_0108004,Host03,ok,associated,sys/chassis-4/blade-1
org-root/ls-SP_CLUS06_0108008,Host87,ok,associated,sys/chassis-16/blade-5
org-root/ls-SP_CLUS01_0108001,Host08,ok,associated,sys/chassis-1/blade-1
org-root/ls-SP_CLUS10_0108004,host47,ok,associated,sys/chassis-4/blade-6
org-root/ls-SP_CLUS04_0108009,Host56,ok,associated,sys/chassis-3/blade-4

Here is the one-line the does a vlookup and outputs the MAC address for the first NIC, i.e. eth0, for each host name.

$mac = @{} ; import-csv .\macs.csv | 
? { $_."Assigned To" -match "eth0" } | 
% { $mac.add(($_."Assigned To" -replace "/ether-eth0"),$_.id) } ; 
import-csv .\hosts.csv | sort-object "User Label" | 
% { "$($mac.get_item($_.name)),$($_."User Label".ToLower())" | 
out-file .\mac2hosts.txt -append }
Advertisements
 
Leave a comment

Posted by on September 21, 2015 in powershell, Scripts

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: