hrr_rb_netconf 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/demo/server.rb +2 -3
- data/demo/server_over_ssh.rb +4 -6
- data/demo/server_with_session-oriented-database.rb +4 -6
- data/demo/server_with_sessionless-database.rb +2 -4
- data/lib/hrr_rb_netconf/loggable.rb +42 -0
- data/lib/hrr_rb_netconf/server/capabilities.rb +8 -4
- data/lib/hrr_rb_netconf/server/capability/base_1_0.rb +97 -91
- data/lib/hrr_rb_netconf/server/capability/base_1_1.rb +109 -103
- data/lib/hrr_rb_netconf/server/capability/candidate_1_0.rb +19 -17
- data/lib/hrr_rb_netconf/server/capability/confirmed_commit_1_0.rb +4 -2
- data/lib/hrr_rb_netconf/server/capability/confirmed_commit_1_1.rb +10 -8
- data/lib/hrr_rb_netconf/server/capability/notification_1_0.rb +62 -62
- data/lib/hrr_rb_netconf/server/capability/rollback_on_error_1_0.rb +3 -1
- data/lib/hrr_rb_netconf/server/capability/startup_1_0.rb +9 -7
- data/lib/hrr_rb_netconf/server/capability/url_1_0.rb +7 -5
- data/lib/hrr_rb_netconf/server/capability/validate_1_0.rb +10 -8
- data/lib/hrr_rb_netconf/server/capability/validate_1_1.rb +11 -9
- data/lib/hrr_rb_netconf/server/capability/writable_running_1_0.rb +4 -2
- data/lib/hrr_rb_netconf/server/capability.rb +16 -27
- data/lib/hrr_rb_netconf/server/datastore/oper_handler.rb +9 -7
- data/lib/hrr_rb_netconf/server/datastore/session.rb +7 -5
- data/lib/hrr_rb_netconf/server/datastore.rb +7 -5
- data/lib/hrr_rb_netconf/server/error/rpc_errorable.rb +8 -5
- data/lib/hrr_rb_netconf/server/model.rb +9 -5
- data/lib/hrr_rb_netconf/server/notification_event.rb +0 -1
- data/lib/hrr_rb_netconf/server/notification_streams.rb +0 -1
- data/lib/hrr_rb_netconf/server/operation.rb +12 -10
- data/lib/hrr_rb_netconf/server/session.rb +39 -37
- data/lib/hrr_rb_netconf/server.rb +24 -22
- data/lib/hrr_rb_netconf/version.rb +1 -1
- data/lib/hrr_rb_netconf.rb +0 -1
- metadata +3 -3
- data/lib/hrr_rb_netconf/logger.rb +0 -56
@@ -9,15 +9,17 @@ module HrrRbNetconf
|
|
9
9
|
DEPENDENCIES = []
|
10
10
|
IF_FEATURES = ['validate']
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def define_capability
|
13
|
+
oper_proc('validate'){ |session, datastore, input_e|
|
14
|
+
datastore.run 'validate', input_e
|
15
|
+
'<ok />'
|
16
|
+
}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
model 'validate', ['source'], 'container'
|
19
|
+
model 'validate', ['source', 'config-source'], 'choice', 'mandatory' => true
|
20
|
+
model 'validate', ['source', 'config-source', 'running'], 'leaf', 'type' => 'empty'
|
21
|
+
model 'validate', ['source', 'config-source', 'config'], 'leaf', 'type' => 'anyxml'
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -9,16 +9,18 @@ module HrrRbNetconf
|
|
9
9
|
DEPENDENCIES = []
|
10
10
|
IF_FEATURES = ['validate']
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def define_capability
|
13
|
+
oper_proc('validate'){ |session, datastore, input_e|
|
14
|
+
datastore.run 'validate', input_e
|
15
|
+
'<ok />'
|
16
|
+
}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
model 'edit-config', ['test-option'], 'leaf', 'type' => 'enumeration', 'enum' => ['test-then-set', 'set', 'test-only'], 'default' => 'test-then-set'
|
19
|
+
model 'validate', ['source'], 'container'
|
20
|
+
model 'validate', ['source', 'config-source'], 'choice', 'mandatory' => true
|
21
|
+
model 'validate', ['source', 'config-source', 'running'], 'leaf', 'type' => 'empty'
|
22
|
+
model 'validate', ['source', 'config-source', 'config'], 'leaf', 'type' => 'anyxml'
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -9,8 +9,10 @@ module HrrRbNetconf
|
|
9
9
|
DEPENDENCIES = []
|
10
10
|
IF_FEATURES = ['writable-running']
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
def define_capability
|
13
|
+
model 'edit-config', ['target', 'config-target', 'running'], 'leaf', 'type' => 'empty'
|
14
|
+
model 'copy-config', ['target', 'config-target', 'running'], 'leaf', 'type' => 'empty'
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -2,10 +2,13 @@
|
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
4
|
require 'uri'
|
5
|
+
require 'hrr_rb_netconf/loggable'
|
5
6
|
|
6
7
|
module HrrRbNetconf
|
7
8
|
class Server
|
8
9
|
class Capability
|
10
|
+
include Loggable
|
11
|
+
|
9
12
|
@subclass_list = Array.new
|
10
13
|
|
11
14
|
class << self
|
@@ -29,49 +32,32 @@ module HrrRbNetconf
|
|
29
32
|
private :__subclass_list__
|
30
33
|
end
|
31
34
|
|
32
|
-
class << self
|
33
|
-
def oper_procs
|
34
|
-
@oper_procs || {}
|
35
|
-
end
|
36
|
-
|
37
|
-
def oper_proc oper_name, &blk
|
38
|
-
@oper_procs ||= Hash.new
|
39
|
-
@oper_procs[oper_name] = blk
|
40
|
-
end
|
41
|
-
|
42
|
-
def models
|
43
|
-
@models || []
|
44
|
-
end
|
45
|
-
|
46
|
-
def model oper_name, path, stmt=nil, attrs={}
|
47
|
-
@models ||= Array.new
|
48
|
-
@models.push [oper_name, path, stmt, attrs]
|
49
|
-
end
|
50
|
-
|
51
|
-
private :oper_proc, :model
|
52
|
-
end
|
53
|
-
|
54
35
|
attr_accessor :if_features, :dependencies, :queries
|
55
36
|
|
56
|
-
def initialize id=nil
|
37
|
+
def initialize id=nil, logger: nil
|
38
|
+
self.logger = logger
|
57
39
|
@id = id || self.class::ID
|
58
40
|
@queries = (self.class::QUERIES rescue {})
|
59
41
|
@if_features = (self.class::IF_FEATURES rescue [])
|
60
42
|
@dependencies = (self.class::DEPENDENCIES rescue [])
|
61
|
-
@oper_procs = self.class.oper_procs.dup
|
62
|
-
@models = (self.class.models rescue [])
|
63
43
|
@uri_proc = Proc.new { |id| id.split('?').first }
|
64
44
|
@keyword_proc = Proc.new { |id| id.split('?').first.match(/^((?:.+(?:\/|:))+.+)(?:\/|:)(.+)$/)[1] }
|
65
45
|
@version_proc = Proc.new { |id| id.split('?').first.match(/^((?:.+(?:\/|:))+.+)(?:\/|:)(.+)$/)[2] }
|
66
46
|
@decode_queries_proc = Proc.new { |qs_s| URI.decode_www_form(qs_s).inject({}){|a,(k,v)| a.merge({k=>(v.split(','))})} }
|
67
47
|
@encode_queries_proc = Proc.new { |qs_h| URI.encode_www_form(qs_h.map{|k,v| [k, v.join(',')]}) }
|
48
|
+
define_capability
|
49
|
+
end
|
50
|
+
|
51
|
+
def define_capability
|
52
|
+
# to be overridden
|
68
53
|
end
|
69
54
|
|
70
55
|
def oper_procs
|
71
|
-
@oper_procs
|
56
|
+
@oper_procs || {}
|
72
57
|
end
|
73
58
|
|
74
59
|
def oper_proc oper_name, &blk
|
60
|
+
@oper_procs ||= Hash.new
|
75
61
|
if blk
|
76
62
|
@oper_procs[oper_name] = blk
|
77
63
|
end
|
@@ -79,10 +65,11 @@ module HrrRbNetconf
|
|
79
65
|
end
|
80
66
|
|
81
67
|
def models
|
82
|
-
@models
|
68
|
+
@models || []
|
83
69
|
end
|
84
70
|
|
85
71
|
def model oper_name, path, stmt=nil, attrs={}
|
72
|
+
@models ||= Array.new
|
86
73
|
@models.push [oper_name, path, stmt, attrs]
|
87
74
|
end
|
88
75
|
|
@@ -188,6 +175,8 @@ module HrrRbNetconf
|
|
188
175
|
version <=> other.version
|
189
176
|
end
|
190
177
|
end
|
178
|
+
|
179
|
+
private :oper_proc, :model
|
191
180
|
end
|
192
181
|
end
|
193
182
|
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_netconf/
|
4
|
+
require 'hrr_rb_netconf/loggable'
|
5
5
|
|
6
6
|
module HrrRbNetconf
|
7
7
|
class Server
|
8
8
|
class Datastore
|
9
9
|
class OperHandler
|
10
|
-
|
11
|
-
|
10
|
+
include Loggable
|
11
|
+
|
12
|
+
def initialize logger: nil
|
13
|
+
self.logger = logger
|
12
14
|
end
|
13
15
|
|
14
16
|
def start *args
|
15
|
-
|
16
|
-
|
17
|
+
log_info { "Starting OperHandler" }
|
18
|
+
log_debug { "args: #{args.inspect}" }
|
17
19
|
@args = args
|
18
20
|
Fiber.yield
|
19
|
-
|
21
|
+
log_info { "Exiting OperHandler" }
|
20
22
|
end
|
21
23
|
|
22
24
|
def run oper, input
|
23
|
-
|
25
|
+
log_debug { "run with oper, input: #{oper.inspect}, #{input.inspect}" }
|
24
26
|
oper.call(*(@args + [input]))
|
25
27
|
end
|
26
28
|
end
|
@@ -1,22 +1,24 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_netconf/
|
4
|
+
require 'hrr_rb_netconf/loggable'
|
5
5
|
require 'hrr_rb_netconf/server/datastore/oper_handler'
|
6
6
|
|
7
7
|
module HrrRbNetconf
|
8
8
|
class Server
|
9
9
|
class Datastore
|
10
10
|
class Session
|
11
|
-
|
12
|
-
|
11
|
+
include Loggable
|
12
|
+
|
13
|
+
def initialize database, oper_procs, session_proc, session, logger: nil
|
14
|
+
self.logger = logger
|
13
15
|
@database = database
|
14
16
|
@oper_procs = oper_procs
|
15
17
|
@session_proc = session_proc
|
16
18
|
@session = session
|
17
19
|
|
18
20
|
if @session_proc
|
19
|
-
@oper_handler = OperHandler.new
|
21
|
+
@oper_handler = OperHandler.new logger: logger
|
20
22
|
@oper_thread = Fiber.new do |session|
|
21
23
|
@session_proc.call @database, session, @oper_handler
|
22
24
|
end
|
@@ -38,7 +40,7 @@ module HrrRbNetconf
|
|
38
40
|
|
39
41
|
def run oper_name, input
|
40
42
|
unless @oper_procs.has_key? oper_name
|
41
|
-
raise Error['operation-not-supported'].new('protocol', 'error')
|
43
|
+
raise Error['operation-not-supported'].new('protocol', 'error', logger: logger)
|
42
44
|
end
|
43
45
|
if @oper_thread
|
44
46
|
@oper_handler.run @oper_procs[oper_name], input
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_netconf/
|
4
|
+
require 'hrr_rb_netconf/loggable'
|
5
5
|
require 'hrr_rb_netconf/server/datastore/session'
|
6
6
|
|
7
7
|
module HrrRbNetconf
|
8
8
|
class Server
|
9
9
|
class Datastore
|
10
|
-
|
11
|
-
|
10
|
+
include Loggable
|
11
|
+
|
12
|
+
def initialize database, logger: nil, &blk
|
13
|
+
self.logger = logger
|
12
14
|
@database = database
|
13
15
|
@oper_procs = Hash.new
|
14
16
|
@session_proc = blk
|
@@ -17,13 +19,13 @@ module HrrRbNetconf
|
|
17
19
|
def oper_proc oper_name, &oper_proc
|
18
20
|
if oper_proc
|
19
21
|
@oper_procs[oper_name] = oper_proc
|
20
|
-
|
22
|
+
log_info { "Operation registered: #{oper_name}" }
|
21
23
|
end
|
22
24
|
@oper_procs[oper_name]
|
23
25
|
end
|
24
26
|
|
25
27
|
def new_session session
|
26
|
-
Session.new @database, @oper_procs, @session_proc, session
|
28
|
+
Session.new @database, @oper_procs, @session_proc, session, logger: logger
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -2,13 +2,16 @@
|
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
4
|
require 'rexml/document'
|
5
|
+
require 'hrr_rb_netconf/loggable'
|
5
6
|
|
6
7
|
module HrrRbNetconf
|
7
8
|
class Server
|
8
|
-
class Error
|
9
|
+
class Error
|
9
10
|
module RpcErrorable
|
10
|
-
|
11
|
-
|
11
|
+
include Loggable
|
12
|
+
|
13
|
+
def initialize type, severity, info: nil, app_tag: nil, path: nil, message: nil, logger: nil
|
14
|
+
self.logger = logger
|
12
15
|
|
13
16
|
@tag = self.class::TAG
|
14
17
|
@type = type
|
@@ -76,10 +79,10 @@ module HrrRbNetconf
|
|
76
79
|
raise ArgumentError.new "error-message arg must contain \"value\" key if Hash"
|
77
80
|
end
|
78
81
|
unless @message.fetch('attributes', {}).keys.include?('xml:lang')
|
79
|
-
|
82
|
+
log_warn { "error-message arg does not contain \"xml:lang\" attribute, so assuming \"en\"" }
|
80
83
|
end
|
81
84
|
else
|
82
|
-
|
85
|
+
log_warn { "error-message arg does not contain \"xml:lang\" attribute, so assuming \"en\"" }
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
@@ -2,13 +2,17 @@
|
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
4
|
require 'rexml/document'
|
5
|
+
require 'hrr_rb_netconf/loggable'
|
5
6
|
require 'hrr_rb_netconf/server/error'
|
6
7
|
require 'hrr_rb_netconf/server/model/node'
|
7
8
|
|
8
9
|
module HrrRbNetconf
|
9
10
|
class Server
|
10
11
|
class Model
|
11
|
-
|
12
|
+
include Loggable
|
13
|
+
|
14
|
+
def initialize operation, logger: nil
|
15
|
+
self.logger = logger
|
12
16
|
@operation = operation
|
13
17
|
@tree = Node.new nil, operation, 'root', {}
|
14
18
|
end
|
@@ -48,7 +52,7 @@ module HrrRbNetconf
|
|
48
52
|
if c.options['validation'].nil?
|
49
53
|
true
|
50
54
|
else
|
51
|
-
raise Error['operation-failed'].new('application', 'error', message: 'Not implemented')
|
55
|
+
raise Error['operation-failed'].new('application', 'error', message: 'Not implemented', logger: logger)
|
52
56
|
end
|
53
57
|
else
|
54
58
|
validate_recursively c, xml_e.elements[c.name], parent_xml_e: xml_e
|
@@ -56,7 +60,7 @@ module HrrRbNetconf
|
|
56
60
|
when 'choice'
|
57
61
|
validate_recursively c, xml_e, validated: validated
|
58
62
|
else
|
59
|
-
raise Error['unknown-element'].new('application', 'error', info: {'bad-element' => "#{c.name}: #{c.stmt}"}, message: 'Not implemented')
|
63
|
+
raise Error['unknown-element'].new('application', 'error', info: {'bad-element' => "#{c.name}: #{c.stmt}"}, message: 'Not implemented', logger: logger)
|
60
64
|
end
|
61
65
|
}
|
62
66
|
end && (xml_e.elements.to_a.map{|e| e.name} - validated).empty?
|
@@ -74,7 +78,7 @@ module HrrRbNetconf
|
|
74
78
|
xml_e != nil && (REXML::Document.new(xml_e.text) rescue false)
|
75
79
|
when 'inet:uri'
|
76
80
|
xml_e != nil
|
77
|
-
raise Error['unknown-element'].new('application', 'error', info: {'bad-element' => "#{node.name}: #{node.stmt}"}, message: 'Not implemented: type inet:uri')
|
81
|
+
raise Error['unknown-element'].new('application', 'error', info: {'bad-element' => "#{node.name}: #{node.stmt}"}, message: 'Not implemented: type inet:uri', logger: logger)
|
78
82
|
when 'integer'
|
79
83
|
if xml_e == nil && node.options['default']
|
80
84
|
parent_xml_e.add_element(node.name).text = node.options['default']
|
@@ -111,7 +115,7 @@ module HrrRbNetconf
|
|
111
115
|
}
|
112
116
|
end
|
113
117
|
else
|
114
|
-
raise Error['unknown-element'].new('application', 'error', info: {'bad-element' => "#{c.name}: #{c.stmt}"}, message: 'Not implemented')
|
118
|
+
raise Error['unknown-element'].new('application', 'error', info: {'bad-element' => "#{c.name}: #{c.stmt}"}, message: 'Not implemented', logger: logger)
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# vim: et ts=2 sw=2
|
3
3
|
|
4
|
-
require 'hrr_rb_netconf/
|
4
|
+
require 'hrr_rb_netconf/loggable'
|
5
5
|
require 'hrr_rb_netconf/server/model'
|
6
6
|
require 'hrr_rb_netconf/server/filter'
|
7
7
|
|
8
8
|
module HrrRbNetconf
|
9
9
|
class Server
|
10
10
|
class Operation
|
11
|
-
|
12
|
-
|
11
|
+
include Loggable
|
12
|
+
|
13
|
+
def initialize session, capabilities, datastore_session, strict_capabilities, logger: nil
|
14
|
+
self.logger = logger
|
13
15
|
@session = session
|
14
16
|
@capabilities = capabilities
|
15
17
|
@datastore_session = datastore_session
|
@@ -22,14 +24,14 @@ module HrrRbNetconf
|
|
22
24
|
|
23
25
|
def load_capabilities
|
24
26
|
@capabilities.each_loadable{ |c|
|
25
|
-
|
27
|
+
log_debug { "Load capability: #{c.id}" }
|
26
28
|
c.oper_procs.each{ |k, v|
|
27
29
|
@oper_procs[k] = v
|
28
30
|
}
|
29
31
|
if @strict_capabilities
|
30
32
|
c.models.each{ |m|
|
31
33
|
oper_name, path, stmt, options = m
|
32
|
-
@models[oper_name] ||= Model.new oper_name
|
34
|
+
@models[oper_name] ||= Model.new oper_name, logger: logger
|
33
35
|
@models[oper_name].add c, path, stmt, options
|
34
36
|
}
|
35
37
|
end
|
@@ -48,24 +50,24 @@ module HrrRbNetconf
|
|
48
50
|
|
49
51
|
def run xml_doc
|
50
52
|
unless xml_doc.root.name == 'rpc'
|
51
|
-
|
52
|
-
raise Error['operation-not-supported'].new('protocol', 'error')
|
53
|
+
log_error { "Invalid root tag: must be rpc, but got #{xml_doc.root.name}" }
|
54
|
+
raise Error['operation-not-supported'].new('protocol', 'error', logger: logger)
|
53
55
|
end
|
54
56
|
|
55
57
|
message_id = xml_doc.attributes['message-id']
|
56
58
|
unless message_id
|
57
|
-
raise Error['missing-attribute'].new('rpc', 'error', info: {'bad-attribute' => 'message-id', 'bad-element' => 'rpc'})
|
59
|
+
raise Error['missing-attribute'].new('rpc', 'error', info: {'bad-attribute' => 'message-id', 'bad-element' => 'rpc'}, logger: logger)
|
58
60
|
end
|
59
61
|
|
60
62
|
input_e = xml_doc.elements[1]
|
61
63
|
|
62
64
|
unless @oper_procs.has_key? input_e.name
|
63
|
-
raise Error['operation-not-supported'].new('protocol', 'error')
|
65
|
+
raise Error['operation-not-supported'].new('protocol', 'error', logger: logger)
|
64
66
|
end
|
65
67
|
|
66
68
|
if @strict_capabilities
|
67
69
|
unless validate input_e
|
68
|
-
raise Error['operation-not-supported'].new('application', 'error')
|
70
|
+
raise Error['operation-not-supported'].new('application', 'error', logger: logger)
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|