UCS API Ruby Script

Written on:November 17, 2011
Comments
Add One

Yesterday I completed my first vFoglight Script Agent. There was nothing special about the entire process just making sure to do everything the right way. A colleague of mine was instrumental in getting the integrating with vFoglight. The script on the other hand I got working pretty easily. Ruby proved quite useful and I actually installed ruby on Windows and it worked like a charm. Here is the script I used in case anyone wants to dabble a bit.

On windows I downloaded the windows installer (1.8.7-p352) – http://rubyinstaller.org/downloads/
After Ruby is install I loaded just one GEM –

gem install rest-client

Here is the code for the script – ucsmblades.rb

#!/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://192.168.1.123/nuova', File.read('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://192.168.1.123/nuova', computeBladesXML, :content_type => 'text/xml'

# Create an XML doc out of ucsResp and parse it for stuff
ucsBladesDoc = Document.new(ucsResp)

#print out the results
ucsBladesDoc.elements.each("configResolveClass/outConfigs/*") {
  |blade|
  bladeName = blade.attributes["dn"]
  bladePower = blade.attributes["operPower"]
  bladeDiscovery = blade.attributes["discovery"]
  bladeAssociated = blade.attributes["association"]
  bladeState = blade.attributes["operState"]
  bladeCheck = blade.attributes["checkPoint"]
  bladeConnPath = blade.attributes["connPath"]
  bladeConnStatus = blade.attributes["connStatus"]
  bladeAvailability = blade.attributes["availability"]

  bladeAdminState = blade.attributes["adminState"]
  bladeSerial = blade.attributes["serial"]
#Location information
  bladeChassis = blade.attributes["chassisId"]
  bladeSlotID = blade.attributes["slotId"]
#Blade Inventory
  bladeModel = blade.attributes["model"]
  bladeTotMemory = blade.attributes["totalMemory"]
  bladeMemory = blade.attributes["availableMemory"]
  bladeAdaptors = blade.attributes["numOfAdaptors"]
  bladeCpus = blade.attributes["numOfCpus"]
  bladeCores = blade.attributes["numOfCores"]
  bladeCoreEnabled = blade.attributes["numOfCoresEnabled"]
  bladeNics = blade.attributes["numOfEthHostIfs"]
  bladeFcs = blade.attributes["numOfFcHostIfs"]
  bladeThreads = blade.attributes["numOfThreads"]

#Start to output
  puts "TABLE "+ bladeSerial
  puts "START_SAMPLE_PERIOD"

  puts "BladeName.StringObservation.obs= " + bladeName
  puts "BladeModel.StringObservation.obs= " + bladeModel
  puts "BladeChassis.StringObservation.obs= " + bladeChassis
  puts "BladeSlotID.StringObservation.obs= " + bladeSlotID
  puts "BladeAdminState.StringObservation.obs= " + bladeAdminState
  puts "BladeAvailability.StringObservation.obs= " + bladeAvailability
  puts "BladeConnStatus.StringObservation.obs= " + bladeConnStatus
  puts "BladeConnPath.StringObservation.obs= " + bladeConnPath
  puts "BladeCheck.StringObservation.obs= " + bladeCheck
  puts "BladeState.StringObservation.obs= " + bladeState
  puts "BladeAssociated.StringObservation.obs= " + bladeAssociated
  puts "BladeDiscovery.StringObservation.obs= " + bladeDiscovery
  puts "BladePower.StringObservation.obs= " + bladePower
  puts "BladeTotMemory:megabyte= " + bladeTotMemory
  puts "BladeMemory:megabyte= " + bladeMemory
  puts "BladeAdaptors:count= " + bladeAdaptors
  puts "BladeCPUs:count= " + bladeCpus
  puts "BladeCores:count= " + bladeCores
  puts "BladeCoresEnabled:count= " + bladeCoreEnabled
  puts "BladeNics:count= " + bladeNics
  puts "BladeFcs:count= " + bladeFcs
  puts "BladeThreads:count= " + bladeThreads

  puts "END_SAMPLE_PERIOD"
  puts "END_TABLE"

}
#end the output

Here is the code for the initiate.xml

<aaaLogin
           inName="admin"
           inPassword="admin"/>

Put everything in a folder and just run it from command line. Make sure and change the UCS address and username and password

ruby -W0 ucsmblades.rb

Cisco UCS+Ruby+XML+API really cool

Written on:November 5, 2011

I have been working on a Cisco UCS plugin for vFoglight and came across some excellent work from another person. If you are looking to do some work with UCS and Ruby I recommend starting here. I used some of this code to understand what is going on with XML parsing. http://viewyonder.com/2009/10/04/vmware-ubuntu-ruby-rest-xml-cisco-ucs-api/

Read more...

Linux SMB not showing up in Network Neighborhood

Written on:October 28, 2011

I recently had a problem with my Linux SMB server where it was not showing up in the Windows Networking. It caused a lot of problems with my Smart Televisions and Windows 7 Machines. Here is how I fixed this problems. Best to kick the services If that doesn’t work check to make sure that the firewall didn’t get enabled. Check your smb.conf files as well. Good luck.

Read more...

openSUSE VMware tools vSphere 5

Written on:September 15, 2011

I just installed openSUSE 11.4 in vSphere 5 and wanted to use the latest tools. openSUSE comes with open source tools but that just isn’t going to work for me. Here are some steps to get it done: Install some applications prior to installing the tools Once this is complete you can mount the tools DVD and then drag it to the desktop, unzip, then execute the installer to install…

Read more...

zypper Package Manager

Written on:September 15, 2011

If you are using openSUSE this is the package manager which is very similar to yum and apt-get. Here are some commands which should help from the command line. This will give you packages which have updates. This will update all packages List all installed packages Check and update specific packages like httpd Sample of searching for packages multiple line examples This will install a package.

Read more...

yum Package Manager

Written on:September 15, 2011

I know apt-get like the back of my hand and here are a few commands to help with YUM. This will give you packages which have updates. This will update all packages List all installed packages List all installed for specific packages like httpd Check and update specific packages like httpd Sample of searching for packages multiple line examples This will install a package.

Read more...
Page 1 of 2712345...1020...Last »