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,77 +1,78 @@
1
- require 'net/ssh'
2
-
3
- module Netconf
4
- class SSH < Netconf::Transport
5
-
6
- NETCONF_PORT = 830
7
- NETCONF_SUBSYSTEM = 'netconf'
8
-
9
- def initialize( args_h, &block )
10
- @args = args_h.clone
11
- @trans = Hash.new
12
-
13
- super( &block )
14
- end
15
-
16
- def trans_open( &block )
17
- # open a connection to the NETCONF subsystem
18
- start_args = Hash.new
19
- start_args[:password] ||= @args[:password]
20
- start_args[:passphrase] = @args[:passphrase] || nil
21
- start_args[:port] = @args[:port] || NETCONF_PORT
22
-
23
- @trans[:conn] = Net::SSH.start( @args[:target], @args[:username], start_args )
24
- @trans[:chan] = @trans[:conn].open_channel{ |ch| ch.subsystem( NETCONF_SUBSYSTEM ) }
25
- end
26
-
27
- def trans_close
28
- @trans[:chan].close if @trans[:chan]
29
- @trans[:conn].close if @trans[:conn]
30
- end
31
-
32
- def trans_receive
33
- @trans[:rx_buf] = ''
34
- @trans[:more] = true
35
-
36
- # collect the response data as it comes back ...
37
- # the "on" functions must be set before calling
38
- # the #loop method
39
-
40
- @trans[:chan].on_data do |ch, data|
41
- if data.include?( RPC::MSG_END )
42
- data.slice!( RPC::MSG_END )
43
- @trans[:rx_buf] << data unless data.empty?
44
- @trans[:more] = false
45
- else
46
- @trans[:rx_buf] << data
47
- end
48
- end
49
-
50
- # ... if there are errors ...
51
- @trans[:chan].on_extended_data do |ch, type, data|
52
- @trans[:rx_err] = data
53
- @trans[:more] = false
54
- end
55
-
56
- # the #loop method is what actually performs
57
- # ssh event processing ...
58
-
59
- @trans[:conn].loop { @trans[:more] }
60
-
61
- return @trans[:rx_buf]
62
- end
63
-
64
- def trans_send( cmd_str )
65
- @trans[:chan].send_data( cmd_str )
66
- end
67
-
68
- # accessor to create an Net::SCP object so the caller can perform
69
- # secure-copy operations (see Net::SCP) for details
70
- def scp
71
- @scp ||= Net::SCP.start( @args[:target], @args[:username], :password => @args[:password] )
72
- end
73
-
74
- end # class: SSH
75
- end #module: Netconf
76
-
77
- require 'net/netconf/ssh'
1
+ require 'net/ssh'
2
+
3
+ module Netconf
4
+ class SSH < Netconf::Transport
5
+
6
+ NETCONF_PORT = 830
7
+ NETCONF_SUBSYSTEM = 'netconf'
8
+
9
+ def initialize( args_h, &block )
10
+ @args = args_h.clone
11
+ @trans = Hash.new
12
+
13
+ super( &block )
14
+ end
15
+
16
+ def trans_open( &block )
17
+ # open a connection to the NETCONF subsystem
18
+ start_args = Hash.new
19
+ start_args[:password] ||= @args[:password]
20
+ start_args[:passphrase] = @args[:passphrase] || nil
21
+ start_args[:port] = @args[:port] || NETCONF_PORT
22
+ start_args.merge!(@args[:ssh_args]) if @args[:ssh_args]
23
+
24
+ @trans[:conn] = Net::SSH.start( @args[:target], @args[:username], start_args )
25
+ @trans[:chan] = @trans[:conn].open_channel{ |ch| ch.subsystem( NETCONF_SUBSYSTEM ) }
26
+ end
27
+
28
+ def trans_close
29
+ @trans[:chan].close if @trans[:chan]
30
+ @trans[:conn].close if @trans[:conn]
31
+ end
32
+
33
+ def trans_receive
34
+ @trans[:rx_buf] = ''
35
+ @trans[:more] = true
36
+
37
+ # collect the response data as it comes back ...
38
+ # the "on" functions must be set before calling
39
+ # the #loop method
40
+
41
+ @trans[:chan].on_data do |ch, data|
42
+ if data.include?( RPC::MSG_END )
43
+ data.slice!( RPC::MSG_END )
44
+ @trans[:rx_buf] << data unless data.empty?
45
+ @trans[:more] = false
46
+ else
47
+ @trans[:rx_buf] << data
48
+ end
49
+ end
50
+
51
+ # ... if there are errors ...
52
+ @trans[:chan].on_extended_data do |ch, type, data|
53
+ @trans[:rx_err] = data
54
+ @trans[:more] = false
55
+ end
56
+
57
+ # the #loop method is what actually performs
58
+ # ssh event processing ...
59
+
60
+ @trans[:conn].loop { @trans[:more] }
61
+
62
+ return @trans[:rx_buf]
63
+ end
64
+
65
+ def trans_send( cmd_str )
66
+ @trans[:chan].send_data( cmd_str )
67
+ end
68
+
69
+ # accessor to create an Net::SCP object so the caller can perform
70
+ # secure-copy operations (see Net::SCP) for details
71
+ def scp
72
+ @scp ||= Net::SCP.start( @args[:target], @args[:username], :password => @args[:password] )
73
+ end
74
+
75
+ end # class: SSH
76
+ end #module: Netconf
77
+
78
+ require 'net/netconf/ssh'
@@ -1,52 +1,52 @@
1
- require 'net/telnet'
2
-
3
- module Netconf
4
-
5
- class Telnet < Netconf::Transport
6
-
7
- def initialize( args, trans_args = nil, &block )
8
- os_type = args[:os_type] || Netconf::DEFAULT_OS_TYPE
9
- @args = args.clone
10
-
11
- # extend this instance with the capabilities of the specific console
12
- # type; it needs to define #login and #start_netconf session
13
- begin
14
- extend Netconf::const_get( os_type )::TransTelnet
15
- rescue NameError
16
- # no extensions available ...
17
- end
18
-
19
- my_trans_args = {}
20
- my_trans_args["Host"] = @args[:target]
21
- my_trans_args["Port"] = @args[:port] if @args[:port]
22
-
23
- @trans = Net::Telnet.new( my_trans_args )
24
-
25
- @trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
26
- @trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
27
-
28
- super( &block )
29
- end
30
-
31
- def trans_open( &block )
32
- trans_login()
33
- trans_start_netconf()
34
- self
35
- end
36
-
37
- def trans_close
38
- @trans.write Netconf::RPC::MSG_CLOSE_SESSION
39
- @trans.close
40
- end
41
-
42
- def trans_send( cmd_str )
43
- @trans.write( cmd_str )
44
- end
45
-
46
- def trans_receive
47
- rsp = @trans.waitfor( Netconf::RPC::MSG_END_RE )
48
- rsp.chomp!( Netconf::RPC::MSG_END + "\n" )
49
- end
50
-
51
- end # class: Serial
52
- end # module: Netconf
1
+ require 'net/telnet'
2
+
3
+ module Netconf
4
+
5
+ class Telnet < Netconf::Transport
6
+
7
+ def initialize( args, trans_args = nil, &block )
8
+ os_type = args[:os_type] || Netconf::DEFAULT_OS_TYPE
9
+ @args = args.clone
10
+
11
+ # extend this instance with the capabilities of the specific console
12
+ # type; it needs to define #login and #start_netconf session
13
+ begin
14
+ extend Netconf::const_get( os_type )::TransTelnet
15
+ rescue NameError
16
+ # no extensions available ...
17
+ end
18
+
19
+ my_trans_args = {}
20
+ my_trans_args["Host"] = @args[:target]
21
+ my_trans_args["Port"] = @args[:port] if @args[:port]
22
+
23
+ @trans = Net::Telnet.new( my_trans_args )
24
+
25
+ @trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
26
+ @trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
27
+
28
+ super( &block )
29
+ end
30
+
31
+ def trans_open( &block )
32
+ trans_login()
33
+ trans_start_netconf()
34
+ self
35
+ end
36
+
37
+ def trans_close
38
+ @trans.write Netconf::RPC::MSG_CLOSE_SESSION
39
+ @trans.close
40
+ end
41
+
42
+ def trans_send( cmd_str )
43
+ @trans.write( cmd_str )
44
+ end
45
+
46
+ def trans_receive
47
+ rsp = @trans.waitfor( Netconf::RPC::MSG_END_RE )
48
+ rsp.chomp!( Netconf::RPC::MSG_END + "\n" )
49
+ end
50
+
51
+ end # class: Serial
52
+ end # module: Netconf
@@ -32,6 +32,14 @@ module Netconf
32
32
 
