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.
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
- require_relative 'restapi/app'
4
+ require 'rubyang/restapi/app'
4
5
 
5
6
  module Rubyang
6
- module RestAPI
7
- end
7
+ module RestAPI
8
+ end
8
9
  end
9
10
 
10
11
  Rubyang::RestAPI::App.run!
@@ -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
- module RestAPI
13
- class App < Sinatra::Base
14
- set :environment, :development
15
- set :bind, '0.0.0.0'
11
+ module RestAPI
12
+ class App < Sinatra::Base
13
+ set :environment, :development
14
+ set :bind, '0.0.0.0'
16
15
 
17
- configure :development do
18
- register Sinatra::Reloader
19
- end
16
+ configure :development do
17
+ register Sinatra::Reloader
18
+ end
20
19
 
21
- register Sinatra::RespondWith
20
+ register Sinatra::RespondWith
22
21
 
23
22
 
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
- db.configure.edit('container1').edit('container2').edit('leaf1').set('value')
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
- get '/' do
32
- respond_to do |f|
33
- f.on( 'application/xml' ){
34
- config = db.configure
35
- config.to_xml( pretty: true )
36
- }
37
- end
38
- end
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
- get %r{/api(?:/(.+)[/]?)} do
41
- respond_to do |f|
42
- f.on( 'application/xml' ){
43
- #{ params: ' '+params[:captures][0] }.to_json
44
- config = db.configure
45
- paths = params[:captures][0].split( '/' )
46
- element = paths.inject( config ){ |parent, child| parent.edit( child ) }
47
- element.to_xml( pretty: true )
48
- }
49
- end
50
- end
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
- post %r{/api(?:/(.+)[/]?)} do
53
- body = request.body.read
54
- respond_to do |f|
55
- f.on( 'application/xml' ){
56
- config = db.configure
57
- paths = params[:captures][0].split( '/' )
58
- element = paths.inject( config ){ |parent, child| parent.edit( child ) }
59
- }
60
- end
61
- end
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
- get %r{/api[/]?} do
64
- respond_to do |f|
65
- f.on( 'application/xml' ){ db.configure.to_xml( pretty: true ) }
66
- end
67
- end
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
- run! if app_file == $0
70
- end
71
- end
68
+ run! if app_file == $0
69
+ end
70
+ end
72
71
  end
@@ -1,8 +1,9 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
- require_relative '../rubyang'
4
+ require 'rubyang'
4
5
 
5
6
  module Rubyang
6
- module Server
7
- end
7
+ module Server
8
+ end
8
9
  end
@@ -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
- 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"
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
- FileUtils.mkdir_p @sock_dir
17
+ FileUtils.mkdir_p @sock_dir
18
18
 
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
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
- 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
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
@@ -1,6 +1,7 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
- require_relative 'base'
4
+ require 'rubyang/server/base'
4
5
 
5
6
  class Example < Rubyang::Server::Base
6
7
  end
@@ -1,3 +1,6 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
1
4
  module Rubyang
2
- VERSION = "0.1.2.1"
5
+ VERSION = "0.1.3"
3
6
  end
data/lib/rubyang/webui.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
- require_relative 'webui/app'
4
+ require 'rubyang/webui/app'
4
5
 
5
6
  module Rubyang
6
- module WebUI
7
- end
7
+ module WebUI
8
+ end
8
9
  end
9
10
 
10
11
  Rubyang::WebUI::App.run!
@@ -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
- require_relative '../../rubyang'
10
- require_relative 'make_json_schema'
8
+ require 'rubyang'
9
+ require 'rubyang/webui/make_json_schema'
11
10
 
12
11
  module Rubyang
