net-netconf 0.4.1 → 0.4.2
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.
- checksums.yaml +4 -4
- data/lib/net/netconf.rb +37 -0
- data/lib/net/netconf/exception.rb +11 -11
- data/lib/net/netconf/ioproc.rb +24 -54
- data/lib/net/netconf/jnpr.rb +1 -1
- data/lib/net/netconf/jnpr/ioproc.rb +2 -2
- data/lib/net/netconf/jnpr/junos_config.rb +1 -1
- data/lib/net/netconf/jnpr/rpc.rb +87 -88
- data/lib/net/netconf/jnpr/serial.rb +4 -4
- data/lib/net/netconf/jnpr/ssh.rb +10 -10
- data/lib/net/netconf/jnpr/telnet.rb +7 -7
- data/lib/net/netconf/rpc.rb +31 -31
- data/lib/net/netconf/rpc_std.rb +19 -23
- data/lib/net/netconf/serial.rb +40 -71
- data/lib/net/netconf/ssh.rb +45 -44
- data/lib/net/netconf/telnet.rb +27 -30
- data/lib/net/netconf/transport.rb +23 -30
- data/lib/net/netconf/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 741e277664fb1c1660b55878c50a47e0b4d21887
|
4
|
+
data.tar.gz: 7b46a74d28874a65a1f346a9303b6e24744dcb61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 058610c26844ee71ffbfa832f300af0e9bc08e66be87325f53ade81730e0ea8a1feed488c4556aea3bab6504ce25e9e155cab5dfad4d5c088c42e1148ecb6e1e
|
7
|
+
data.tar.gz: ba146336a067d81baad536e725cf5c981ef1139c50ee78e5373458da9b1c1cd18cdc51a368eb15fefd620750282cb2bf596e561bfe5af800cabe6e3651e33737
|
data/lib/net/netconf.rb
CHANGED
@@ -17,8 +17,45 @@ module Netconf
|
|
17
17
|
def self.raise_on_warning=( bool )
|
18
18
|
@raise_on_warning = bool
|
19
19
|
end
|
20
|
+
|
20
21
|
def self.raise_on_warning
|
21
22
|
@raise_on_warning
|
22
23
|
end
|
23
24
|
|
25
|
+
def self.waitfor(on_re = nil)
|
26
|
+
time_out = @trans_timeout
|
27
|
+
wait_io = @trans_waitio
|
28
|
+
|
29
|
+
time_out = nil if time_out == false
|
30
|
+
done = false
|
31
|
+
rx_buf = ''
|
32
|
+
|
33
|
+
until( rx_buf.match( on_re ) and not IO::select( [@trans], nil, nil, wait_io ) )
|
34
|
+
|
35
|
+
unless IO::select( [@trans], nil, nil, time_out )
|
36
|
+
raise TimeoutError, 'Netconf IO timed out while waiting for more data'
|
37
|
+
end
|
38
|
+
|
39
|
+
begin
|
40
|
+
|
41
|
+
rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
|
42
|
+
|
43
|
+
rx_buf += rx_some
|
44
|
+
break if rx_buf.match( on_re )
|
45
|
+
|
46
|
+
rescue EOFError # End of file reached
|
47
|
+
rx_buf = nil if rx_buf == ''
|
48
|
+
break # out of outer 'until' loop
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
rx_buf
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.trans_receive
|
56
|
+
got = waitfor( Netconf::RPC::MSG_END_RE )
|
57
|
+
msg_end = got.rindex( Netconf::RPC::MSG_END )
|
58
|
+
got[msg_end .. -1] = ''
|
59
|
+
got
|
60
|
+
end
|
24
61
|
end
|
@@ -1,37 +1,37 @@
|
|
1
1
|
module Netconf
|
2
|
-
|
2
|
+
|
3
3
|
class InitError < StandardError
|
4
4
|
end
|
5
|
-
|
5
|
+
|
6
6
|
class StateError < StandardError
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class OpenError < StandardError
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
class RpcError < StandardError
|
13
13
|
attr_reader :trans
|
14
14
|
attr_reader :cmd, :rsp
|
15
|
-
|
15
|
+
|
16
16
|
def initialize( trans, cmd, rsp )
|
17
17
|
@trans = trans
|
18
|
-
@cmd = cmd; @rsp = rsp;
|
18
|
+
@cmd = cmd; @rsp = rsp;
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def to_s
|
22
22
|
"RPC command error: #{cmd.first_element_child.name}\n#{rsp.to_xml}"
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
class EditError < Netconf::RpcError
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
class LockError < Netconf::RpcError
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
class CommitError < Netconf::RpcError
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
class ValidateError < Netconf::RpcError
|
36
36
|
end
|
37
37
|
|
data/lib/net/netconf/ioproc.rb
CHANGED
@@ -1,88 +1,58 @@
|
|
1
1
|
module Netconf
|
2
|
-
|
2
|
+
|
3
3
|
class IOProc < Netconf::Transport
|
4
|
-
|
4
|
+
|
5
5
|
DEFAULT_RDBLKSZ = (1024*1024)
|
6
|
-
|
6
|
+
|
7
7
|
attr_reader :args
|
8
|
-
|
8
|
+
|
9
9
|
def initialize( args_h = {}, &block )
|
10
10
|
os_type = args_h[:os_type] || Netconf::DEFAULT_OS_TYPE
|
11
|
-
|
11
|
+
|
12
12
|
@args = args_h.clone
|
13
|
-
|
13
|
+
|
14
14
|
# an OS specific implementation must exist to support this transport type
|
15
|
-
extend Netconf::const_get( os_type )::IOProc
|
16
|
-
|
15
|
+
extend Netconf::const_get( os_type )::IOProc
|
16
|
+
|
17
17
|
@trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
|
18
18
|
@trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
|
19
19
|
|
20
|
-
super( &block )
|
21
|
-
end
|
22
|
-
|
20
|
+
super( &block )
|
21
|
+
end
|
22
|
+
|
23
23
|
# the OS specific transport must implement this method
|
24
|
-
def trans_open # :yield: self
|
24
|
+
def trans_open # :yield: self
|
25
25
|
raise "Unsupported IOProc"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def trans_receive_hello
|
29
29
|
trans_receive()
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def trans_send_hello
|
33
33
|
nil
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def trans_close
|
37
37
|
@trans.write Netconf::RPC::MSG_CLOSE_SESSION
|
38
38
|
@trans.close
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def trans_send( cmd_str )
|
42
42
|
@trans.write( cmd_str )
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def trans_receive
|
46
|
-
|
47
|
-
msg_end = got.rindex( Netconf::RPC::MSG_END )
|
48
|
-
got[msg_end .. -1] = ''
|
49
|
-
got
|
46
|
+
Netconf.trans_receive
|
50
47
|
end
|
51
|
-
|
48
|
+
|
52
49
|
def puts( str = nil )
|
53
50
|
@trans.puts( str )
|
54
51
|
end
|
55
|
-
|
56
|
-
def waitfor( on_re )
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
time_out = nil if time_out == false
|
62
|
-
done = false
|
63
|
-
rx_buf = ''
|
64
|
-
|
65
|
-
until( rx_buf.match( on_re ) and not IO::select( [@trans], nil, nil, wait_io ) )
|
66
|
-
|
67
|
-
unless IO::select( [@trans], nil, nil, time_out )
|
68
|
-
raise TimeoutError, "Netconf IO timed out while waiting for more data"
|
69
|
-
end
|
70
|
-
|
71
|
-
begin
|
72
|
-
|
73
|
-
rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
|
74
|
-
|
75
|
-
rx_buf += rx_some
|
76
|
-
break if rx_buf.match( on_re )
|
77
|
-
|
78
|
-
rescue EOFError # End of file reached
|
79
|
-
rx_buf = nil if rx_buf == ''
|
80
|
-
break # out of outer 'until' loop
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
rx_buf
|
85
|
-
end
|
86
|
-
|
52
|
+
|
53
|
+
def waitfor( on_re )
|
54
|
+
Netconf.waitfor(on_re)
|
55
|
+
end
|
56
|
+
|
87
57
|
end # class: IOProc
|
88
58
|
end # module: Netconf
|
data/lib/net/netconf/jnpr.rb
CHANGED
data/lib/net/netconf/jnpr/rpc.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## -----------------------------------------------------------------------
|
2
|
-
## This file contains the Junos specific RPC methods that are generated
|
3
|
-
## specifically and different as generated by the Netconf::RPC::Builder
|
2
|
+
## This file contains the Junos specific RPC methods that are generated
|
3
|
+
## specifically and different as generated by the Netconf::RPC::Builder
|
4
4
|
## module. These are specifically the following:
|
5
5
|
##
|
6
6
|
## get_configuration - alternative NETCONF: 'get-config'
|
@@ -14,149 +14,148 @@
|
|
14
14
|
|
15
15
|
module Netconf
|
16
16
|
module RPC
|
17
|
-
module Junos
|
18
|
-
|
17
|
+
module Junos
|
18
|
+
|
19
19
|
def lock_configuration
|
20
|
-
lock(
|
21
|
-
end
|
22
|
-
|
20
|
+
lock('candidate')
|
21
|
+
end
|
22
|
+
|
23
23
|
def check_configuration
|
24
|
-
validate(
|
25
|
-
end
|
26
|
-
|
27
|
-
def commit_configuration(
|
28
|
-
rpc = Netconf::RPC::Builder.commit_configuration(
|
29
|
-
Netconf::RPC.set_exception(
|
30
|
-
@trans.rpc_exec(
|
24
|
+
validate('candidate')
|
25
|
+
end
|
26
|
+
|
27
|
+
def commit_configuration(params = nil, attrs = nil)
|
28
|
+
rpc = Netconf::RPC::Builder.commit_configuration(params, attrs)
|
29
|
+
Netconf::RPC.set_exception(rpc, Netconf::CommitError)
|
30
|
+
@trans.rpc_exec(rpc)
|
31
|
+
end
|
32
|
+
|
33
|
+
def nokogiri_case(arg)
|
34
|
+
filter = case arg
|
35
|
+
when Nokogiri::XML::Builder then arg.doc.root
|
36
|
+
when Nokogiri::XML::Document then arg.root
|
37
|
+
else arg
|
31
38
|
end
|
32
39
|
|
33
|
-
def get_configuration(
|
34
|
-
|
40
|
+
def get_configuration(*args)
|
35
41
|
filter = nil
|
36
|
-
|
42
|
+
|
37
43
|
while arg = args.shift
|
38
44
|
case arg.class.to_s
|
39
|
-
when /^Nokogiri/
|
40
|
-
|
41
|
-
when Nokogiri::XML::Builder then arg.doc.root
|
42
|
-
when Nokogiri::XML::Document then arg.root
|
43
|
-
else arg
|
44
|
-
end
|
45
|
+
when /^Nokogiri/
|
46
|
+
nokogiri_case(arg)
|
45
47
|
when 'Hash' then attrs = arg
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
51
|
rpc = Nokogiri::XML('<rpc><get-configuration/></rpc>').root
|
50
|
-
Netconf::RPC.add_attributes(
|
51
|
-
|
52
|
+
Netconf::RPC.add_attributes(rpc.first_element_child, attrs) if attrs
|
53
|
+
|
52
54
|
if block_given?
|
53
|
-
Nokogiri::XML::Builder.with(rpc.at(
|
54
|
-
xml.configuration
|
55
|
-
yield(
|
56
|
-
|
55
|
+
Nokogiri::XML::Builder.with(rpc.at('get-configuration')) do |xml|
|
56
|
+
xml.configuration do
|
57
|
+
yield(xml)
|
58
|
+
end
|
59
|
+
end
|
57
60
|
elsif filter
|
58
61
|
# filter must have toplevel = <configuration>
|
59
|
-
|
62
|
+
# *MUST* use the .dup so we don't disrupt the original filter
|
63
|
+
rpc.first_element_child << filter.dup
|
60
64
|
end
|
61
|
-
|
62
|
-
@trans.rpc_exec(
|
65
|
+
|
66
|
+
@trans.rpc_exec(rpc)
|
63
67
|
end
|
64
|
-
|
65
|
-
def load_configuration(
|
66
|
-
|
68
|
+
|
69
|
+
def load_configuration(*args)
|
67
70
|
config = nil
|
68
|
-
|
71
|
+
|
69
72
|
# default format is XML
|
70
|
-
attrs = { :
|
71
|
-
|
73
|
+
attrs = { format: 'xml' }
|
74
|
+
|
72
75
|
while arg = args.shift
|
73
76
|
case arg.class.to_s
|
74
|
-
when /^Nokogiri/
|
75
|
-
|
76
|
-
when Nokogiri::XML::Builder then arg.doc.root
|
77
|
-
when Nokogiri::XML::Document then arg.root
|
78
|
-
else arg
|
79
|
-
end
|
77
|
+
when /^Nokogiri/
|
78
|
+
nokogiri_case(arg)
|
80
79
|
when 'Hash' then attrs.merge! arg
|
81
80
|
when 'Array' then config = arg.join("\n")
|
82
81
|
when 'String' then config = arg
|
83
82
|
end
|
84
83
|
end
|
85
|
-
|
84
|
+
|
86
85
|
case attrs[:format]
|
87
86
|
when 'set'
|
88
87
|
toplevel = 'configuration-set'
|
89
88
|
attrs[:format] = 'text'
|
90
|
-
attrs[:action] = 'set'
|
89
|
+
attrs[:action] = 'set'
|
91
90
|
when 'text'
|
92
|
-
toplevel = 'configuration-text'
|
91
|
+
toplevel = 'configuration-text'
|
93
92
|
when 'xml'
|
94
|
-
toplevel = 'configuration'
|
95
|
-
end
|
96
|
-
|
93
|
+
toplevel = 'configuration'
|
94
|
+
end
|
95
|
+
|
97
96
|
rpc = Nokogiri::XML('<rpc><load-configuration/></rpc>').root
|
98
97
|
ld_cfg = rpc.first_element_child
|
99
|
-
Netconf::RPC.add_attributes(
|
100
|
-
|
98
|
+
Netconf::RPC.add_attributes(ld_cfg, attrs) if attrs
|
99
|
+
|
101
100
|
if block_given?
|
102
101
|
if attrs[:format] == 'xml'
|
103
|
-
Nokogiri::XML::Builder.with(
|
104
|
-
xml.send(
|
105
|
-
yield(
|
106
|
-
|
102
|
+
Nokogiri::XML::Builder.with(ld_cfg) do |xml|
|
103
|
+
xml.send(toplevel) do
|
104
|
+
yield(xml)
|
105
|
+
end
|
106
|
+
end
|
107
107
|
else
|
108
|
-
config = yield # returns String | Array(of stringable)
|
109
|
-
config = config.join("\n") if config.class == Array
|
108
|
+
config = yield # returns String | Array(of stringable)
|
109
|
+
config = config.join("\n") if config.class == Array
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
if config
|
114
114
|
if attrs[:format] == 'xml'
|
115
|
-
# config assumes toplevel = <configuration> given
|
116
|
-
ld_cfg << config.dup
|
115
|
+
# config assumes toplevel = <configuration> given
|
116
|
+
ld_cfg << config.dup # duplicate the config so as to not distrupt it
|
117
117
|
else
|
118
|
-
# config is stringy, so just add it as the text node
|
119
|
-
c_node = Nokogiri::XML::Node.new(
|
118
|
+
# config is stringy, so just add it as the text node
|
119
|
+
c_node = Nokogiri::XML::Node.new(toplevel, rpc)
|
120
120
|
c_node.content = config
|
121
|
-
ld_cfg << c_node
|
121
|
+
ld_cfg << c_node
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
# set a specific exception class on this RPC so it can be
|
126
126
|
# properlly handled by the calling enviornment
|
127
|
-
|
128
|
-
Netconf::RPC
|
129
|
-
@trans.rpc_exec(
|
127
|
+
|
128
|
+
Netconf::RPC.set_exception(rpc, Netconf::EditError)
|
129
|
+
@trans.rpc_exec(rpc)
|
130
130
|
end # load_configuration
|
131
|
-
|
132
|
-
def command(
|
131
|
+
|
132
|
+
def command(cmd_str, attrs = nil)
|
133
133
|
rpc = Nokogiri::XML("<rpc><command>#{cmd_str}</command></rpc>").root
|
134
|
-
Netconf::RPC.add_attributes(
|
135
|
-
@trans.rpc_exec(
|
134
|
+
Netconf::RPC.add_attributes(rpc.at('command'), attrs) if attrs
|
135
|
+
@trans.rpc_exec(rpc)
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
## contributed by 'dgjnpr'
|
139
|
-
def request_pfe_execute(
|
139
|
+
def request_pfe_execute(params = nil)
|
140
140
|
raise ArgumentError, 'Manditorary argument :target missing' unless params[:target]
|
141
141
|
raise ArgumentError, 'Manditorary argument :command missing' unless params[:command]
|
142
142
|
|
143
|
-
rpc_nx = Nokogiri::XML::Builder.new
|
144
|
-
xml.rpc
|
145
|
-
xml.send(
|
146
|
-
xml.send(
|
143
|
+
rpc_nx = Nokogiri::XML::Builder.new do |xml|
|
144
|
+
xml.rpc do
|
145
|
+
xml.send('request-pfe-execute') do
|
146
|
+
xml.send('target', params[:target])
|
147
147
|
if params[:command].class.to_s =~ /^Array/
|
148
|
-
params[:command].each
|
149
|
-
xml.send(
|
150
|
-
|
148
|
+
params[:command].each do |cmd|
|
149
|
+
xml.send('command', cmd)
|
150
|
+
end
|
151
151
|
elsif params[:command].class.to_s =~ /^String/
|
152
|
-
xml.send(
|
152
|
+
xml.send('command', params[:command])
|
153
153
|
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
@trans.rpc_exec(
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
@trans.rpc_exec(rpc_nx)
|
158
158
|
end
|
159
|
-
|
160
|
-
end # module: JUNOS
|
159
|
+
end # module: JUNOS
|
161
160
|
end # module: RPC
|
162
161
|
end # module: Netconf
|