hrr_rb_netconf 0.1.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.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +32 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE +201 -0
  8. data/README.md +220 -0
  9. data/Rakefile +6 -0
  10. data/demo/server.rb +54 -0
  11. data/demo/server_over_ssh.rb +97 -0
  12. data/demo/server_with_session-oriented-database.rb +134 -0
  13. data/demo/server_with_sessionless-database.rb +81 -0
  14. data/hrr_rb_netconf.gemspec +28 -0
  15. data/lib/hrr_rb_netconf.rb +10 -0
  16. data/lib/hrr_rb_netconf/logger.rb +56 -0
  17. data/lib/hrr_rb_netconf/server.rb +109 -0
  18. data/lib/hrr_rb_netconf/server/capabilities.rb +75 -0
  19. data/lib/hrr_rb_netconf/server/capability.rb +206 -0
  20. data/lib/hrr_rb_netconf/server/capability/base_1_0.rb +183 -0
  21. data/lib/hrr_rb_netconf/server/capability/base_1_1.rb +247 -0
  22. data/lib/hrr_rb_netconf/server/capability/candidate_1_0.rb +34 -0
  23. data/lib/hrr_rb_netconf/server/capability/confirmed_commit_1_0.rb +24 -0
  24. data/lib/hrr_rb_netconf/server/capability/confirmed_commit_1_1.rb +24 -0
  25. data/lib/hrr_rb_netconf/server/capability/rollback_on_error_1_0.rb +16 -0
  26. data/lib/hrr_rb_netconf/server/capability/startup_1_0.rb +22 -0
  27. data/lib/hrr_rb_netconf/server/capability/url_1_0.rb +23 -0
  28. data/lib/hrr_rb_netconf/server/capability/validate_1_0.rb +25 -0
  29. data/lib/hrr_rb_netconf/server/capability/validate_1_1.rb +25 -0
  30. data/lib/hrr_rb_netconf/server/capability/writable_running_1_0.rb +17 -0
  31. data/lib/hrr_rb_netconf/server/capability/xpath_1_0.rb +14 -0
  32. data/lib/hrr_rb_netconf/server/datastore.rb +30 -0
  33. data/lib/hrr_rb_netconf/server/datastore/oper_handler.rb +29 -0
  34. data/lib/hrr_rb_netconf/server/datastore/session.rb +52 -0
  35. data/lib/hrr_rb_netconf/server/error.rb +52 -0
  36. data/lib/hrr_rb_netconf/server/error/access_denied.rb +19 -0
  37. data/lib/hrr_rb_netconf/server/error/bad_attribute.rb +20 -0
  38. data/lib/hrr_rb_netconf/server/error/bad_element.rb +20 -0
  39. data/lib/hrr_rb_netconf/server/error/data_exists.rb +19 -0
  40. data/lib/hrr_rb_netconf/server/error/data_missing.rb +19 -0
  41. data/lib/hrr_rb_netconf/server/error/in_use.rb +19 -0
  42. data/lib/hrr_rb_netconf/server/error/invalid_value.rb +19 -0
  43. data/lib/hrr_rb_netconf/server/error/lock_denied.rb +19 -0
  44. data/lib/hrr_rb_netconf/server/error/malformed_message.rb +19 -0
  45. data/lib/hrr_rb_netconf/server/error/missing_attribute.rb +19 -0
  46. data/lib/hrr_rb_netconf/server/error/missing_element.rb +19 -0
  47. data/lib/hrr_rb_netconf/server/error/operation_failed.rb +19 -0
  48. data/lib/hrr_rb_netconf/server/error/operation_not_supported.rb +19 -0
  49. data/lib/hrr_rb_netconf/server/error/partial_operation.rb +19 -0
  50. data/lib/hrr_rb_netconf/server/error/resource_denied.rb +19 -0
  51. data/lib/hrr_rb_netconf/server/error/rollback_failed.rb +19 -0
  52. data/lib/hrr_rb_netconf/server/error/rpc_errorable.rb +138 -0
  53. data/lib/hrr_rb_netconf/server/error/too_big.rb +19 -0
  54. data/lib/hrr_rb_netconf/server/error/unknown_attribute.rb +19 -0
  55. data/lib/hrr_rb_netconf/server/error/unknown_element.rb +19 -0
  56. data/lib/hrr_rb_netconf/server/error/unknown_namespace.rb +19 -0
  57. data/lib/hrr_rb_netconf/server/errors.rb +28 -0
  58. data/lib/hrr_rb_netconf/server/filter.rb +48 -0
  59. data/lib/hrr_rb_netconf/server/filter/subtree.rb +135 -0
  60. data/lib/hrr_rb_netconf/server/filter/xpath.rb +59 -0
  61. data/lib/hrr_rb_netconf/server/model.rb +123 -0
  62. data/lib/hrr_rb_netconf/server/model/node.rb +19 -0
  63. data/lib/hrr_rb_netconf/server/operation.rb +92 -0
  64. data/lib/hrr_rb_netconf/server/session.rb +177 -0
  65. data/lib/hrr_rb_netconf/version.rb +6 -0
  66. metadata +149 -0
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbNetconf
5
+ class Server
6
+ class Capability
7
+ class WritableRunning_1_0 < Capability
8
+ ID = 'urn:ietf:params:netconf:capability:writable-running:1.0'
9
+ DEPENDENCIES = []
10
+ IF_FEATURES = ['writable-running']
11
+
12
+ model 'edit-config', ['target', 'config-target', 'running'], 'leaf', 'type' => 'empty'
13
+ model 'copy-config', ['target', 'config-target', 'running'], 'leaf', 'type' => 'empty'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbNetconf
5
+ class Server
6
+ class Capability
7
+ class Xpath_1_0 < Capability
8
+ ID = 'urn:ietf:params:netconf:capability:xpath:1.0'
9
+ DEPENDENCIES = []
10
+ IF_FEATURES = ['xpath']
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/logger'
5
+ require 'hrr_rb_netconf/server/datastore/session'
6
+
7
+ module HrrRbNetconf
8
+ class Server
9
+ class Datastore
10
+ def initialize database, &blk
11
+ @logger = Logger.new self.class.name
12
+ @database = database
13
+ @oper_procs = Hash.new
14
+ @session_proc = blk
15
+ end
16
+
17
+ def oper_proc oper_name, &oper_proc
18
+ if oper_proc
19
+ @oper_procs[oper_name] = oper_proc
20
+ @logger.info { "Operation registered: #{oper_name}" }
21
+ end
22
+ @oper_procs[oper_name]
23
+ end
24
+
25
+ def new_session session
26
+ Session.new @database, @oper_procs, @session_proc, session
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/logger'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Datastore
9
+ class OperHandler
10
+ def initialize
11
+ @logger = Logger.new self.class.name
12
+ end
13
+
14
+ def start *args
15
+ @logger.info { "Starting OperHandler" }
16
+ @logger.debug { "args: #{args.inspect}" }
17
+ @args = args
18
+ Fiber.yield
19
+ @logger.info { "Exiting OperHandler" }
20
+ end
21
+
22
+ def run oper, input
23
+ @logger.debug { "run with oper, input: #{oper.inspect}, #{input.inspect}" }
24
+ oper.call(*(@args + [input]))
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/logger'
5
+ require 'hrr_rb_netconf/server/datastore/oper_handler'
6
+
7
+ module HrrRbNetconf
8
+ class Server
9
+ class Datastore
10
+ class Session
11
+ def initialize database, oper_procs, session_proc, session
12
+ @logger = Logger.new self.class.name
13
+ @database = database
14
+ @oper_procs = oper_procs
15
+ @session_proc = session_proc
16
+ @session = session
17
+
18
+ if @session_proc
19
+ @oper_handler = OperHandler.new
20
+ @oper_thread = Fiber.new do |session|
21
+ @session_proc.call @database, session, @oper_handler
22
+ end
23
+ @oper_thread.resume(session)
24
+ end
25
+ end
26
+
27
+ def close
28
+ if @oper_thread
29
+ while true
30
+ begin
31
+ @oper_thread.resume
32
+ rescue FiberError
33
+ break
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def run oper_name, input
40
+ unless @oper_procs.has_key? oper_name
41
+ raise Error['operation-not-supported'].new('protocol', 'error')
42
+ end
43
+ if @oper_thread
44
+ @oper_handler.run @oper_procs[oper_name], input
45
+ else
46
+ @oper_procs[oper_name].call @database, input
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbNetconf
5
+ class Server
6
+ class Error < StandardError
7
+ @subclass_list = Array.new
8
+
9
+ class << self
10
+ def inherited klass
11
+ @subclass_list.push klass if @subclass_list
12
+ end
13
+
14
+ def [] key
15
+ __subclass_list__(__method__).find{ |klass| klass::TAG == key }
16
+ end
17
+
18
+ def list
19
+ __subclass_list__(__method__).map{ |klass| klass::TAG }
20
+ end
21
+
22
+ def __subclass_list__ method_name
23
+ send(:method_missing, method_name) unless @subclass_list
24
+ @subclass_list
25
+ end
26
+
27
+ private :__subclass_list__
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ require 'hrr_rb_netconf/server/error/in_use'
34
+ require 'hrr_rb_netconf/server/error/invalid_value'
35
+ require 'hrr_rb_netconf/server/error/too_big'
36
+ require 'hrr_rb_netconf/server/error/missing_attribute'
37
+ require 'hrr_rb_netconf/server/error/bad_attribute'
38
+ require 'hrr_rb_netconf/server/error/unknown_attribute'
39
+ require 'hrr_rb_netconf/server/error/missing_element'
40
+ require 'hrr_rb_netconf/server/error/bad_element'
41
+ require 'hrr_rb_netconf/server/error/unknown_element'
42
+ require 'hrr_rb_netconf/server/error/unknown_namespace'
43
+ require 'hrr_rb_netconf/server/error/access_denied'
44
+ require 'hrr_rb_netconf/server/error/lock_denied'
45
+ require 'hrr_rb_netconf/server/error/resource_denied'
46
+ require 'hrr_rb_netconf/server/error/rollback_failed'
47
+ require 'hrr_rb_netconf/server/error/data_exists'
48
+ require 'hrr_rb_netconf/server/error/data_missing'
49
+ require 'hrr_rb_netconf/server/error/operation_not_supported'
50
+ require 'hrr_rb_netconf/server/error/operation_failed'
51
+ require 'hrr_rb_netconf/server/error/partial_operation'
52
+ require 'hrr_rb_netconf/server/error/malformed_message'
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class AccessDenied < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'access-denied'
13
+ TYPE = ['protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class BadAttribute < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'bad-attribute'
13
+ TYPE = ['rpc', 'protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = ['bad-attribute', 'bad-element']
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class BadElement < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'bad-element'
13
+ TYPE = ['protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = ['bad-element']
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class DataExists < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'data-exists'
13
+ TYPE = ['application']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class DataMissing < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'data-missing'
13
+ TYPE = ['application']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class InUse < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'in-use'
13
+ TYPE = ['protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class InvalidValue < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'invalid-value'
13
+ TYPE = ['protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class LockDenied < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'lock-denied'
13
+ TYPE = ['protocol']
14
+ SEVERITY = ['error']
15
+ INFO = ['session-id']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class MalformedMessage < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'malformed-message'
13
+ TYPE = ['rpc']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class MissingAttribute < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'missing-attribute'
13
+ TYPE = ['rpc', 'protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = ['bad-attribute', 'bad-element']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class MissingElement < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'missing-element'
13
+ TYPE = ['protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = ['bad-element']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'hrr_rb_netconf/server/error/rpc_errorable'
5
+
6
+ module HrrRbNetconf
7
+ class Server
8
+ class Error
9
+ class OperationFailed < Error
10
+ include RpcErrorable
11
+
12
+ TAG = 'operation-failed'
13
+ TYPE = ['rpc', 'protocol', 'application']
14
+ SEVERITY = ['error']
15
+ INFO = []
16
+ end
17
+ end
18
+ end
19
+ end