
Whilst all the big systems management companies are integrating with UCS, the inquisitive amongst us are surely intrigued by the open API offered by UCS.
We all know how popular the vCenter API has been, including the amazing success of Powershell, so imagine if the same happened to UCS… or hang on, vCenter + UCS… hmmm, the mind boggles.
I’ve been doing some research (ok, foolin’ around) with the UCS API today and it has taken me just a few hours, from scratch, to get a complete system working. Amazing. No way would this have been possible without VMware Workstation, Ubuntu, Ruby, the amazing Ruby libraries (GEM, rest-client, REXML) and the open Cisco UCS API.
So what did I find? Well, only having a few hours today I just managed to get a few odds and ends working.. but now my mind is abuzz with “vmkusage for UCS”… :-)
I’ll let the script and output do the talking, suffice to say I asked UCS what blades were in there, what they were called and their power status. Through the API I can get every value, I can also set values, and I can listen (callbacks) for events. S W E E T!
Here’s the script (download)
#!/usr/bin/ruby -v
#
# Steve Chambers rough'n'ready RUCS script (Ruby UCS)
# No error checking or anything clever, just plain
# code to demonstrate how easy this is
#
require 'rubygems' # rest_client is a GEM addon, so need this to use it
require 'rest_client' # hides all the hard stuff for connecting to RESTful service
require 'rexml/document' # makes XML work dead easy
include REXML # means I don't have to put REXML:: before every Document class
# Login to UCS
# initiate.xml is simply the <aaaLogin /> code from page 2-2 of the UCS API pdf
ucsResp = RestClient.post 'http://beltac/nuova', File.read('../xml/initiate.xml'), :content_type => 'text/xml'
# Create an XML doc and parse it, especially taking out the cookie.
ucsLoginDoc = Document.new(ucsResp)
ucsLoginRoot = ucsLoginDoc.root
ucsCookie = ucsLoginRoot.attributes['outCookie']
#
# Now we've got a session and a cookie, the UCS XML API is at our disposal!
#
# The UCS XML-API has a powerful query system, so let's see the blades
computeBladesXML = '<configResolveClass cookie="' + ucsCookie + '" inHierarchical="false" classId="computeBlade"/>'
ucsResp = RestClient.post 'http://beltac/nuova', computeBladesXML, :content_type => 'text/xml'
# Create an XML doc out of ucsResp and parse it for stuff
ucsBladesDoc = Document.new(ucsResp)
ucsBladesDoc.elements.each("configResolveClass/outConfigs/*") {
|blade|
bladeName = blade.attributes["dn"]
bladePower = blade.attributes["operPower"]
puts "Blade " + bladeName + " is currently powered " + bladePower
}
And here’s the output:
stechamb@ubuntu:~/dev/ruby/scripts$ ./test.rb ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] Blade sys/chassis-2/blade-6 is currently powered on Blade sys/chassis-1/blade-1 is currently powered off Blade sys/chassis-1/blade-2 is currently powered on Blade sys/chassis-2/blade-3 is currently powered on Blade sys/chassis-2/blade-1 is currently powered off Blade sys/chassis-2/blade-2 is currently powered off Blade sys/chassis-2/blade-5 is currently powered off Blade sys/chassis-2/blade-7 is currently powered off Blade sys/chassis-2/blade-4 is currently powered off Blade sys/chassis-2/blade-8 is currently powered off Blade sys/chassis-1/blade-3 is currently powered off Blade sys/chassis-1/blade-4 is currently powered off Blade sys/chassis-1/blade-5 is currently powered off Blade sys/chassis-1/blade-6 is currently powered off Blade sys/chassis-1/blade-7 is currently powered off Blade sys/chassis-1/blade-8 is currently powered off Blade sys/chassis-4/blade-1 is currently powered off Blade sys/chassis-3/blade-2 is currently powered off Blade sys/chassis-3/blade-3 is currently powered off Blade sys/chassis-3/blade-4 is currently powered off Blade sys/chassis-3/blade-5 is currently powered off Blade sys/chassis-3/blade-1 is currently powered off Blade sys/chassis-3/blade-6 is currently powered off Blade sys/chassis-4/blade-2 is currently powered off
Nice…. :-)
One Comment
brilliant, i’m going to play with this for sure.
what would be really cool is an open source datacenter orchestration framework. kind of like OpenNMS is for network/host management.
Most orchestration tools cost too much and are too complex to be reliable. Also, if i were to build an IaaS product offering around such a software framework, i would be very nervous. all the eggs in one basket. the vendor has you over a barrel. i was at a telco that was shafted by a provisioning software vendor. over a year of problems. in the end, we gave up and got some smart internal guys to write their own from scratch. took 3 months, using Ruby on Rails.