netconf 0.2.5 → 0.3.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.
@@ -1,64 +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
-
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
+
@@ -1,68 +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
-
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
+
@@ -1,62 +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
-
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
+
@@ -1,20 +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
- }
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
+ }
@@ -1,49 +1,49 @@
1
- require 'net/netconf'
2
-
3
- puts "NETCONF v.#{Netconf::VERSION}"
4
-
5
- login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
-
7
- puts "Connecting to device: #{login[:target]}"
8
-
9
- Netconf::SSH.new( login ){ |dev|
10
- puts "Connected."
11
-
12
- # ----------------------------------------------------------------------
13
- # retrieve the full config. Default source is 'running'
14
- # Alternatively you can pass the source name as a string parameter
15
- # to #get_config
16
-
17
- puts "Retrieving full config, please wait ... "
18
- cfgall = dev.rpc.get_config
19
- puts "Showing 'system' hierarchy ..."
20
- puts cfgall.xpath('configuration/system') # JUNOS toplevel config element is <configuration>
21
-
22
- # ----------------------------------------------------------------------
23
- # specifying a filter as a block to get_config
24
-
25
- cfgsvc1 = dev.rpc.get_config{ |x|
26
- x.configuration { x.system { x.services }}
27
- }
28
-
29
- puts "Retrieved services as BLOCK:"
30
- cfgsvc1.xpath('//services/*').each{|s| puts s.name }
31
-
32
- # ----------------------------------------------------------------------
33
- # specifying a filter as a parameter to get_config
34
-
35
- filter = Nokogiri::XML::Builder.new{ |x|
36
- x.configuration { x.system { x.services }}
37
- }
38
-
39
- cfgsvc2 = dev.rpc.get_config( filter )
40
- puts "Retrieved services as PARAM:"
41
- cfgsvc2.xpath('//services/*').each{|s| puts s.name }
42
-
43
- cfgsvc3 = dev.rpc.get_config( filter )
44
- puts "Retrieved services as PARAM, re-used filter"
45
- cfgsvc3.xpath('//services/*').each{|s| puts s.name }
46
- }
47
-
48
-
49
-
1
+ require 'net/netconf'
2
+
3
+ puts "NETCONF v.#{Netconf::VERSION}"
4
+
5
+ login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
6
+
7
+ puts "Connecting to device: #{login[:target]}"
8
+
9
+ Netconf::SSH.new( login ){ |dev|
10
+ puts "Connected."
11
+
12
+ # ----------------------------------------------------------------------
13
+ # retrieve the full config. Default source is 'running'
14
+ # Alternatively you can pass the source name as a string parameter
15
+ # to #get_config
16
+
17
+ puts "Retrieving full config, please wait ... "
18
+ cfgall = dev.rpc.get_config
19
+ puts "Showing 'system' hierarchy ..."
20
+ puts cfgall.xpath('configuration/system') # JUNOS toplevel config element is <configuration>
21
+
22
+ # ----------------------------------------------------------------------
23
+ # specifying a filter as a block to get_config
24
+
25
+ cfgsvc1 = dev.rpc.get_config{ |x|
26
+ x.configuration { x.system { x.services }}
27
+ }
28
+
29
+ puts "Retrieved services as BLOCK:"
30
+ cfgsvc1.xpath('//services/*').each{|s| puts s.name }
31
+
32
+ # ----------------------------------------------------------------------
33
+ # specifying a filter as a parameter to get_config
34
+
35
+ filter = Nokogiri::XML::Builder.new{ |x|
36
+ x.configuration { x.system { x.services }}
37
+ }
38
+
39
+ cfgsvc2 = dev.rpc.get_config( filter )
40
+ puts "Retrieved services as PARAM:"
41
+ cfgsvc2.xpath('//services/*').each{|s| puts s.name }
42
+
43
+ cfgsvc3 = dev.rpc.get_config( filter )
44
+ puts "Retrieved services as PARAM, re-used filter"
45
+ cfgsvc3.xpath('//services/*').each{|s| puts s.name }
46
+ }
47
+
48
+
49
+