13
- module WebUI
14
- class App < Sinatra::Base
15
- set :environment, :development
16
- set :bind, '0.0.0.0'
17
-
18
- helpers Sinatra::ContentFor
19
-
20
- configure :development do
21
- register Sinatra::Reloader
22
- end
23
-
24
-
25
- target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
26
- model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
27
- db = Rubyang::Database.new
28
- db.load_model model
29
-
30
-
31
- get '/' do
32
- locals = Hash.new
33
- erb :index, locals: locals
34
- end
35
-
36
- get '/api/reload_model' do
37
- target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
38
- model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
39
- db = Rubyang::Database.new
40
- db.load_model @model
41
- '{}'
42
- end
43
-
44
- get '/api/schema' do
45
- schema_tree = db.configure.schema
46
- data = make_json_schema( schema_tree )
47
- puts data
48
- sleep 0
49
- data
50
- end
51
-
52
- get '/api/data' do
53
- config = db.configure
54
- data = config.to_json( pretty: true )
55
- puts data
56
- sleep 0
57
- data
58
- end
59
-
60
- post '/api/data' do
61
- request.body.rewind
62
- data = request.body.read
63
- puts data
64
- db.configure.load_override_json( data )
65
- sleep 1
66
- '{}'
67
- end
68
-
69
- run! if app_file == $0
70
- end
71
- end
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
- json_schema_tree = Array.new
5
- make_json_schema_recursive json_schema_tree, schema_tree
6
- return JSON.pretty_generate(json_schema_tree)
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
- case schema_tree.model
11
- when nil
12
- json_schema_tree.push Hash.new
13
- json_schema_tree.last[:root] = Hash.new
14
- json_schema_tree.last[:root][:name] = "root"
15
- json_schema_tree.last[:root][:description] = "root"
16
- json_schema_tree.last[:root][:children] = Array.new
17
- schema_tree.children.each{ |child_schema_tree|
18
- make_json_schema_recursive json_schema_tree.last[:root][:children], child_schema_tree
19
- }
20
- when Rubyang::Model::Container
21
- json_schema_tree.push Hash.new
22
- json_schema_tree.last[:container] = Hash.new
23
- json_schema_tree.last[:container][:name] = schema_tree.model.arg
24
- json_schema_tree.last[:container][:description] = schema_tree.model.substmt('description').first.arg
25
- json_schema_tree.last[:container][:children] = Array.new
26
- schema_tree.children.each{ |child_schema_tree|
27
- make_json_schema_recursive json_schema_tree.last[:container][:children], child_schema_tree
28
- }
29
- when Rubyang::Model::List
30
- json_schema_tree.push Hash.new
31
- json_schema_tree.last[:list] = Hash.new
32
- json_schema_tree.last[:list][:key] = schema_tree.model.substmt('key')[0].arg
33
- json_schema_tree.last[:list][:name] = schema_tree.model.arg
34
- json_schema_tree.last[:list][:description] = schema_tree.model.substmt('description').first.arg
35
- json_schema_tree.last[:list][:children] = Array.new
36
- schema_tree.children.each{ |child_schema_tree|
37
- make_json_schema_recursive json_schema_tree.last[:list][:children], child_schema_tree
38
- }
39
- when Rubyang::Model::Leaf
40
- json_schema_tree.push Hash.new
41
- json_schema_tree.last[:leaf] = Hash.new
42
- json_schema_tree.last[:leaf][:name] = schema_tree.model.arg
43
- json_schema_tree.last[:leaf][:description] = schema_tree.model.substmt('description').first.arg
44
- json_schema_tree.last[:leaf][:type] = schema_tree.type.arg
45
- end
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
- require 'yaml'
51
- require_relative '../../rubyang'
51
+ require 'yaml'
52
+ require_relative '../../rubyang'
52
53
 
53
- target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
54
+ target_yang = File.expand_path( File.dirname( __FILE__ ) ) + '/target.yang'
54
55
 
55
- model = Rubyang::Model::Parser.parse( File.open( target_yang, 'r' ).read )
56
- db = Rubyang::Database.new
57
- db.load_model model
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
- schema_tree = db.configure.schema
60
+ schema_tree = db.configure.schema
60
61
 
61
- json = make_json_schema schema_tree
62
- puts json
62
+ json = make_json_schema schema_tree
63
+ puts json
63
64
  end