Quick post to share a little Ruby script that lets you send commands and get output from the Nexus 1000V VSM.
HTML: Basic Ruby interface to the Nexus 1000V
Public Clone URL: git://gist.github.com/1326436.git
Enjoy!
class NX1K
require 'net/ssh'
attr_writer :host, :user, :pwd
def send(xml)
session = Net::SSH.start(@host, @user, :password => @pwd, :timeout => 10, :verbose => :debug) do |session|
channel = session.open_channel do |channel|
channel.subsystem("xmlagent") do |xmlagent, success|
xmlagent.on_data do |xmlagent, data|
puts "(xmlagent) ON_DATA: #{data.inspect}"
xmlagent.close if data === "]]>]]>"
end
xmlagent.on_close do |xmlagent|
puts "(xmlagent) ON_CLOSE"
end
xmlagent.on_eof do |xmlagent|
puts "(xmlagent) ON_EOF"
end
xmlagent.send_data(IO.read('nx1k_hello.xml'))
xmlagent.send_data(xml)
end #xmlagent
end #channel
end #session
end #send
end #class
vsm = NX1K.new
vsm.host = '192.168.1.130'
vsm.user = 'admin'
vsm.pwd = 'VCEr0cks!'
vsm.send(IO.read('nx1k_show_int.xml'))
Related posts:
- Easy access to the Cisco UCS API via the Ruby UCSAPI Module
- VMware + Ubuntu + Ruby + REST + XML + Cisco UCS API

Thank you for this code, I’m trying to brush up on my coding and this is great springboard to get me going!
Thanks,
Steve