junoser 0.1.6 → 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.
data/lib/junoser/ruler.rb CHANGED
@@ -38,8 +38,11 @@ module Junoser
38
38
 
39
39
  def process_reserved_element(str)
40
40
  str.gsub! /"\$\S+"/, 'arg'
41
- str.gsub! '"as-number" arg', 'arg'
42
- str.gsub! '"confederation-as" arg', 'arg'
41
+
42
+ %w[as-number confederation-as metric-value limit-threshold filename filter-name class-name classifier-name link-subscription per-traffic-class-bandwidth].each do |key|
43
+ str.gsub! %["#{key}" arg], 'arg'
44
+ end
45
+
43
46
  str.gsub! '"equal-literal"', '"="'
44
47
  str.gsub! '"plus-literal"', '"+"'
45
48
  str.gsub! '"minus-literal"', '"-"'
@@ -47,73 +50,94 @@ module Junoser
47
50
  str.gsub!(/\((.*) \| "name"\)/) { "(#$1 | arg)" }
48
51
  str.gsub! '"vlan" ("id-name" | "all")', '"vlan" ("all" | arg)'
49
52
  str.gsub!(/("ssh-\S+") arg/) { "#$1 (quote | arg)" }
50
- str.gsub! '"metric-value" arg', 'arg'
51
- str.gsub! '"limit-threshold" arg', 'arg'
52
- str.gsub! '"filename" arg', 'arg'
53
53
  str.gsub! '"description" arg', '"description" (quote | arg)'
54
54
  str.gsub! '"as-path-prepend" arg', '"as-path-prepend" (quote | arg)'
55
+ str.gsub! '"path-list" arg (', 'b(ipaddr,'
55
56
 