33
33
  end # initialize
34
34
 
35
+ def open?
36
+ @state == :NETCONF_OPEN
37
+ end
38
+
39
+ def closed?
40
+ @state == :NECONF_CLOSED
41
+ end
42
+
35
43
  def open( &block ) # :yield: specialized transport open, generally not used
36
44
 
37
45
  raise Netconf::StateError if @state == :NETCONF_OPEN
@@ -79,6 +87,7 @@ module Netconf
79
87
  # string in; string out
80
88
  def send_and_receive( cmd_str )
81
89
  trans_send( cmd_str )
90
+ trans_send( RPC::MSG_END )
82
91
  trans_receive()
83
92
  end
84
93
 
@@ -111,12 +120,26 @@ module Netconf
111
120
 
112
121
  rsp_nx = rsp_nx.root
113
122
 
114
- # the <rpc-error> could either be at the toplevel or
115
- # as a child element of toplevel.
123
+ # check for rpc-error elements. these could be
124
+ # located anywhere in the structured response
116
125
 
117
- if rsp_nx.xpath( "rpc-error|*/rpc-error" )[0]
118
- exception = Netconf::RPC.get_exception( cmd_nx )
119
- raise exception.new( self, cmd_nx, rsp_nx )
126
+ rpc_errs = rsp_nx.xpath('//self::rpc-error')
127
+ if rpc_errs.count > 0
128
+
129
+ # look for rpc-errors that have a severity == 'error'
130
+ # in some cases the rpc-error is generated with
131
+ # severity == 'warning'
132
+
133
+ sev_err = rpc_errs.xpath('error-severity[. = "error"]')
134
+
135
+ # if there are rpc-error with severity == 'error'
136
+ # or if the caller wants to raise if severity == 'warning'
137
+ # then generate the exception
138
+
139
+ if(( sev_err.count > 0 ) || Netconf::raise_on_warning )
140
+ exception = Netconf::RPC.get_exception( cmd_nx )
141
+ raise exception.new( self, cmd_nx, rsp_nx )
142
+ end
120
143
  end
