netconf 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ #
2
+ # This code is used to retrieve the running configuration
3
+ # from a Tail-F "confD" NETCONF server, and display the
4
+ # configured user names
5
+ #
6
+
7
+ require 'net/netconf'
8
+
9
+ puts "NETCONF v#{Netconf::VERSION}"
10
+
11
+ login = { :target => 'jeap', :port => 2022,
12
+ :username => "admin", :password => "admin" }
13
+
14
+ Netconf::SSH.new( login ){ |dev|
15
+
16
+ config = dev.rpc.get_config
17
+
18
+ puts "Showing users on this device ..."
19
+
20
+ config.xpath("//users/user").each{|user|
21
+ puts "Username: #{user.xpath('name').text}"
22
+ }
23
+
24
+ }
25
+
26
+
27
+
@@ -1,6 +1,6 @@
1
1
  require 'net/netconf/jnpr'
2
2
 
3
- puts "NETCONF v.#{Netconf::VERSION}"
3
+ puts "NETCONF v#{Netconf::VERSION}"
4
4
 
5
5
  login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
6
 
@@ -14,9 +14,9 @@ Netconf::SSH.new( login ){ |dev|
14
14
  location = Nokogiri::XML::Builder.new{ |x|
15
15
  x.system {
16
16
  x.location {
17
- x.building "Main Campus, C"
18
- x.floor 15
19
- x.rack 37
17
+ x.building "Main Campus, D"
18
+ x.floor 22
19
+ x.rack 38
20
20
  }
21
21
  }
22
22
  }
@@ -52,7 +52,6 @@ Netconf::SSH.new( login ){ |dev|
52
52
  puts "Commit error"
53
53
  rescue Netconf::RpcError => e
54
54
  puts "General RPC error"
55
- binding.pry
56
55
  else
57
56
  puts "Configuration Committed."
58
57
  end
@@ -55,7 +55,6 @@ Netconf::SSH.new( login ){ |dev|
55
55
  puts "Commit error"
56
56
  rescue Netconf::RpcError => e
57
57
  puts "General RPC error"
58
- binding.pry
59
58
  else
60
59
  puts "Configuration Committed."
61
60
  end
@@ -59,7 +59,6 @@ EOCONF
59
59
  puts "Commit error"
60
60
  rescue Netconf::RpcError => e
61
61
  puts "General RPC error"
62
- binding.pry
63
62
  else
64
63
  puts "Configuration Committed."
65
64
  end
@@ -22,8 +22,6 @@ dev.open { |con|
22
22
 
23
23
  inv = dev.rpc.get_chassis_inventory
24
24
 
25
- binding.pry
26
-
27
25
  dev.close
28
26
 
29
27
 
@@ -4,10 +4,8 @@ puts "NETCONF v.#{Netconf::VERSION}"
4
4
 
5
5
  serial_port = '/dev/ttyS4'
6
6
 
7
- login = {
8
- :port => serial_port,
9
- :username => "jeremy", :password => "jeremy1"
10
- }
7
+ login = { :port => serial_port,
8
+ :username => "jeremy", :password => "jeremy1" }
11
9
 
12
10
  puts "Connecting to SERIAL: #{serial_port} ... please wait."
13
11
 
@@ -21,8 +19,6 @@ Netconf::Serial.new( login ){ |dev|
21
19
  puts "Chassis: " + inv.xpath('chassis/description').text
22
20
  puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
23
21
 
24
- binding.pry
25
-
26
22
  }
27
23
 
28
24
 
@@ -1,6 +1,6 @@
1
1
  require 'net/netconf/jnpr/telnet'
2
2
 
3
- puts "NETCONF v.#{Netconf::VERSION}"
3
+ puts "NETCONF v#{Netconf::VERSION}"
4
4
 
5
5
  login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
6
 
@@ -9,7 +9,6 @@ Netconf::Telnet.new( login ){ |dev|
9
9
  puts "Chassis: " + inv.xpath('chassis/description').text
10
10
  puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
11
11
 
12
- binding.pry
13
12
  }
14
13
 
15
14
 
@@ -1,18 +1,15 @@
1
1
  require 'net/netconf'
2
2
 
3
- puts "NETCONF v.#{Netconf::VERSION}"
3
+ puts "NETCONF v#{Netconf::VERSION}"
4
4
 
5
- login = { :target => '192.168.10.2',
6
- :username => "jeremy",
7
- :password => "jeremy1" }
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
8
6
 
9
7
  Netconf::SSH.new( login ){ |dev|
10
-
8
+
11
9
  inv = dev.rpc.get_chassis_inventory
12
10
 
13
11
  puts "Chassis: " + inv.xpath('chassis/description').text
14
- puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
15
-
12
+ puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
16
13
  }
17
14
 
18
15
 
data/examples/jnpr/scp.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'net/netconf'
2
2
  require 'net/scp'
3
3
 
4
- login = { :target => 'vsrx', :username => "jeremy" }
4
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
5
5
 
6
6
  file_name = __FILE__
7
7
 
data/lib/net/netconf.rb CHANGED
@@ -7,7 +7,10 @@ require 'net/netconf/transport'
7
7
  require 'net/netconf/ssh'
8
8
 
9
9
  module Netconf
10
- VERSION = "0.2.1"
10
+ VERSION = "0.2.2"
11
+
12
+ NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0"
13
+
11
14
  DEFAULT_OS_TYPE = :JUNOS
12
15
  DEFAULT_TIMEOUT = 10
13
16
  DEFAULT_WAITIO = 0
@@ -5,15 +5,12 @@ module Netconf
5
5
  MSG_END_RE = /\]\]>\]\]>[\r\n]*$/
6
6
  MSG_CLOSE_SESSION = '<rpc><close-session/></rpc>'
