Quick update – there’s a new gem you can get at https://rubygems.org/gems/UCSAPI.
Important note: I’m now using Ruby 1.9.2 so if you run this on 1.8.7 it might not work (for example, I have to do a ‘require_relative’ which is new in 1.9.2 I think). I haven’t got time to test it against older 1.8.7 install (Yes! I should be using rvm to test! and Yes! my code should be more robust! but [fishes for excuse])
This is still rough’n'ready code and you have to bear in mind that I’m learning and playing with Ruby as I go.
Headlines are:
- You get a UCS object and login to the api
- Then you can get fabrics, fabrics and slots, and all the attributes
- Next is to add fans and psus
This is taking quite a bit of time because (a) my wife is giving birth at the moment, and (b) I’m concentrating on making the code re-usable so the rest of the managed objects are a doddle to add. I want this to be as usable as PowerShell, but with all the added goodness of Ruby.
One cosmetic thing I’m going to do next is add prettier “to string” methods so you get similar output to PowerShell.
Any comments…please add here.
Here’s an example of how to use (taken from the test case that’s in the gem – lib/tc_ucsapi.rb). The output from the test case is here.
require 'UCSAPI'@ucs = UCS.new(@options)@ucs.loginputs "\nTEST: GET ALL FABRICS - @ucs.fabric"puts @ucs.fabricsputs "\nTEST: GET FABRIC A BY ID - @ucs.fabric(:id = 'A')"puts @ucs.fabric(:id => 'A')puts "\nTEST: GET FABRIC B BY DN - @ucs.fabric(:dn => 'sys/switch-B')"puts @ucs.fabric(:dn => 'sys/switch-B')puts "\nTEST: GET ALL FABRICS TOTAL MEMORY - @ucs.fabric.totalMemory"puts @ucs.fabric.totalMemoryputs "\nTEST: NON-EXISTENT METHOD VIA FABRIC ARRAY PROXY - @ucs.fabric.noSuchMethod"puts @ucs.fabric.noSuchMethodputs "\nTEST: GET ALL FABRIC ATTRIBUTES - @ucs.fabric.attributes"puts @ucs.fabric.attributesputs "\nTEST: GET ALL FABRIC INSPECT - @ucs.fabric.each { |fabric| puts fabric.inspect }"@ucs.fabric.each { |fabric| puts fabric.inspect }puts "\nTEST: USE FABRICS PROXY METHOD - @ucs.fabrics(:id => 'A')"puts @ucs.fabrics(:id => 'A')puts "\nTEST: GET FABRIC A BOOTFLASH - @ucs.fabric(:id=>'A').bootflash"puts @ucs.fabric(:id=>'A').bootflashputs "\nTEST: GET ALL FABRICS BOOTFLASH - @ucs.fabric.bootflash"puts @ucs.fabric.bootflashputs "\nTEST: GET FABRIC A WORKSPACE - @ucs.fabric(:id=>'A').workspace"puts @ucs.fabric(:id=>'A').workspaceputs "\nTEST: GET FABRIC A WORKSPACE SIZE - @ucs.fabric(:id=>'A').workspace.size"puts @ucs.fabric(:id=>'A').workspace.sizeputs "\nTEST: GET ALL FABRICS WORKSPACE - @ucs.fabric.workspace"puts @ucs.fabric.workspaceputs "\nTEST: GET FABRIC A OPT - @ucs.fabric(:id=>'A').opt"puts @ucs.fabric(:id=>'A').optputs "\nTEST: GET FABRIC A OPT SIZE - @ucs.fabric(:id=>'A').opt.size"puts @ucs.fabric(:id=>'A').opt.sizeputs "\nTEST: GET ALL FABRICS OPT - @ucs.fabric.opt"puts @ucs.fabric.optputs "\nTEST: GET FABRIC A STATS - @ucs.fabric(:id=>'A').stats"puts @ucs.fabric(:id=>'A').statsputs "\nTEST: GET FABRIC A LOAD - @ucs.fabric(:id=>'A').stats.load"puts @ucs.fabric(:id=>'A').stats.loadputs "\nTEST: GET ALL FABRICS STATS - @ucs.fabric.stats"puts @ucs.fabric.statsputs "\nTEST: GET FABRIC A SLOTS - @ucs.fabric(:id=>'A').slots"puts @ucs.fabric(:id=>'A').slotsputs "\nTEST: GET FABRIC A SLOT 1 - @ucs.fabric(:id=>'A').slot(:id=>1)"puts @ucs.fabric(:id=>'A').slot(:id=>1).to_sputs "\nTEST: GET ALL FABRICS ALL SLOTS - @ucs.fabric.slots"puts @ucs.fabrics.slotsputs "\nTEST: GET ALL SLOTS ALL ATTRIBUTES - @ucs.fabric.slots.attributes"puts @ucs.fabrics.slots.attributesputs "\nTEST: GET THE SERIAL NUMBER OF ALL SLOTS - @ucs.fabric.slots.serial"puts @ucs.fabrics.slots.serialputs "\nTEST: GET THE NUM PORTS OF FABRIC A SLOT 1 - @ucs.fabric( :id => 'A').slot( :id => 1 ).numPorts"puts @ucs.fabric( :id => 'B').slot( :id => 1 ).numPorts@ucs.logout


Comments