net-netconf 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b84dffc3bef4a7c78fa7c383945452a1319f186c
4
+ data.tar.gz: 850b49f0af7e175a8590f7ef447a3d712d81cc4b
5
+ SHA512:
6
+ metadata.gz: ee2f9173a0d140b1a1120b52ada2ea4f4fcc880ee83d1320ff569c10c069a81f17e0c8157247756b58ba7452d7888165311042905d2eafbd9e82a4709d488cfc
7
+ data.tar.gz: 9b2605221513738aa169b05c828b5dbbecc4578d1590a0ae8a8abf4a22eb70832d27e342492aef141cabd7f562c2817733d17be505c29a4e0b0fd91b103f30b2
@@ -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
+
@@ -0,0 +1,55 @@
1
+ require 'net/netconf/jnpr'
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ new_host_name = "vsrx"
8
+
9
+ puts "Connecting to device: #{login[:target]}"
10
+
11
+ Netconf::SSH.new( login ){ |dev|
12
+ puts "Connected!"
13
+
14
+ location = []
15
+ location << 'set system location building "Main Campus, C"'
16
+ location << "set system location floor 15"
17
+ location << "set system location rack 1117"
18
+
19
+ begin
20
+
21
+ rsp = dev.rpc.lock_configuration
22
+
23
+ # --------------------------------------------------------------------
24
+ # configuration as BLOCK
25
+
26
+ rsp = dev.rpc.load_configuration( :format => 'set' ) {
27
+ "set system host-name #{new_host_name}"
28
+ }
29
+
30
+ # --------------------------------------------------------------------
31
+ # configuration as PARAM
32
+
33
+ rsp = dev.rpc.load_configuration( location, :format => 'set' )
34
+
35
+ rpc = dev.rpc.check_configuration
36
+ rpc = dev.rpc.commit_configuration
37
+ rpc = dev.rpc.unlock_configuration
38
+
39
+ rescue Netconf::LockError => e
40
+ puts "Lock error"
41
+ rescue Netconf::EditError => e
42
+ puts "Edit error"
43
+ rescue Netconf::ValidateError => e
44
+ puts "Validate error"
45
+ rescue Netconf::CommitError => e
46
+ puts "Commit error"
47
+ rescue Netconf::RpcError => e
48
+ puts "General RPC error"
49
+ else
50
+ puts "Configuration Committed."
51
+ end
52
+ }
53
+
54
+
55
+
@@ -0,0 +1,64 @@
1
+ require 'net/netconf/jnpr'
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ new_host_name = "vsrx-gizmo"
8
+
9
+ puts "Connecting to device: #{login[:target]}"
10
+
11
+ Netconf::SSH.new( login ){ |dev|
12
+ puts "Connected!"
13
+
14
+ location = <<EOCONF
15
+ system {
16
+ location {
17
+ building "Main Campus, E"
18
+ floor 15
19
+ rack 1117
20
+ }
21
+ }
22
+ EOCONF
23
+
24
+ begin
25
+
26
+ rsp = dev.rpc.lock_configuration
27
+
28
+ # --------------------------------------------------------------------
29
+ # configuration as BLOCK
30
+
31
+ rsp = dev.rpc.load_configuration( :format => 'text' ) {
32
+ <<-EOCONF
33
+ system {
34
+ host-name #{new_host_name}
35
+ }
36
+ EOCONF
37
+ }
38
+
39
+ # --------------------------------------------------------------------
40
+ # configuration as PARAM
41
+
42
+ rsp = dev.rpc.load_configuration( location, :format => 'text' )
43
+
44
+ rpc = dev.rpc.check_configuration
45
+ rpc = dev.rpc.commit_configuration
46
+ rpc = dev.rpc.unlock_configuration
47
+
48
+ rescue Netconf::LockError => e
49
+ puts "Lock error"
50
+ rescue Netconf::EditError => e
51
+ puts "Edit error"
52
+ rescue Netconf::ValidateError => e
53
+ puts "Validate error"
54
+ rescue Netconf::CommitError => e
55
+ puts "Commit error"
56
+ rescue Netconf::RpcError => e
57
+ puts "General RPC error"
58
+ else
59
+ puts "Configuration Committed."
60
+ end
61
+ }
62
+
63
+
64
+
@@ -0,0 +1,73 @@
1
+ require 'net/netconf/jnpr'
2
+
3
+ puts "NETCONF v#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'ex4', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ new_host_name = "ex4-abc"
8
+
9
+ puts "Connecting to device: #{login[:target]}"
10
+
11
+ Netconf::SSH.new( login ){ |dev|
12
+ puts "Connected!"
13
+
14
+ # when providing a collection of configuration,
15
+ # you need to include the <configuration> as the
16
+ # toplevel element
17
+
18
+ location = Nokogiri::XML::Builder.new{ |x|
19
+ x.configuration {
20
+ x.system {
21
+ x.location {
22
+ x.building "Main Campus, D"
23
+ x.floor 22
24
+ x.rack 38
25
+ }
26
+ }
27
+ x.system {
28
+ x.services {
29
+ x.ftp;
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ begin
36
+
37
+ rsp = dev.rpc.lock_configuration
38
+
39
+ # --------------------------------------------------------------------
40
+ # configuration as PARAM
41
+
42
+ rsp = dev.rpc.load_configuration( location, :action => 'replace' )
43
+
44
+ # --------------------------------------------------------------------
45
+ # configuration as BLOCK
46
+
47
+ rsp = dev.rpc.load_configuration{ |x|
48
+ x.system {
49
+ x.send(:'host-name', new_host_name )
50
+ }
51
+ }
52
+
53
+ rpc = dev.rpc.check_configuration
54
+ rpc = dev.rpc.commit_configuration
55
+ rpc = dev.rpc.unlock_configuration
56
+
57
+ rescue Netconf::LockError => e
58
+ puts "Lock error"
59
+ rescue Netconf::EditError => e
60
+ puts "Edit error"
61
+ rescue Netconf::ValidateError => e
62
+ puts "Validate error"
63
+ rescue Netconf::CommitError => e
64
+ puts "Commit error"
65
+ rescue Netconf::RpcError => e
66
+ puts "General RPC error"
67
+ else
68
+ puts "Configuration Committed."
69
+ end
70
+ }
71
+
72
+
73
+
@@ -0,0 +1,64 @@
1
+ require 'net/netconf'
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ new_host_name = "vsrx-abc"
8
+
9
+ puts "Connecting to device: #{login[:target]}"
10
+
11
+ Netconf::SSH.new( login ){ |dev|
12
+ puts "Connected!"
13
+
14
+ target = 'candidate'
15
+
16
+ location = Nokogiri::XML::Builder.new{ |x| x.configuration {
17
+ x.system {
18
+ x.location {
19
+ x.building "Main Campus, A"
20
+ x.floor 5
21
+ x.rack 27
22
+ }
23
+ }
24
+ }}
25
+
26
+ begin
27
+
28
+ rsp = dev.rpc.lock target
29
+
30
+ # --------------------------------------------------------------------
31
+ # configuration as BLOCK
32
+
33
+ rsp = dev.rpc.edit_config{ |x| x.configuration {
34
+ x.system {
35
+ x.send(:'host-name', new_host_name )
36
+ }
37
+ }}
38
+
39
+ # --------------------------------------------------------------------
40
+ # configuration as PARAM
41
+
42
+ rsp = dev.rpc.edit_config( location )
43
+
44
+ rsp = dev.rpc.validate target
45
+ rpc = dev.rpc.commit
46
+ rpc = dev.rpc.unlock target
47
+
48
+ rescue Netconf::LockError => e
49
+ puts "Lock error"
50
+ rescue Netconf::EditError => e
51
+ puts "Edit error"
52
+ rescue Netconf::ValidateError => e
53
+ puts "Validate error"
54
+ rescue Netconf::CommitError => e
55
+ puts "Commit error"
56
+ rescue Netconf::RpcError => e
57
+ puts "General RPC error"
58
+ else
59
+ puts "Configuration Committed."
60
+ end
61
+ }
62
+
63
+
64
+
@@ -0,0 +1,68 @@
1
+ require 'net/netconf'
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ new_host_name = "vsrx"
8
+
9
+ puts "Connecting to device: #{login[:target]}"
10
+
11
+ Netconf::SSH.new( login ){ |dev|
12
+ puts "Connected!"
13
+
14
+ target = 'candidate'
15
+
16
+ location = Nokogiri::XML::Builder.new{ |x| x.send(:'configuration-text', <<-EOCONF
17
+ system {
18
+ location {
19
+ building "Main Campus, ABC123"
20
+ floor 5
21
+ rack 27
22
+ }
23
+ }
24
+ EOCONF
25
+ )}
26
+
27
+
28
+ begin
29
+
30
+ rsp = dev.rpc.lock target
31
+
32
+ # --------------------------------------------------------------------
33
+ # configuration as BLOCK
34
+
35
+ rsp = dev.rpc.edit_config(:toplevel => 'config-text'){
36
+ |x| x.send(:'configuration-text', <<EOCONF
37
+ system {
38
+ host-name #{new_host_name};
39
+ }
40
+ EOCONF
41
+ )}
42
+
43
+ # --------------------------------------------------------------------
44
+ # configuration as PARAM
45
+
46
+ rsp = dev.rpc.edit_config( location, :toplevel => 'config-text' )
47
+
48
+ rsp = dev.rpc.validate target
49
+ rpc = dev.rpc.commit
50
+ rpc = dev.rpc.unlock target
51
+
52
+ rescue Netconf::LockError => e
53
+ puts "Lock error"
54
+ rescue Netconf::EditError => e
55
+ puts "Edit error"
56
+ rescue Netconf::ValidateError => e
57
+ puts "Validate error"
58
+ rescue Netconf::CommitError => e
59
+ puts "Commit error"
60
+ rescue Netconf::RpcError => e
61
+ puts "General RPC error"
62
+ else
63
+ puts "Configuration Committed."
64
+ end
65
+ }
66
+
67
+
68
+
@@ -0,0 +1,62 @@
1
+ require 'net/netconf/jnpr' # note: including Juniper specific extension
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'ex4', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ puts "Connecting to device: #{login[:target]}"
8
+
9
+ Netconf::SSH.new( login ){ |dev|
10
+ puts "Connected."
11
+
12
+ puts "Retrieving full config, please wait ... "
13
+ cfgall = dev.rpc.get_configuration # Junos specific RPC
14
+ puts "Showing 'system' hierarchy ..."
15
+ puts cfgall.xpath('system') # Root is <configuration>, so don't need to include it in XPath
16
+
17
+ # ----------------------------------------------------------------------
18
+ # specifying a filter as a block to get_configuration
19
+ # Junos extension does the proper toplevel wrapping
20
+
21
+ puts "Retrieved services from BLOCK, as XML:"
22
+
23
+ cfgsvc1_1 = dev.rpc.get_configuration{ |x|
24
+ x.system { x.services }
25
+ x.system { x.login }
26
+ }
27
+
28
+ cfgsvc1_1.xpath('system/services/*').each{|s| puts s.name }
29
+
30
+ puts "Retrieved services from BLOCK, as TEXT:"
31
+
32
+ cfgsvc1_2 = dev.rpc.get_configuration( :format => 'text' ){ |x|
33
+ x.system { x.services }
34
+ }
35
+
36
+ puts cfgsvc1_2.text
37
+
38
+ # ----------------------------------------------------------------------
39
+ # specifying a filter as a parameter to get_configuration
40
+ # you must wrap the config in a toplevel <configuration> element
41
+
42
+ filter = Nokogiri::XML::Builder.new{ |x| x.configuration {
43
+ x.system { x.services }
44
+ x.system { x.login }
45
+ }}
46
+
47
+ puts "Retrieved services by PARAM, as XML"
48
+
49
+ cfgsvc2 = dev.rpc.get_configuration( filter )
50
+ cfgsvc2.xpath('system/services/*').each{|s| puts s.name }
51
+
52
+ # ----------------------------------------------------------------------
53
+ # specifying a filter as a parameter to get_configuration,
54
+ # get response back in "text" format
55
+
56
+ puts "Retrieved services by PARAM, as TEXT:"
57
+ cfgsvc3 = dev.rpc.get_configuration( filter, :format => 'text' )
58
+ puts cfgsvc3.text
59
+ }
60
+
61
+
62
+
@@ -0,0 +1,20 @@
1
+ require 'net/netconf/jnpr'
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ Netconf::SSH.new( login ){ |dev|
8
+
9
+ configs = dev.rpc.get_configuration{ |x|
10
+ x.interfaces( :matching => 'interface[name="ge-*"]' )
11
+ }
12
+
13
+ ge_cfgs = configs.xpath('interfaces/interface')
14
+
15
+ puts "There are #{ge_cfgs.count} GE interfaces:"
16
+ ge_cfgs.each{|ifd|
17
+ units = ifd.xpath('unit').count
18
+ puts " " + ifd.xpath('name')[0].text + " with #{units} unit" + ((units>1) ? "s" : '')
19
+ }
20
+ }