57
+ str.gsub!(/(s\(\s*)"address" \(\s*arg\s*\)/) { "#{$1}arg" }
58
+ str.gsub!(/^(\s*"idle-timeout" \(\s*c\(\s*c\(\s*"forever",\s*)"timeout" arg/) { "#{$1}arg" }
59
+
60
+ str = omit_label(str, 'contents', 'syslog_object')
61
+ str = omit_label(str, 'interface', 'cos_interfaces_type')
62
+ str = omit_label(str, 'interface', 'ir_interfaces_type')
63
+ str = omit_label(str, 'interface', 'interfaces_type')
64
+ str = omit_label(str, 'client-address-list', 'client_address_object')
65
+ str = omit_label(str, 'prefix-list-item', 'prefix_list_items')
66
+ str = omit_label(str, 'instance', 'juniper_routing_instance')
67
+ str = omit_label(str, 'vlan', 'vlan_type')
68
+
69
+ str.gsub!(/"icmp"(.*)"icmp6"/) { %["icmpv6"#$1"icmp"] }
70
+ str.gsub!(/"http"(.*)"https"/) { %["https"#$1"http"] }
71
+ str.gsub!(/"snmp"(.*)"snmptrap"/) { %["snmptrap"#$1"snmp"] }
72
+ str.gsub!(/"cspf"(.*)"cspf-link"/) { %["cspf-link"#$1"cspf"] }
73
+ str.gsub!(/"route-filter" (\(\s*control_route_filter_type\s*\))/) { %["route-filter" arg #{$1}.as(:oneline)] }
74
+ str.gsub!(/"source-address-filter" (\(\s*control_source_address_filter_type\s*\))/) { %["source-adress-filter" arg #{$1}.as(:oneline)] }
75
+ str.gsub!(/("next-hop" \(\s*c\(\s*c\(\s*[^)]*)"address" \(\s*ipaddr\s*\)/) { "#{$1}ipaddr" }
76
+
77
+ %w[metric metric2 metric3 metric4 tag tag2 preference preference2 color color2 local-preference].each do |key|
78
+ str.gsub!(/^(\s*"#{key}" \(\s*c\(\s*c\(\s*)"#{key}" arg/) { "#{$1}arg" }
79
+ end
80
+ str.gsub!(/^(\s*"vrf-target" \(\s*)c\(\s*"community" arg,/) { "#{$1}ca(" }
81
+ str.gsub!(/^(\s*)"priority" \(\s*c\(\s*"setup-priority" arg,\s*"reservation-priority" arg\s*\)\s*\)/) { %[#{$1}a("priority", a(arg, arg)).as(:oneline)] }
82
+
83
+ %w[teardown hold-time stub].each do |key|
84
+ str.gsub!(/^(\s*"#{key}" \(\s*)c\(/) { "#{$1}sc(" }
85
+ end
86
+ %w[file confederation].each do |key|
87
+ str.gsub!(/^(\s*"#{key}" \(\s*)c\(\s*arg,/) { "#{$1}sca(" }
88
+ end
89
+ %w[exact longer orlonger].each do |key|
90
+ str.gsub!(/^(\s*"#{key}") \(\s*arg\s*\)/) { "#{$1}" }
91
+ end
56
92
 
57
93
  str.gsub!(/^(\s*)"inline-services"/) do
58
94
  format(['"inline-services" (',
59
95
  ' "bandwidth" ("1g" | "10g")',
60
96
  ')'], $1)
61
97
  end
62
- str.gsub!(/^(\s*)"ieee-802.3ad" \(\s*sc\(\s*"lacp" \(\s*sc\(/) do
98
+ str.gsub!(/^(\s*)"ieee-802.3ad" \(\s*c\(\s*"lacp" \(\s*c\(/) do
63
99
  format(['"802.3ad" (',
64
- ' sc(',
65
- ' arg,',
100
+ ' ca(',
66
101
  ' "lacp" (',
67
- ' sc(',
102
+ ' c(',
68
103
  ' "force-up",'], $1)
69
104
  end
70
- str.gsub!(/^(\s*)"as-path" \(\s*sc\(\s*"path" arg/) do
105
+ str.gsub!(/^(\s*)"as-path" \(\s*c\(\s*"path" arg,/) do
71
106
  format(['"as-path" (',
72
- ' sc(',
73
- ' arg'], $1)
107
+ ' ca('], $1)
74
108
  end
75
- str.gsub!(/^(\s*)"as-path" arg \(\s*sc\(\s*"path" arg\s*\)/) do
109
+ str.gsub!(/^(\s*)"as-path" arg \(\s*c\(\s*"path" arg\s*\)/) do
76
110
  format(['"as-path" arg (',
77
- ' sc(',
111
+ ' c(',
78
112
  ' quote,',
79
113
  ' arg',
80
114
  ' )'], $1)
81
115
  end
116
+ str.gsub!(/^(\s*)"ribgroup-name" arg$/) do
117
+ format(['arg (',
118
+ ' arg',
119
+ ')'], $1)
120
+ end
82
121
 
83
122
  str.gsub!(/^rule\(:regular_expression\) do\s*((?!end).)*\s*end/) do
84
- "rule(:regular_expression) do
85
- (quote | arg).as(:arg)
86
- end"
123
+ format(['rule(:regular_expression) do',
124
+ ' (quote | arg).as(:arg)',
125
+ 'end'])
87
126
  end
88
-
89
- str.gsub!(/("next-hop" \(\s*sc\(\s*c\(\s*[^)]*)"address" \(\s*ipaddr\s*\)/) { "#{$1}ipaddr" }
90
-
91
- %w[metric metric2 metric3 metric4 tag tag2 preference preference2 color color2 local-preference].each do |key|
92
- str.gsub!(/^(\s*"#{key}" \(\s*sc\(\s*c\(\s*)"#{key}" arg/) { "#{$1}arg" }
127
+ str.gsub!(/^rule\(:login_user_object\) do\s*arg\.as\(:arg\) \(\s*c\(\s*"full-name" arg,/) do
128
+ format(['rule(:login_user_object) do',
129
+ ' arg.as(:arg) (',
130
+ ' sc(',
131
+ ' "full-name" (quote | arg),'])
93
132
  end
94
133
 
95
- str.gsub!(/(s\(\s*)"address" \(\s*arg\s*\)/) { "#{$1}arg" }
96
- str.gsub!(/^(\s*"idle-timeout" \(\s*sc\(\s*c\(\s*"forever",\s*)"timeout" arg/) { "#{$1}arg" }
97
-
98
- str = omit_label(str, 'contents', 'syslog_object')
99
- str = omit_label(str, 'interface', 'cos_interfaces_type')
100
- str = omit_label(str, 'interface', 'ir_interfaces_type')
101
- str = omit_label(str, 'interface', 'interfaces_type')
102
- str = omit_label(str, 'client-address-list', 'client_address_object')
103
- str = omit_label(str, 'prefix-list-item', 'prefix_list_items')
104
- str = omit_label(str, 'instance', 'juniper_routing_instance')
105
- str = omit_label(str, 'vlan', 'vlan_type')
106
-
107
- str.gsub!(/"icmp"(.*)"icmp6"/) { %["icmpv6"#$1"icmp"] }
108
- str.gsub!(/"http"(.*)"https"/) { %["https"#$1"http"] }
109
- str.gsub!(/"snmp"(.*)"snmptrap"/) { %["snmptrap"#$1"snmp"] }
110
-
111
- str.gsub!(/(rule\(:juniper_policy_options\) do\s*)sc\(/) { "#{$1}c(" }
112
-
113
- str.gsub!(/"route-filter" (\(\s*control_route_filter_type\s*\))/) { %["route-filter" arg #{$1}.as(:oneline)] }
134
+ str.gsub!(/(rule\(:juniper_policy_options\) do\s*)c\(/) { "#{$1}c(" }
114
135
  str.gsub!(/(rule\(:control_route_filter_type\) do\s*)s\(\s*arg,/) { "#{$1}b(" }
115
- str.gsub!(/"source-address-filter" (\(\s*control_source_address_filter_type\s*\))/) { %["source-adress-filter" arg #{$1}.as(:oneline)] }
116
136
  str.gsub!(/(rule\(:control_source_address_filter_type\) do\s*)s\(\s*arg,/) { "#{$1}b(" }
137
+ str.gsub!(/^(rule\(:trace_file_type\) do\s*)c\(\s*arg,/) { "#{$1}sca(" }
138
+ str.gsub!(/^(rule\(:archive_object\) do\s*)c\(/) { "#{$1}sc(" }
139
+
140
+ str.gsub!(/^(\s*)c\(\s*arg,$/) { "#{$1}ca(" }
117
141
 
118
142
  str
119
143
  end
@@ -152,6 +176,10 @@ module Junoser
152
176
  objects.inject {|rule, object| rule | object }
153
177
  end
154
178
 
179
+ def ca(*objects)
180
+ objects.inject {|rule, object| rule | object } | arg
181
+ end
182
+
155
183
  # sequence
156
184
  def s(*objects)
157
185
  # TODO: eval "minOccurs" attribute of choice element
@@ -163,6 +191,10 @@ module Junoser
163
191
  (c(*objects) >> space.maybe).repeat(0)
164
192
  end
165
193
 
194
+ def sca(*objects)
195
+ (c(*objects, arg) >> space.maybe).repeat(0)
196
+ end
197
+
166
198
  rule(:arg) { match('\\S').repeat(1) }
167
199
  rule(:space) { match('\\s').repeat(1) }
168
200
  rule(:any) { match('.').repeat(1) }
@@ -1,3 +1,3 @@
1
1
  module Junoser
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -28,7 +28,7 @@ module Junoser
28
28
  when has_single_child_of?(Junoser::Xsd::Choice)
29
29
  child = config.first
30
30
  str = child.config.map(&:to_s).compact.join(",\n")
31
- format('sc(', str, ')') unless str.empty?
31
+ format('c(', str, ')') unless str.empty?
32
32
  else
33
33
  str = config.map {|c| c.is_a?(String) ? format(OFFSET + c) : c.to_s }.compact.join(",\n")
34
34
  format('s(', str, ')')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junoser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -153,9 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.4.5
156
+ rubygems_version: 2.4.5.1
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: PEG parser for JUNOS configuration.
160
160
  test_files: []
161
- has_rdoc: