net-netconf 0.4.0 → 0.4.1
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/rpc_std.rb +42 -42
- data/lib/net/netconf/transport.rb +55 -54
- data/lib/net/netconf/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 882b8dffb9e72058c0cfc8d9d245d2a33c445e94
|
4
|
+
data.tar.gz: 6965b0162647568257b9d7f413faf8cc99952301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f74d7e05706421321cc163259181dbb05321440787663a823af37c79c5b70e0b63737cd4cac6912a8ab69c0d4a42f701d93ea4afc4a5c95ac8a567a9b36595dc
|
7
|
+
data.tar.gz: f079cf1748209eb9df67c347c1c225fab5bb2a0d4aae43667dfa759b327e51fd5d1c21dc16edd48b929f553622d598950f5a54b4fa5ba1b8272af7ec8a571f6d
|
data/lib/net/netconf/rpc_std.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
module Netconf
|
1
|
+
module Netconf
|
2
2
|
module RPC
|
3
|
-
|
4
|
-
MSG_END =
|
3
|
+
|
4
|
+
MSG_END = ']]>]]>'
|
5
5
|
MSG_END_RE = /\]\]>\]\]>[\r\n]*$/
|
6
|
-
MSG_CLOSE_SESSION = '<rpc><close-session/></rpc>'
|
6
|
+
MSG_CLOSE_SESSION = '<rpc><close-session/></rpc>'
|
7
7
|
MSG_HELLO = <<-EOM
|
8
8
|
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
|
9
9
|
<capabilities>
|
@@ -13,55 +13,55 @@ module Netconf
|
|
13
13
|
EOM
|
14
14
|
|
15
15
|
module Standard
|
16
|
-
|
17
|
-
def lock( target )
|
16
|
+
|
17
|
+
def lock( target )
|
18
18
|
rpc = Nokogiri::XML( "<rpc><lock><target><#{target}/></target></lock></rpc>" ).root
|
19
19
|
Netconf::RPC.set_exception( rpc, Netconf::LockError )
|
20
|
-
@trans.rpc_exec( rpc )
|
20
|
+
@trans.rpc_exec( rpc )
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def unlock( target )
|
24
24
|
rpc = Nokogiri::XML( "<rpc><unlock><target><#{target}/></target></unlock></rpc>" ).root
|
25
|
-
@trans.rpc_exec( rpc )
|
25
|
+
@trans.rpc_exec( rpc )
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def validate( source )
|
29
29
|
rpc = Nokogiri::XML( "<rpc><validate><source><#{source}/></source></validate></rpc>" ).root
|
30
|
-
Netconf::RPC.set_exception( rpc, Netconf::ValidateError )
|
31
|
-
@trans.rpc_exec( rpc )
|
30
|
+
Netconf::RPC.set_exception( rpc, Netconf::ValidateError )
|
31
|
+
@trans.rpc_exec( rpc )
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def commit
|
35
35
|
rpc = Nokogiri::XML( "<rpc><commit/></rpc>" ).root
|
36
|
-
Netconf::RPC.set_exception( rpc, Netconf::CommitError )
|
37
|
-
@trans.rpc_exec( rpc )
|
36
|
+
Netconf::RPC.set_exception( rpc, Netconf::CommitError )
|
37
|
+
@trans.rpc_exec( rpc )
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def delete_config( target )
|
41
41
|
rpc = Nokogiri::XML( "<rpc><delete-config><target><#{target}/></target></delete-config></rpc>" ).root
|
42
|
-
@trans.rpc_exec( rpc )
|
42
|
+
@trans.rpc_exec( rpc )
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def get_config( *args ) # :yeield: filter_builder
|
46
|
-
|
46
|
+
|
47
47
|
source = 'running' # default source is 'running'
|
48
48
|
filter = nil # no filter by default
|
49
|
-
|
49
|
+
|
50
50
|
while arg = args.shift
|
51
51
|
case arg.class.to_s
|
52
|
-
when /^Nokogiri/
|
52
|
+
when /^Nokogiri/
|
53
53
|
filter = case arg
|
54
54
|
when Nokogiri::XML::Builder then arg.doc.root
|
55
55
|
when Nokogiri::XML::Document then arg.root
|
56
56
|
else arg
|
57
|
-
end
|
57
|
+
end
|
58
58
|
when 'Hash' then attrs = arg
|
59
59
|
when 'String' then source = arg
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
rpc = Nokogiri::XML("<rpc><get-config><source><#{source}/></source></get-config></rpc>").root
|
64
|
-
|
64
|
+
|
65
65
|
if block_given?
|
66
66
|
Nokogiri::XML::Builder.with( rpc.at( 'get-config' )){ |xml|
|
67
67
|
xml.filter( :type => 'subtree' ) {
|
@@ -69,37 +69,37 @@ EOM
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
if filter
|
74
74
|
f_node = Nokogiri::XML::Node.new( 'filter', rpc )
|
75
75
|
f_node['type'] = 'subtree'
|
76
76
|
f_node << filter.dup # copy filter, don't mess with the original since it may be re-used
|
77
77
|
rpc.at('get-config') << f_node
|
78
|
-
end
|
79
|
-
|
80
|
-
@trans.rpc_exec( rpc )
|
78
|
+
end
|
79
|
+
|
80
|
+
@trans.rpc_exec( rpc )
|
81
81
|
end
|
82
82
|
|
83
83
|
def edit_config( *args ) # :yeield: config_builder
|
84
|
-
|
84
|
+
|
85
85
|
toplevel = 'config' # default toplevel config element
|
86
86
|
target = 'candidate' # default source is 'candidate' @@@/JLS hack; need to fix this
|
87
87
|
config = nil
|
88
88
|
options = {}
|
89
|
-
|
89
|
+
|
90
90
|
while arg = args.shift
|
91
91
|
case arg.class.to_s
|
92
|
-
when /^Nokogiri/
|
92
|
+
when /^Nokogiri/
|
93
93
|
config = case arg
|
94
94
|
when Nokogiri::XML::Builder then arg.doc.root
|
95
95
|
when Nokogiri::XML::Document then arg.root
|
96
96
|
else arg
|
97
|
-
end
|
97
|
+
end
|
98
98
|
when 'Hash' then options = arg
|
99
99
|
when 'String' then target = arg
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
toplevel = options[:toplevel] if options[:toplevel]
|
104
104
|
|
105
105
|
rpc_str = <<-EO_RPC
|
@@ -112,7 +112,7 @@ EOM
|
|
112
112
|
EO_RPC
|
113
113
|
|
114
114
|
rpc = Nokogiri::XML( rpc_str ).root
|
115
|
-
|
115
|
+
|
116
116
|
if block_given?
|
117
117
|
Nokogiri::XML::Builder.with(rpc.at( toplevel )){ |xml|
|
118
118
|
yield( xml )
|
@@ -120,14 +120,14 @@ EO_RPC
|
|
120
120
|
elsif config
|
121
121
|
rpc.at( toplevel ) << config.dup
|
122
122
|
else
|
123
|
-
raise ArgumentError, "You must specify edit-config data!"
|
124
|
-
end
|
125
|
-
|
126
|
-
Netconf::RPC.set_exception( rpc, Netconf::EditError )
|
127
|
-
@trans.rpc_exec( rpc )
|
128
|
-
end
|
129
|
-
|
123
|
+
raise ArgumentError, "You must specify edit-config data!"
|
124
|
+
end
|
125
|
+
|
126
|
+
Netconf::RPC.set_exception( rpc, Netconf::EditError )
|
127
|
+
@trans.rpc_exec( rpc )
|
128
|
+
end
|
129
|
+
|
130
130
|
end
|
131
131
|
|
132
|
-
end # module: RPC
|
132
|
+
end # module: RPC
|
133
133
|
end # module: Netconf
|
@@ -12,145 +12,146 @@
|
|
12
12
|
|
13
13
|
module Netconf
|
14
14
|
class Transport
|
15
|
-
|
15
|
+
|
16
16
|
attr_reader :rpc, :state, :session_id, :capabilities
|
17
17
|
attr_writer :timeout, :waitio
|
18
|
-
|
19
|
-
def initialize( &block )
|
20
|
-
|
18
|
+
|
19
|
+
def initialize( &block )
|
20
|
+
|
21
21
|
@state = :NETCONF_CLOSED
|
22
22
|
@os_type = @args[:os_type] || Netconf::DEFAULT_OS_TYPE
|
23
|
-
|
23
|
+
|
24
24
|
@rpc = Netconf::RPC::Executor.new( self, @os_type )
|
25
25
|
@rpc_message_id = 1
|
26
|
-
|
26
|
+
|
27
27
|
if block_given?
|
28
28
|
open( &block = nil ) # do not pass this block to open()
|
29
29
|
yield self
|
30
30
|
close()
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end # initialize
|
34
|
-
|
34
|
+
|
35
35
|
def open?
|
36
36
|
@state == :NETCONF_OPEN
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def closed?
|
40
40
|
@state == :NECONF_CLOSED
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def open( &block ) # :yield: specialized transport open, generally not used
|
44
|
-
|
44
|
+
|
45
45
|
raise Netconf::StateError if @state == :NETCONF_OPEN
|
46
|
-
|
46
|
+
|
47
47
|
# block is used to deal with special open processing ...
|
48
48
|
# this is *NOT* the block passed to initialize()
|
49
|
-
raise Netconf::OpenError unless trans_open( &block )
|
50
|
-
|
49
|
+
raise Netconf::OpenError unless trans_open( &block )
|
50
|
+
|
51
51
|
# read the <hello> from the server and parse out
|
52
52
|
# the capabilities and session-id
|
53
|
-
|
53
|
+
|
54
54
|
hello_rsp = Nokogiri::XML( trans_receive_hello() )
|
55
55
|
hello_rsp.remove_namespaces!
|
56
|
-
|
56
|
+
|
57
57
|
@capabilities = hello_rsp.xpath('//capability').map{ |c| c.text }
|
58
58
|
@session_id = hello_rsp.xpath('//session-id').text
|
59
|
-
|
60
|
-
# send the <hello>
|
59
|
+
|
60
|
+
# send the <hello>
|
61
61
|
trans_send_hello()
|
62
|
-
|
63
|
-
@state = :NETCONF_OPEN
|
64
|
-
self
|
62
|
+
|
63
|
+
@state = :NETCONF_OPEN
|
64
|
+
self
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def trans_receive_hello
|
68
68
|
trans_receive()
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def trans_send_hello
|
72
72
|
trans_send( Netconf::RPC::MSG_HELLO )
|
73
|
+
trans_send( RPC::MSG_END )
|
73
74
|
end
|
74
|
-
|
75
|
+
|
75
76
|
def has_capability?( capability )
|
76
77
|
@capabilities.select{|c| c.include? capability }.pop
|
77
78
|
# note: the caller could also simply use #grep on @capabilities
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
def close
|
81
|
-
raise Netconf::StateError unless @state == :NETCONF_OPEN
|
82
|
+
raise Netconf::StateError unless @state == :NETCONF_OPEN
|
82
83
|
trans_close()
|
83
|
-
@state = :NETCONF_CLOSED
|
84
|
+
@state = :NETCONF_CLOSED
|
84
85
|
self
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
# string in; string out
|
88
89
|
def send_and_receive( cmd_str )
|
89
90
|
trans_send( cmd_str )
|
90
91
|
trans_send( RPC::MSG_END )
|
91
92
|
trans_receive()
|
92
93
|
end
|
93
|
-
|
94
|
+
|
94
95
|
def rpc_exec( cmd_nx )
|
95
|
-
raise Netconf::StateError unless @state == :NETCONF_OPEN
|
96
|
-
|
96
|
+
raise Netconf::StateError unless @state == :NETCONF_OPEN
|
97
|
+
|
97
98
|
# add the mandatory message-id and namespace to the RPC
|
98
|
-
|
99
|
+
|
99
100
|
rpc_nx = cmd_nx.parent.root
|
100
101
|
rpc_nx.default_namespace = Netconf::NAMESPACE
|
101
102
|
rpc_nx['message-id'] = @rpc_message_id.to_s
|
102
103
|
@rpc_message_id += 1
|
103
|
-
|
104
|
-
# send the XML command through the transport and
|
104
|
+
|
105
|
+
# send the XML command through the transport and
|
105
106
|
# receive the response; then covert it to a Nokogiri XML
|
106
107
|
# object so we can process it.
|
107
|
-
|
108
|
+
|
108
109
|
rsp_nx = Nokogiri::XML( send_and_receive( cmd_nx.to_xml ))
|
109
|
-
|
110
|
+
|
110
111
|
# the following removes only the default namespace (xmlns)
|
111
112
|
# definitions from the document. This is an alternative
|
112
113
|
# to using #remove_namespaces! which would remove everything
|
113
|
-
# including vendor specific namespaces. So this approach is a
|
114
|
-
# nice "compromise" ... just don't know what it does
|
114
|
+
# including vendor specific namespaces. So this approach is a
|
115
|
+
# nice "compromise" ... just don't know what it does
|
115
116
|
# performance-wise on large datasets.
|
116
117
|
|
117
118
|
rsp_nx.traverse{ |n| n.namespace = nil }
|
118
|
-
|
119
|
+
|
119
120
|
# set the response context to the root node; <rpc-reply>
|
120
|
-
|
121
|
+
|
121
122
|
rsp_nx = rsp_nx.root
|
122
|
-
|
123
|
+
|
123
124
|
# check for rpc-error elements. these could be
|
124
125
|
# located anywhere in the structured response
|
125
|
-
|
126
|
+
|
126
127
|
rpc_errs = rsp_nx.xpath('//self::rpc-error')
|
127
128
|
if rpc_errs.count > 0
|
128
|
-
|
129
|
+
|
129
130
|
# look for rpc-errors that have a severity == 'error'
|
130
131
|
# in some cases the rpc-error is generated with
|
131
132
|
# severity == 'warning'
|
132
|
-
|
133
|
+
|
133
134
|
sev_err = rpc_errs.xpath('error-severity[. = "error"]')
|
134
|
-
|
135
|
+
|
135
136
|
# if there are rpc-error with severity == 'error'
|
136
137
|
# or if the caller wants to raise if severity == 'warning'
|
137
138
|
# then generate the exception
|
138
|
-
|
139
|
+
|
139
140
|
if(( sev_err.count > 0 ) || Netconf::raise_on_warning )
|
140
|
-
exception = Netconf::RPC.get_exception( cmd_nx )
|
141
|
+
exception = Netconf::RPC.get_exception( cmd_nx )
|
141
142
|
raise exception.new( self, cmd_nx, rsp_nx )
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
145
146
|
# return the XML with context at toplevel element; i.e.
|
146
147
|
# after the <rpc-reply> element
|
147
148
|
# @@@/JLS: might this be <ok> ? isn't for Junos, but need to check
|
148
149
|
# @@@/JLS: the generic case.
|
149
|
-
|
150
|
+
|
150
151
|
rsp_nx.first_element_child
|
151
|
-
|
152
|
+
|
152
153
|
end
|
153
|
-
|
154
154
|
|
155
|
-
|
155
|
+
|
156
|
+
end #--class: Transport
|
156
157
|
end #--module: Netconf
|
data/lib/net/netconf/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-netconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Kirsche
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.2'
|
55
|
-
description: Ruby NetConf client
|
55
|
+
description: Updated and maintained fork of the Juniper Ruby NetConf client
|
56
56
|
email: kev.kirsche@gmail.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
@@ -112,5 +112,5 @@ rubyforge_project:
|
|
112
112
|
rubygems_version: 2.4.6
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
|
-
summary: NetConf client
|
115
|
+
summary: Updated NetConf client
|
116
116
|
test_files: []
|