title: Cisco UCS Python SDK script for querying Firmware versions
body: <p>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.</p>
  
  <p><strong>Cisco UCS descrition:</strong> <a href="http://www.cisco.com/c/en/us/products/servers-unified-computing/index.html" rel="nofollow">http://www.cisco.com/c/en/us/products/servers-unified-computing/index.html</a></p>
  
  <p><strong>Cisco UCS Python SDK:</strong> <a href="https://communities.cisco.com/docs/DOC-37174" rel="nofollow">https://communities.cisco.com/docs/DOC-37174</a></p>
  
  <p><strong>Script referenced from Cisco dev site:</strong>  <a href="https://sreeninet.wordpress.com/2014/09/20/cisco-ucs-automation-using-python-sdk/" rel="nofollow">https://sreeninet.wordpress.com/2014/09/20/cisco-ucs-automation-using-python-sdk/</a>  &lt;-- this is where the majority of the code in my script came from, major props to Sreenivas.</p>
  
  <p><strong>My script:</strong> <a href="http://pastebin.com/txjnHi9q" rel="nofollow">http://pastebin.com/txjnHi9q</a></p>
  
  <p>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.</p>
  
  <p>My script displays results similar to this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Looking at line 46 of my script linked above, it shows this code:</p>
  
  <pre><code>molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"sys/mgmt/fw-system"}
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>molist = handle.GetManagedObject(None, EquipmentChassis.ClassId())
  molist1 = handle.GetManagedObject(None, ComputeBlade.ClassId())
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas on how to go about the above in Python?</p>
  
  <p>My apologies if I missed any pertinent information.  I will gladly answer any questions I can. :D</p>