rubyang 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1442,7 +1442,7 @@ rule
1442
1442
  "string" : STRING
1443
1443
  | "string" "+" STRING
1444
1444
  {
1445
- result = val[0] + val[1]
1445
+ result = val[0] + val[2]
1446
1446
  }
1447
1447
 
1448
1448
  "stmtend" : ";"
@@ -1,4 +1,11 @@
1
1
  # coding: utf-8
2
2
 
3
- require_relative 'restapi/httpd.rb'
3
+ require_relative 'restapi/app'
4
+
5
+ module Rubyang
6
+ module RestAPI
7
+ end
8
+ end
9
+
10
+ Rubyang::RestAPI::App.run!
4
11
 
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'sinatra/base'
6
+ require 'sinatra/reloader'
7
+ require 'sinatra/respond_with'
8
+
9
+ require_relative '../../rubyang'
10
+
11
+ module Rubyang
12
+ module RestAPI
13
+ class App < Sinatra::Base
14
+ set :environment, :development
15
+ set :bind, '0.0.0.0'
16
+
17
+ configure :development do
18
+ register Sinatra::Reloader
19
+ end
20
+
21
+ register Sinatra::RespondWith
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
+ db.configure.edit('container1').edit('container2').edit('leaf1').set('value')
29
+
30
+
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
39
+
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
51
+
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
62
+
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
68
+
69
+ run! if app_file == $0
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../rubyang'
4
+
5
+ module Rubyang
6
+ module Server
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../../rubyang'
4
+
5
+ require 'fileutils'
6
+ require 'drb/drb'
7
+
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"
16
+
17
+ FileUtils.mkdir_p @sock_dir
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
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
30
+ end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ class Example < Rubyang::Server::Base
6
+ end
7
+
8
+ example = Example.new
9
+ example.run
@@ -1,3 +1,3 @@
1
1
  module Rubyang
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -30,7 +30,7 @@ function make_form(trees, parent_id){
30
30
  }else if(stmt == "leaf"){
31
31
  var child_schema_path = parent_id + '/' + tree["name"];
32
32
  var child_id = next_id();
33
- addleaf(parent_id, child_id, child_schema_path, tree["name"], tree["description"], 'string', '');
33
+ addleaf(parent_id, child_id, child_schema_path, tree["name"], tree["description"], tree["type"], '');
34
34
  }
35
35
  }
36
36
  }