121
144
 
122
145
  # return the XML with context at toplevel element; i.e.
@@ -0,0 +1,3 @@
1
+ module Netconf
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeremy Schulman
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: nokogiri
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ! '>='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: net-ssh
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ! '>='
37
33
  - !ruby/object:Gem::Version
@@ -39,11 +35,24 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ! '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: 2.5.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: net-scp
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.1
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.1.1
47
56
  description: Extensible Ruby-based NETCONF client
48
57
  email: jschulman@juniper.net
49
58
  executables: []
@@ -64,6 +73,7 @@ files:
64
73
  - lib/net/netconf/ssh.rb
65
74
  - lib/net/netconf/telnet.rb
66
75
  - lib/net/netconf/transport.rb
76
+ - lib/net/netconf/version.rb
67
77
  - lib/net/netconf.rb
68
78
  - examples/confd/get-running.rb
69
79
  - examples/jnpr/edit-config-jnpr-set.rb
@@ -79,28 +89,27 @@ files:
79
89
  - examples/jnpr/get-inventory-telnet.rb
80
90
  - examples/jnpr/get-inventory.rb
81
91
  - examples/jnpr/scp.rb
82
- homepage: https://github.com/Juniper-Workflow/net-netconf
92
+ homepage: https://github.com/Juniper/net-netconf
83
93
  licenses: []
94
+ metadata: {}
84
95
  post_install_message:
85
96
  rdoc_options: []
86
97
  require_paths:
87
98
  - lib
88
99
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
100
  requirements:
91
101
  - - ! '>='
92
102
  - !ruby/object:Gem::Version
93
103
  version: '0'
94
104
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
105
  requirements:
97
106
  - - ! '>='
98
107
  - !ruby/object:Gem::Version
99
108
  version: '0'
100
109
  requirements: []
101
110
  rubyforge_project:
102
- rubygems_version: 1.8.23
111
+ rubygems_version: 2.0.4
103
112
  signing_key:
104
- specification_version: 3
113
+ specification_version: 4
105
114
  summary: NETCONF client
106
115
  test_files: []