2

I have been working to train myself in the greatness that is Python and one of the best ways for me to learn is by doing. So, one of the many projects I have taken up is to pull firmware information from our Cisco UCS environments. After discovering that Cisco provides a Python SDK to query UCS; I used that as my starting point. Below are links for clarification of what a UCS is and the UCS Python SDK.

Cisco UCS descrition: http://www.cisco.com/c/en/us/products/servers-unified-computing/index.html

Cisco UCS Python SDK: https://communities.cisco.com/docs/DOC-37174

Script referenced from Cisco dev site: https://sreeninet.wordpress.com/2014/09/20/cisco-ucs-automation-using-python-sdk/ <-- this is where the majority of the code in my script came from, major props to Sreenivas.

My script: http://pastebin.com/txjnHi9q

I simply want to pull the Name, Model and Firmware version for each of the server blades, chassis and fabric interconnects. So, using the SDK provided by Cisco and a big chunk of the script linked above, my script is able to log into our UCS and query A and B Fabric Interconnects, the UCS manager and get both the model and firmware versions.

My script displays results similar to this:

UCS Manager Version: 2.2(3f)

Fabric Interconnect A:
Model: N10-S6200
Software Ver: 5.2(3)N2(2.23f)

Fabric Interconnect B:
Model: N10-S6200
Software Ver: 5.2(3)N2(2.23f)

Blade Chassis:
N20-C6508
N20-C6508
Blade Servers:
N20-B6625-1
N20-B6625-1

As shown above, I have successfully retrieved the firmware versions for the Fabric Interconnects and UCS Manager. I attempted using the same method for pulling the Blade Chassis and Blade Servers name, model and firmware but that is where things get more difficult for this newbie.

Looking at line 46 of my script linked above, it shows this code:

molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"sys/mgmt/fw-system"}

The "sys/mgmt/fw-system" is where I get confused when trying to get the firmware version. I can only get the blade and chassis model number as referenced on lines 124 and 133 as shown below.

molist = handle.GetManagedObject(None, EquipmentChassis.ClassId())
molist1 = handle.GetManagedObject(None, ComputeBlade.ClassId())

The UCS stores firmware for blades in "sys/chassis-N/slot-N/mgmt/fw-system" where N is the number of the chassis and slot. I attempted to just increment chassis-1 to chassis-2 -3 -4 and so on and slot-1 to slot-2 -3 -4. That did not work because the number of chassis and the number of blades in each chassis is not always the same. For example, each chassis can hold up to 8 server blades (slot) but not all chassis have all 8 installed. Some have 2 blades some have 6, etc. Once I got past the first chassis and tried to increment to chassis-2 the script would just pause indefinitely. It may not matter but I also need to take into account that chassis and slots can number in the triple digits.

Any ideas on how to go about the above in Python?

My apologies if I missed any pertinent information. I will gladly answer any questions I can. :D

Grimdari
  • 353
  • 1
  • 16

1 Answers1

0

I'm sure you've found a solution to your problem by now, but I came across this post looking for something similar.

Cisco has done a few changes to their Python SDK, but it looks pretty similar.

I started with getting all chassis:

from ucsmsdk.ucshandle import UcsHandle
handle = UcsHandle(host, login, pwd)
handle.login()

for chassis in handle.query_classid(class_id="EquipmentChassis"):

Queried the children of the chassis to find blades:

  for chassis_child in handle.query_children(in_mo=chassis):
      if chassis_child.get_class_id() == 'ComputeBlade':

Now i got a ComputeBlade-object with lots of useful stuff to put in our CMDB. But to find the firmware versions, we have to dig even further. First to find the BIOS:

         for blade_part in handle.query_children(in_mo=chassis_child):
             if blade_part.get_class_id() == 'BiosUnit':
                 for bios_part in handle.query_children(in_mo=blade_part):
                     if bios_part.get_class_id() == 'FirmwareRunning':
                         print chassis_child.dn, bios_part.version

phew .. That wasn't very elegant, and I hope to find an easier way to do this in the SDK, but I hope it helps anyone else starting out with UCSM sdk.

Commander Keen
  • 742
  • 6
  • 12