@@ -204,7 +204,27 @@ function addleaf(parent_id, id, schemapath, schemaname, description, datatype, o
204
204
  label.attr('for', id_form);
205
205
  label.html(description);
206
206
 
207
- if(datatype == "string"){
207
+ if(datatype == "binary"){
208
+ input = $('<input>');
209
+ input.attr('id',id_form);
210
+ input.addClass('form-control');
211
+ input.attr('type', 'text');
212
+ }else if(datatype == "bits"){
213
+ input = $('<input>');
214
+ input.attr('id',id_form);
215
+ input.addClass('form-control');
216
+ input.attr('type', 'text');
217
+ }else if(datatype == "boolean"){
218
+ input = $('<input>');
219
+ input.attr('id',id_form);
220
+ input.addClass('form-control');
221
+ input.attr('type', 'text');
222
+ }else if(datatype == "decimal64"){
223
+ input = $('<input>');
224
+ input.attr('id',id_form);
225
+ input.addClass('form-control');
226
+ input.attr('type', 'text');
227
+ }else if(datatype == "empty"){
208
228
  input = $('<input>');
209
229
  input.attr('id',id_form);
210
230
  input.addClass('form-control');
@@ -221,7 +241,79 @@ function addleaf(parent_id, id, schemapath, schemaname, description, datatype, o
221
241
  input.append(option0);
222
242
  input.append(option1);
223
243
  input.append(option2);
224
- }else{
244
+ }else if(datatype == "identityref"){
245
+ input = $('<input>');
246
+ input.attr('id',id_form);
247
+ input.addClass('form-control');
248
+ input.attr('type', 'text');
249
+ }else if(datatype == "instance-identifier"){
250
+ input = $('<input>');
251
+ input.attr('id',id_form);
252
+ input.addClass('form-control');
253
+ input.attr('type', 'text');
254
+ }else if(datatype == "int8"){
255
+ input = $('<input>');
256
+ input.attr('id',id_form);
257
+ input.addClass('form-control');
258
+ input.attr('type', 'text');
259
+ }else if(datatype == "int16"){
260
+ input = $('<input>');
261
+ input.attr('id',id_form);
262
+ input.addClass('form-control');
263
+ input.attr('type', 'text');
264
+ }else if(datatype == "int32"){
265
+ input = $('<input>');
266
+ input.attr('id',id_form);
267
+ input.addClass('form-control');
268
+ input.attr('type', 'text');
269
+ }else if(datatype == "int64"){
270
+ input = $('<input>');
271
+ input.attr('id',id_form);
272
+ input.addClass('form-control');
273
+ input.attr('type', 'text');
274
+ }else if(datatype == "leafref"){
275
+ input = $('<select>');
276
+ input.attr('id',id_form);
277
+ input.addClass('form-control');
278
+ var option0 = $('<option>');
279
+ var option1 = $('<option>');
280
+ var option2 = $('<option>');
281
+ option0.html('0');
282
+ option1.html('1');
283
+ option2.html('2');
284
+ input.append(option0);
285
+ input.append(option1);
286
+ input.append(option2);
287
+ }else if(datatype == "string"){
288
+ input = $('<input>');
289
+ input.attr('id',id_form);
290
+ input.addClass('form-control');
291
+ input.attr('type', 'text');
292
+ }else if(datatype == "uint8"){
293
+ input = $('<input>');
294
+ input.attr('id',id_form);
295
+ input.addClass('form-control');
296
+ input.attr('type', 'text');
297
+ }else if(datatype == "uint16"){
298
+ input = $('<input>');
299
+ input.attr('id',id_form);
300
+ input.addClass('form-control');
301
+ input.attr('type', 'text');
302
+ }else if(datatype == "uint32"){
303
+ input = $('<input>');
304
+ input.attr('id',id_form);
305
+ input.addClass('form-control');
306
+ input.attr('type', 'text');
307
+ }else if(datatype == "uint64"){
308
+ input = $('<input>');
309
+ input.attr('id',id_form);
310
+ input.addClass('form-control');
311
+ input.attr('type', 'text');
312
+ }else if(datatype == "union"){
313
+ input = $('<input>');
314
+ input.attr('id',id_form);
315
+ input.addClass('form-control');
316
+ input.attr('type', 'text');
225
317
  }
226
318
 
227
319
  $('#'+parent_id).append(panel);
@@ -0,0 +1,33 @@
1
+ module rubyang {
2
+ namespace "http://github.com/hirura/rubyang";
3
+ prefix rubyang;
4
+
5
+ organization "rubyang";
6
+ contact "http://github.com/hirura/";
7
+ description "The module to support some basic features";
8
+
9
+ revision 2016-07-02 {
10
+ description "Initial revision. Just for testing.";
11
+ }
12
+
13
+ container rubyang {
14
+ list component {
15
+ key name;
16
+ leaf name {
17
+ type string;
18
+ }
19
+ leaf hook {
20
+ type enumeration {
21
+ //enum start;
22
+ enum commit;
23
+ //enum finish;
24
+ }
25
+ }
26
+ leaf file-path {
27
+ type string {
28
+ pattern '/.+\.rb';
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
data/rubyang.gemspec CHANGED
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "sinatra", '~> 1.0'
31
31
  spec.add_dependency "sinatra-contrib", '~> 1.0'
32
32
 
33
- spec.add_development_dependency "bundler", '~> 1.0'
34
- spec.add_development_dependency "rake", '~> 11.0'
35
- spec.add_development_dependency "rspec", '~> 3.0'
36
- spec.add_development_dependency "racc", '~> 1.0'
37
- spec.add_development_dependency "coveralls", '~> 0.0'
33
+ spec.add_development_dependency "bundler", '~> 1.0'
34
+ spec.add_development_dependency "rake", '~> 11.0'
35
+ spec.add_development_dependency "rspec", '~> 3.0'
36
+ spec.add_development_dependency "racc", '~> 1.0'
37
+ spec.add_development_dependency "codeclimate-test-reporter", '~> 0.0'
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hirura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: coveralls
98
+ name: codeclimate-test-reporter
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
@@ -131,7 +131,10 @@ files:
131
131
  - lib/rubyang.rb
132
132
  - lib/rubyang/cli.rb
133
133
  - lib/rubyang/cli/parser.rb
134
+ - lib/rubyang/component/base.rb
135
+ - lib/rubyang/component/example.rb
134
136
  - lib/rubyang/database.rb
137
+ - lib/rubyang/database/component_manager.rb
135
138
  - lib/rubyang/database/data_tree.rb
136
139
  - lib/rubyang/database/helper.rb
137
140
  - lib/rubyang/database/schema_tree.rb
@@ -140,7 +143,10 @@ files:
140
143
  - lib/rubyang/model/parser/parser.tab.rb
141
144
  - lib/rubyang/model/parser/parser.y
142
145
  - lib/rubyang/restapi.rb
143
- - lib/rubyang/restapi/httpd.rb
146
+ - lib/rubyang/restapi/app.rb
147
+ - lib/rubyang/server.rb
148
+ - lib/rubyang/server/base.rb
149
+ - lib/rubyang/server/example.rb
144
150
  - lib/rubyang/version.rb
145
151
  - lib/rubyang/webui.rb
146
152
  - lib/rubyang/webui/app.rb
@@ -152,6 +158,7 @@ files:
152
158
  - lib/rubyang/xpath/parser.rb
153
159
  - lib/rubyang/xpath/parser/parser.tab.rb
154
160
  - lib/rubyang/xpath/parser/parser.y
161
+ - lib/rubyang/yang/rubyang.yang
155
162
  - rubyang.gemspec
156
163
  homepage: https://github.com/hirura/rubyang
157
164
  licenses:
@@ -1,62 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'sinatra'
4
- require 'sinatra/contrib'
5
- require 'sinatra/reloader'
6
- require 'json'
7
-
8
- require_relative '../../rubyang'
9
- db = Rubyang::Database.new
10
- yang_str = <<-EOB
11
- module module1 {
12
- namespace "http://module1/";
13
- prefix module1;
14
- container container1 {
15
- container container2 {
16
- leaf leaf1 { type string; }
17
- }
18
- }
19
- }
20
- EOB
21
- db.load_model Rubyang::Model::Parser.parse( yang_str )
22
- config = db.configure
23
- config.edit( 'container1' ).edit( 'container2' ).edit( 'leaf1' ).set( 'aaa' )
24
-
25
-
26
- get '/' do
27
- respond_to do |f|
28
- f.on( 'application/xml' ){
29
- config = db.configure
30
- config.to_xml( pretty: true )
31
- }
32
- end
33
- end
34
-
35
- get %r{/api(?:/(.+)[/]?)} do
36
- respond_to do |f|
37
- f.on( 'application/xml' ){
38
- #{ params: ' '+params[:captures][0] }.to_json
39
- config = db.configure
40
- paths = params[:captures][0].split( '/' )
41
- element = paths.inject( config ){ |parent, child| parent.edit( child ) }
42
- element.to_xml( pretty: true )
43
- }
44
- end
45
- end
46
-
47
- post %r{/api(?:/(.+)[/]?)} do
48
- body = request.body.read
49
- respond_to do |f|
50
- f.on( 'application/xml' ){
51
- config = db.configure
52
- paths = params[:captures][0].split( '/' )
53
- element = paths.inject( config ){ |parent, child| parent.edit( child ) }
54
- }
55
- end
56
- end
57
-
58
- get %r{/api[/]?} do
59
- respond_to do |f|
60
- f.on( 'application/xml' ){ db.configure.to_xml( pretty: true ) }
61
- end
62
- end