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:

  1. Easy access to the Cisco UCS API via the Ruby UCSAPI Module
  2. VMware + Ubuntu + Ruby + REST + XML + Cisco UCS API

1 Comment

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free