rubyang 0.1.2.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -3
- data/lib/rubyang.rb +5 -6
- data/lib/rubyang/cli.rb +114 -114
- data/lib/rubyang/cli/parser.rb +56 -56
- data/lib/rubyang/compat.rb +14 -0
- data/lib/rubyang/component/base.rb +21 -21
- data/lib/rubyang/component/example.rb +8 -7
- data/lib/rubyang/database.rb +45 -34
- data/lib/rubyang/database/component_manager.rb +64 -64
- data/lib/rubyang/database/data_tree.rb +1110 -1077
- data/lib/rubyang/database/helper.rb +31 -30
- data/lib/rubyang/database/logger.rb +58 -0
- data/lib/rubyang/database/schema_tree.rb +1198 -1298
- data/lib/rubyang/model.rb +1139 -923
- data/lib/rubyang/model/logger.rb +58 -0
- data/lib/rubyang/model/parser.rb +197 -195
- data/lib/rubyang/model/parser/parser.tab.rb +1373 -1263
- data/lib/rubyang/model/parser/parser.y +393 -215
- data/lib/rubyang/restapi.rb +4 -3
- data/lib/rubyang/restapi/app.rb +52 -53
- data/lib/rubyang/server.rb +4 -3
- data/lib/rubyang/server/base.rb +20 -20
- data/lib/rubyang/server/example.rb +2 -1
- data/lib/rubyang/version.rb +4 -1
- data/lib/rubyang/webui.rb +4 -3
- data/lib/rubyang/webui/app.rb +62 -63
- data/lib/rubyang/webui/make_json_schema.rb +49 -48
- data/lib/rubyang/xpath.rb +458 -456
- data/lib/rubyang/xpath/logger.rb +58 -0
- data/lib/rubyang/xpath/parser.rb +134 -144
- data/lib/rubyang/xpath/parser/parser.tab.rb +373 -616
- data/lib/rubyang/xpath/parser/parser.y +249 -492
- data/rubyang.gemspec +11 -15
- metadata +49 -32
- data/lib/rubyang/logger.rb +0 -19
data/lib/rubyang/restapi.rb
CHANGED
data/lib/rubyang/restapi/app.rb
CHANGED
@@ -1,72 +1,71 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
require 'bundler/setup'
|
4
|
-
|
5
5
|
require 'sinatra/base'
|
6
6
|
require 'sinatra/reloader'
|
7
7
|
require 'sinatra/respond_with'
|
8
|
-
|
9
|
-
require_relative '../../rubyang'
|
8
|
+
require 'rubyang'
|
10
9
|
|
11
10
|
module Rubyang
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
module RestAPI
|
12
|
+
class App < Sinatra::Base
|
13
|
+
set :environment, :development
|
14
|
+
set :bind, '0.0.0.0'
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
configure :development do
|
17
|
+
register Sinatra::Reloader
|
18
|
+
end
|
20
19
|
|
21
|
-
|
20
|
+
register Sinatra::RespondWith
|
22
21
|
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
|
24
|
+
model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
|
25
|
+
db = Rubyang::Database.new
|
26
|
+
db.load_model model
|
27
|
+
db.configure.edit('container1').edit('container2').edit('leaf1').set('value')
|
29
28
|
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
get '/' do
|
31
|
+
respond_to do |f|
|
32
|
+
f.on( 'application/xml' ){
|
33
|
+
config = db.configure
|
34
|
+
config.to_xml( pretty: true )
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
get %r{/api(?:/(.+)[/]?)} do
|
40
|
+
respond_to do |f|
|
41
|
+
f.on( 'application/xml' ){
|
42
|
+
#{ params: ' '+params[:captures][0] }.to_json
|
43
|
+
config = db.configure
|
44
|
+
paths = params[:captures][0].split( '/' )
|
45
|
+
element = paths.inject( config ){ |parent, child| parent.edit( child ) }
|
46
|
+
element.to_xml( pretty: true )
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
post %r{/api(?:/(.+)[/]?)} do
|
52
|
+
body = request.body.read
|
53
|
+
respond_to do |f|
|
54
|
+
f.on( 'application/xml' ){
|
55
|
+
config = db.configure
|
56
|
+
paths = params[:captures][0].split( '/' )
|
57
|
+
element = paths.inject( config ){ |parent, child| parent.edit( child ) }
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
get %r{/api[/]?} do
|
63
|
+
respond_to do |f|
|
64
|
+
f.on( 'application/xml' ){ db.configure.to_xml( pretty: true ) }
|
65
|
+
end
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
run! if app_file == $0
|
69
|
+
end
|
70
|
+
end
|
72
71
|
end
|
data/lib/rubyang/server.rb
CHANGED
data/lib/rubyang/server/base.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
require_relative '../../rubyang'
|
2
|
+
# vim: et ts=2 sw=2
|
4
3
|
|
5
4
|
require 'fileutils'
|
6
5
|
require 'drb/drb'
|
6
|
+
require 'rubyang'
|
7
7
|
|
8
8
|
module Rubyang
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
module Server
|
10
|
+
class Base
|
11
|
+
def initialize
|
12
|
+
@pid = Process.pid
|
13
|
+
@sock_dir = "/tmp/rubyang/server"
|
14
|
+
#@sock_file = "#{@sock_dir}/#{self.class.to_s}.#{@pid}.sock"
|
15
|
+
@sock_file = "#{@sock_dir}/#{self.class.to_s}.sock"
|
16
16
|
|
17
|
-
|
17
|
+
FileUtils.mkdir_p @sock_dir
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
@db = Rubyang::Database.new
|
20
|
+
@db.load_model Rubyang::Model::Parser.parse File.open( "#{File.dirname(__FILE__)}/../yang/rubyang.yang", 'r' ).read
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
def run
|
24
|
+
#DRb.start_service( "drbunix:#{@sock_file}", @db, safe_level: 1 )
|
25
|
+
DRb.start_service( "drbunix:#{@sock_file}", @db )
|
26
|
+
DRb.thread.join
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
30
|
end
|
data/lib/rubyang/version.rb
CHANGED
data/lib/rubyang/webui.rb
CHANGED
data/lib/rubyang/webui/app.rb
CHANGED
@@ -1,74 +1,73 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
require 'bundler/setup'
|
4
|
-
|
5
5
|
require 'sinatra/base'
|
6
6
|
require 'sinatra/reloader'
|
7
7
|
require 'sinatra/content_for'
|
8
|
-
|
9
|
-
|
10
|
-
require_relative 'make_json_schema'
|
8
|
+
require 'rubyang'
|
9
|
+
require 'rubyang/webui/make_json_schema'
|
11
10
|
|
12
11
|
module Rubyang
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
12
|
+
module WebUI
|
13
|
+
class App < Sinatra::Base
|
14
|
+
set :environment, :development
|
15
|
+
set :bind, '0.0.0.0'
|
16
|
+
|
17
|
+
helpers Sinatra::ContentFor
|
18
|
+
|
19
|
+
configure :development do
|
20
|
+
register Sinatra::Reloader
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
|
25
|
+
model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
|
26
|
+
db = Rubyang::Database.new
|
27
|
+
db.load_model model
|
28
|
+
|
29
|
+
|
30
|
+
get '/' do
|
31
|
+
locals = Hash.new
|
32
|
+
erb :index, locals: locals
|
33
|
+
end
|
34
|
+
|
35
|
+
get '/api/reload_model' do
|
36
|
+
target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
|
37
|
+
model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
|
38
|
+
db = Rubyang::Database.new
|
39
|
+
db.load_model @model
|
40
|
+
'{}'
|
41
|
+
end
|
42
|
+
|
43
|
+
get '/api/schema' do
|
44
|
+
schema_tree = db.configure.schema
|
45
|
+
data = make_json_schema( schema_tree )
|
46
|
+
puts data
|
47
|
+
sleep 0
|
48
|
+
data
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/api/data' do
|
52
|
+
config = db.configure
|
53
|
+
data = config.to_json( pretty: true )
|
54
|
+
puts data
|
55
|
+
sleep 0
|
56
|
+
data
|
57
|
+
end
|
58
|
+
|
59
|
+
post '/api/data' do
|
60
|
+
request.body.rewind
|
61
|
+
data = request.body.read
|
62
|
+
puts data
|
63
|
+
db.configure.load_override_json( data )
|
64
|
+
sleep 1
|
65
|
+
'{}'
|
66
|
+
end
|
67
|
+
|
68
|
+
run! if app_file == $0
|
69
|
+
end
|
70
|
+
end
|
72
71
|
end
|
73
72
|
|
74
73
|
|
@@ -1,63 +1,64 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
def make_json_schema schema_tree
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
json_schema_tree = Array.new
|
6
|
+
make_json_schema_recursive json_schema_tree, schema_tree
|
7
|
+
return JSON.pretty_generate(json_schema_tree)
|
7
8
|
end
|
8
9
|
|
9
10
|
def make_json_schema_recursive json_schema_tree, schema_tree
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
11
|
+
case schema_tree.model
|
12
|
+
when nil
|
13
|
+
json_schema_tree.push Hash.new
|
14
|
+
json_schema_tree.last[:root] = Hash.new
|
15
|
+
json_schema_tree.last[:root][:name] = "root"
|
16
|
+
json_schema_tree.last[:root][:description] = "root"
|
17
|
+
json_schema_tree.last[:root][:children] = Array.new
|
18
|
+
schema_tree.children.each{ |child_schema_tree|
|
19
|
+
make_json_schema_recursive json_schema_tree.last[:root][:children], child_schema_tree
|
20
|
+
}
|
21
|
+
when Rubyang::Model::Container
|
22
|
+
json_schema_tree.push Hash.new
|
23
|
+
json_schema_tree.last[:container] = Hash.new
|
24
|
+
json_schema_tree.last[:container][:name] = schema_tree.model.arg
|
25
|
+
json_schema_tree.last[:container][:description] = schema_tree.model.substmt('description').first.arg
|
26
|
+
json_schema_tree.last[:container][:children] = Array.new
|
27
|
+
schema_tree.children.each{ |child_schema_tree|
|
28
|
+
make_json_schema_recursive json_schema_tree.last[:container][:children], child_schema_tree
|
29
|
+
}
|
30
|
+
when Rubyang::Model::List
|
31
|
+
json_schema_tree.push Hash.new
|
32
|
+
json_schema_tree.last[:list] = Hash.new
|
33
|
+
json_schema_tree.last[:list][:key] = schema_tree.model.substmt('key')[0].arg
|
34
|
+
json_schema_tree.last[:list][:name] = schema_tree.model.arg
|
35
|
+
json_schema_tree.last[:list][:description] = schema_tree.model.substmt('description').first.arg
|
36
|
+
json_schema_tree.last[:list][:children] = Array.new
|
37
|
+
schema_tree.children.each{ |child_schema_tree|
|
38
|
+
make_json_schema_recursive json_schema_tree.last[:list][:children], child_schema_tree
|
39
|
+
}
|
40
|
+
when Rubyang::Model::Leaf
|
41
|
+
json_schema_tree.push Hash.new
|
42
|
+
json_schema_tree.last[:leaf] = Hash.new
|
43
|
+
json_schema_tree.last[:leaf][:name] = schema_tree.model.arg
|
44
|
+
json_schema_tree.last[:leaf][:description] = schema_tree.model.substmt('description').first.arg
|
45
|
+
json_schema_tree.last[:leaf][:type] = schema_tree.type.arg
|
46
|
+
end
|
46
47
|
end
|
47
48
|
|
48
49
|
|
49
50
|
if __FILE__ == $0
|
50
|
-
|
51
|
-
|
51
|
+
require 'yaml'
|
52
|
+
require_relative '../../rubyang'
|
52
53
|
|
53
|
-
|
54
|
+
target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
|
57
|
+
db = Rubyang::Database.new
|
58
|
+
db.load_model model
|
58
59
|
|
59
|
-
|
60
|
+
schema_tree = db.configure.schema
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
json = make_json_schema schema_tree
|
63
|
+
puts json
|
63
64
|
end
|