Juniper / net-netconf

A Ruby gem for NETCONF
Other
64 stars 36 forks source link

Unable to iterate over show version all-members #37

Closed lollipopman closed 9 years ago

lollipopman commented 10 years ago
#!/usr/bin/env ruby

require 'net/netconf'
require 'junos-ez/stdlib'
require 'pp'

login = { :target => '172.23.80.5', :username => "root", :password => "a1b2c3" }

ndev = Netconf::SSH.new( login )
ndev.open

puts "Connected!"

target = 'candidate'

# JUNOS toplevel element is 'configuration'

Junos::Ez::Provider( ndev )
Junos::Ez::L1ports::Provider( ndev, :l1_ports )

Junos::Ez::IPports::Provider( ndev, :ip_ports )
Junos::Ez::Config::Utils( ndev, :cu )

# show the device softare version fact
pp ndev.fact :version

# show the device serial-number face
pp ndev.fact :serialnumber

# get a list of all available facts (Array)
pp ndev.facts.list

# get a hash of all facts and their associated values
pp ndev.facts.catalog

ndev.close

When running the above code, we receive this error:

/var/lib/gems/1.9.1/gems/netconf-0.3.1/lib/net/netconf/rpc.rb:32:in `block (3 levels) in method_missing': undefined method `each' for "show version all-members
":String (NoMethodError)
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:391:in `call'
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:391:in `insert'
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:375:in `method_missing'
        from /var/lib/gems/1.9.1/gems/netconf-0.3.1/lib/net/netconf/rpc.rb:31:in `block (2 levels) in method_missing'
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:391:in `call'
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:391:in `insert'
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:375:in `method_missing'
        from /var/lib/gems/1.9.1/gems/netconf-0.3.1/lib/net/netconf/rpc.rb:31:in `block in method_missing'
        from /var/lib/gems/1.9.1/gems/nokogiri-1.5.10/lib/nokogiri/xml/builder.rb:293:in `initialize'
        from /var/lib/gems/1.9.1/gems/netconf-0.3.1/lib/net/netconf/rpc.rb:30:in `new'
        from /var/lib/gems/1.9.1/gems/netconf-0.3.1/lib/net/netconf/rpc.rb:30:in `method_missing'
        from /var/lib/gems/1.9.1/gems/netconf-0.3.1/lib/net/netconf/rpc.rb:65:in `method_missing'
        from /home/jhathaway/.gem/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts/version.rb:14:in `block in <top (required)>'
        from /home/jhathaway/.gem/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:67:in `block in read!'
        from /home/jhathaway/.gem/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:64:in `each'
        from /home/jhathaway/.gem/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:64:in `read!'
        from /home/jhathaway/.gem/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:16:in `Provider'
        from netconf.add.a.vlan:17:in `<main>'
JamesNickerson commented 10 years ago

Change

require 'net/netconf'

to

require 'net/netconf/jnpr'
ganeshrn commented 9 years ago

@JamesNickerson Please reopen if issue is still seen.

lucasiglesias commented 8 years ago

Hi, I´m having almost the same error.. already checked to be using 'net/netconf/jnpr' Here is the script:

    #!/usr/bin/ruby

    require 'pp'
    require 'net/netconf/jnpr'
    require 'junos-ez/stdlib'
    require 'highline/import'

    # Create a hash map to hold login parameters for NetConf session
    login = Hash.new

    # Prompt for system IP, username and password
    login[:target]   = "192.168.108.199"
    login[:username] = ask("username: "){     |a| a.echo = true }

    # Connect to target and start netconf ssh session
    dev = Netconf::SSH.new( login ) 
    dev.open

    Junos::Ez::Provider( dev )

    pp dev.facts.catalog

    dev.close

And here the output:

# ./ruby_ez_1.rb 
username: test
/usr/local/rvm/gems/ruby-2.2.1/gems/net-netconf-0.4.3/lib/net/netconf/rpc.rb:32:in `block (3 levels) in method_missing': undefined method `each' for "show version":String (NoMethodError)
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:391:in `call'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:391:in `insert'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:375:in `method_missing'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/net-netconf-0.4.3/lib/net/netconf/rpc.rb:31:in `block (2 levels) in method_missing'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:391:in `call'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:391:in `insert'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:375:in `method_missing'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/net-netconf-0.4.3/lib/net/netconf/rpc.rb:31:in `block in method_missing'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/builder.rb:293:in `initialize'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/net-netconf-0.4.3/lib/net/netconf/rpc.rb:30:in `new'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/net-netconf-0.4.3/lib/net/netconf/rpc.rb:30:in `method_missing'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/net-netconf-0.4.3/lib/net/netconf/rpc.rb:65:in `method_missing'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts/version.rb:22:in `block in <top (required)>'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:67:in `block in read!'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:64:in `each'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:64:in `read!'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/junos-ez-stdlib-0.1.2/lib/junos-ez/facts.rb:16:in `Provider'
        from ./ruby_ez_1.rb:20:in `<main>'

Any ideas?