7
7
  MSG_HELLO = <<-EOM
8
- <hello>
8
+ <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
9
9
  <capabilities>
10
- <capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>
11
- <capability>urn:ietf:params:xml:ns:netconf:base:1.0#candidate</capability>
12
- <capability>urn:ietf:params:xml:ns:netconf:base:1.0#confirmed-commit</capability>
13
- <capability>urn:ietf:params:xml:ns:netconf:base:1.0#validate</capability>
14
- <capability>urn:ietf:params:xml:ns:netconf:base:1.0#url?protocol=http,ftp,file</capability>
10
+ <capability>urn:ietf:params:netconf:base:1.0</capability>
15
11
  </capabilities>
16
- </hello>
12
+ </hello>
13
+ ]]>]]>
17
14
  EOM
18
15
 
19
16
  module Standard
@@ -68,13 +68,17 @@ module Netconf
68
68
  self
69
69
  end
70
70
 
71
- def trans_hello
71
+ def trans_receive_hello
72
72
  hello_str = trans_receive()
73
73
  so_xml = hello_str.index("\n") + 1
74
74
  hello_str.slice!(0, so_xml)
75
75
  hello_str
76
76
  end
77
77
 
78
+ def trans_send_hello
79
+ nil
80
+ end
81
+
78
82
  def trans_close
79
83
  @trans.write Netconf::RPC::MSG_CLOSE_SESSION
80
84
  @trans.close
@@ -115,7 +119,10 @@ module Netconf
115
119
 
116
120
  begin
117
121
 
118
- rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
122
+ rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
123
+
124
+ $stdout.puts rx_some
125
+
119
126
  rx_buf += rx_some
120
127
  break if rx_buf.match( on_re )
121
128
 
@@ -33,13 +33,7 @@ module Netconf
33
33
  trans_start_netconf()
34
34
  self
35
35
  end
36
-
37
- def trans_hello
38
- hello_str = trans_receive()
39
- so_xml = hello_str.index("\n") + 1 # skip over the last issued command
40
- hello_str[so_xml .. -1]
41
- end
42
-
36
+
43
37
  def trans_close
44
38
  @trans.write Netconf::RPC::MSG_CLOSE_SESSION
45
39
  @trans.close
@@ -22,6 +22,7 @@ module Netconf
22
22
  @os_type = @args[:os_type] || Netconf::DEFAULT_OS_TYPE
23
23
 
24
24
  @rpc = Netconf::RPC::Executor.new( self, @os_type )
25
+ @rpc_message_id = 1
25
26
 
26
27
  if block_given?
27
28
  open( &block = nil ) # do not pass this block to open()
@@ -38,19 +39,31 @@ module Netconf
38
39
  # block is used to deal with special open processing ...
39
40
  # this is *NOT* the block passed to initialize()
40
41
  raise Netconf::OpenError unless trans_open( &block )
41
- @state = :NETCONF_OPEN
42
-
43
- hello_rsp = Nokogiri::XML( trans_hello() )
42
+
43
+ # read the <hello> from the server and parse out
44
+ # the capabilities and session-id
44
45
 
46
+ hello_rsp = Nokogiri::XML( trans_receive_hello() )
47
+ hello_rsp.remove_namespaces!
48
+
45
49
  @capabilities = hello_rsp.xpath('//capability').map{ |c| c.text }
46
- @session_id = hello_rsp.xpath('//session-id').text
50
+ @session_id = hello_rsp.xpath('//session-id').text
51
+
52
+ # send the <hello>
53
+ trans_send_hello()
54
+
55
+ @state = :NETCONF_OPEN
47
56
  self
48
57
  end
49
58
 
50
- def trans_hello
59
+ def trans_receive_hello
51
60
  trans_receive()
52
61
  end
53
62
 
63
+ def trans_send_hello
64
+ trans_send( Netconf::RPC::MSG_HELLO )
65
+ end
66
+
54
67
  def has_capability?( capability )
55
68
  @capabilities.select{|c| c.include? capability }.pop
56
69
  # note: the caller could also simply use #grep on @capabilities
@@ -71,7 +84,14 @@ module Netconf
71
84
 
72
85
  def rpc_exec( cmd_nx )
73
86
  raise Netconf::StateError unless @state == :NETCONF_OPEN
74
-
87
+
88
+ # add the mandatory message-id and namespace to the RPC
89
+
90
+ rpc_nx = cmd_nx.parent.root
91
+ rpc_nx.default_namespace = Netconf::NAMESPACE
92
+ rpc_nx['message-id'] = @rpc_message_id.to_s
93
+ @rpc_message_id += 1
94
+
75
95
  # send the XML command through the transport and
76
96
  # receive the response; then covert it to a Nokogiri XML
77
97
  # object so we can process it.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-09 00:00:00.000000000 Z
13
+ date: 2013-01-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -63,6 +63,7 @@ files:
63
63
  - lib/net/netconf/telnet.rb
64
64
  - lib/net/netconf/transport.rb
65
65
  - lib/net/netconf.rb
66
+ - examples/confd/get-running.rb
66
67
  - examples/jnpr/edit-config-jnpr-set.rb
67
68
  - examples/jnpr/edit-config-jnpr-text.rb
68
69
  - examples/jnpr/edit-config-jnpr.rb
@@ -76,7 +77,7 @@ files:
76
77
  - examples/jnpr/get-inventory-telnet.rb
77
78
  - examples/jnpr/get-inventory.rb
78
79
  - examples/jnpr/scp.rb
79
- homepage: https://github.com/Juniper-Workflow
80
+ homepage: https://github.com/Juniper-Workflow/net-netconf
80
81
  licenses: []
81
82
  post_install_message:
82
83
  rdoc_options: []