junoser 0.2.13 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Rakefile +5 -3
- data/example/vmx-17.2R1.13.rb +94962 -0
- data/lib/junoser/parser.rb +87922 -31833
- data/lib/junoser/ruler.rb +62 -58
- data/lib/junoser/version.rb +1 -1
- data/lib/junoser/xsd/base.rb +4 -0
- data/lib/junoser/xsd/element.rb +7 -2
- data/lib/junoser/xsd/enumeration.rb +5 -1
- data/lib/junoser/xsd/parsable.rb +1 -1
- data/lib/junoser/xsd/restriction.rb +5 -1
- data/lib/junoser/xsd/simple_type.rb +28 -0
- data/lib/junoser/xsd/union.rb +24 -0
- metadata +5 -2
data/lib/junoser/ruler.rb
CHANGED
@@ -48,41 +48,26 @@ module Junoser
|
|
48
48
|
str.gsub! '"minus-literal"', '"-"'
|
49
49
|
|
50
50
|
str.gsub!(/\((.*) \| "name"\)/) { "(#$1 | arg)" }
|
51
|
-
str.gsub!(/\("name" \| (.*)\)/) { "(arg | #$1)" }
|
52
|
-
str.gsub! '"vlan" ("id-name" | "all")', '"vlan" ("all" | arg)'
|
53
51
|
str.gsub! '"vlan" ("all" | "vlan-name")', '"vlan" ("all" | arg)'
|
52
|
+
str.gsub!(/\((.*) \| "vlan-id"\)/) { "(#$1 | arg)" }
|
54
53
|
str.gsub!(/("ssh-\S+") arg/) { "#$1 (quote | arg)" }
|
55
54
|
str.gsub! '"description" arg', '"description" (quote | arg)'
|
56
55
|
str.gsub! '"as-path-prepend" arg', '"as-path-prepend" (quote | arg)'
|
57
|
-
str.gsub!
|
56
|
+
str.gsub!(/arg \| (".*")/) { "#$1 | arg" }
|
58
57
|
str.gsub! '"dhcp-service" (', '("dhcp-service" | "dhcp") ('
|
59
58
|
|
60
|
-
str.gsub!(/(
|
61
|
-
str.gsub!(
|
62
|
-
|
63
|
-
str = omit_label(str, 'contents', 'syslog_object')
|
64
|
-
str = omit_label(str, 'interface', 'cos_interfaces_type')
|
65
|
-
str = omit_label(str, 'interface', 'ir_interfaces_type')
|
66
|
-
str = omit_label(str, 'interface', 'interfaces_type')
|
67
|
-
str = omit_label(str, 'client-address-list', 'client_address_object')
|
68
|
-
str = omit_label(str, 'prefix-list-item', 'prefix_list_items')
|
69
|
-
str = omit_label(str, 'instance', 'juniper_routing_instance')
|
70
|
-
str = omit_label(str, 'vlan', 'vlan_type')
|
71
|
-
str = omit_label(str, 'dynamic-tunnel', 'dynamic_tunnel_type')
|
72
|
-
|
73
|
-
str.gsub!(/"icmp"(.*)"icmp6"/) { %["icmpv6"#$1"icmp"] }
|
59
|
+
str.gsub!(/"inet"(.*)"inet6"/) { %["inet6"#$1"inet"] }
|
60
|
+
str.gsub!(/"icmp"(.*)"icmp6"/) { %["icmp6"#$1"icmp"] }
|
61
|
+
str.gsub!(/"icmp"(.*)"icmpv6"/) { %["icmpv6"#$1"icmp"] }
|
74
62
|
str.gsub!(/"http"(.*)"https"/) { %["https"#$1"http"] }
|
75
63
|
str.gsub!(/"snmp"(.*)"snmptrap"/) { %["snmptrap"#$1"snmp"] }
|
64
|
+
%w[ccc ethernet-over-atm tcc vpls bridge].each do |encap|
|
65
|
+
str.gsub!(/"ethernet"(.*)"ethernet-#{encap}"/) { %["ethernet-#{encap}"#$1"ethernet"] }
|
66
|
+
end
|
67
|
+
str.gsub! '"icmp6" |', '"icmp6" | "icmpv6" |'
|
76
68
|
str.gsub!(/"cspf"(.*)"cspf-link"/) { %["cspf-link"#$1"cspf"] }
|
77
69
|
str.gsub!(/"route-filter" (\(\s*control_route_filter_type\s*\))/) { %["route-filter" arg #{$1}.as(:oneline)] }
|
78
70
|
str.gsub!(/"source-address-filter" (\(\s*control_source_address_filter_type\s*\))/) { %["source-adress-filter" arg #{$1}.as(:oneline)] }
|
79
|
-
str.gsub!(/("next-hop" \(\s*c\(\s*c\(\s*[^)]*)"address" \(\s*ipaddr\s*\)/) { "#{$1}ipaddr" }
|
80
|
-
|
81
|
-
%w[metric metric2 metric3 metric4 tag tag2 preference preference2 color color2 local-preference].each do |key|
|
82
|
-
str.gsub!(/^(\s*"#{key}" \(\s*c\(\s*c\(\s*)"#{key}" arg/) { "#{$1}arg" }
|
83
|
-
end
|
84
|
-
str.gsub!(/^(\s*"vrf-target" \(\s*)c\(\s*"community" arg,/) { "#{$1}ca(" }
|
85
|
-
str.gsub!(/^(\s*)"priority" \(\s*c\(\s*"setup-priority" arg,\s*"reservation-priority" arg\s*\)\s*\)/) { %[#{$1}a("priority", a(arg, arg)).as(:oneline)] }
|
86
71
|
|
87
72
|
%w[teardown hold-time stub].each do |key|
|
88
73
|
str.gsub!(/^(\s*"#{key}" \(\s*)c\(/) { "#{$1}sc(" }
|
@@ -94,11 +79,7 @@ module Junoser
|
|
94
79
|
str.gsub!(/^(\s*"#{key}") arg/) { "#{$1}" }
|
95
80
|
end
|
96
81
|
|
97
|
-
|
98
|
-
format(['"inline-services" (',
|
99
|
-
' "bandwidth" ("1g" | "10g")',
|
100
|
-
')'], $1)
|
101
|
-
end
|
82
|
+
|
102
83
|
str.gsub!(/^(\s*)"ieee-802.3ad" \(\s*c\(\s*"lacp" \(\s*c\(/) do
|
103
84
|
format(['"802.3ad" (',
|
104
85
|
' ca(',
|
@@ -106,20 +87,34 @@ module Junoser
|
|
106
87
|
' c(',
|
107
88
|
' "force-up",'], $1)
|
108
89
|
end
|
109
|
-
str.gsub!(/^(\s*)"as-path" \(\s*c\(\s*
|
110
|
-
format(['"as-path" (',
|
111
|
-
' ca('], $1)
|
112
|
-
end
|
113
|
-
str.gsub!(/^(\s*)"as-path" arg \(\s*c\(\s*"path" arg\s*\)/) do
|
90
|
+
str.gsub!(/^(\s*)"as-path" arg \(\s*c\(\s*arg/) do
|
114
91
|
format(['"as-path" arg (',
|
115
92
|
' c(',
|
116
|
-
' quote
|
117
|
-
' arg',
|
118
|
-
' )'], $1)
|
93
|
+
' quote | arg'], $1)
|
119
94
|
end
|
120
|
-
str.gsub!(/^(\s*)"
|
121
|
-
format(['
|
122
|
-
' arg',
|
95
|
+
str.gsub!(/^(\s*)"priority" \(\s*c\(\s*arg,\s*arg\s*\)/) do
|
96
|
+
format(['"priority" (',
|
97
|
+
' a(arg, arg)', $1])
|
98
|
+
end
|
99
|
+
str.gsub!(/^(\s*)"path" arg \(\s*c\(\s*c\(\s*"abstract",\s*c\(\s*"loose",\s*"loose-link",\s*"strict"\s*\)\s*\)\.as\(:oneline\)/) do
|
100
|
+
format(['"path" arg (',
|
101
|
+
' c(',
|
102
|
+
' b(',
|
103
|
+
' ipaddr,',
|
104
|
+
' c(',
|
105
|
+
' "abstract",',
|
106
|
+
' c(',
|
107
|
+
' "loose-link",',
|
108
|
+
' "loose",',
|
109
|
+
' "strict"',
|
110
|
+
' )',
|
111
|
+
' ).as(:oneline)',
|
112
|
+
' )', $1])
|
113
|
+
end
|
114
|
+
|
115
|
+
str.gsub!(/^(\s*)c\(\s*\("default"\)\s*\)/) do
|
116
|
+
format(['c(',
|
117
|
+
' ("default" | arg)',
|
123
118
|
')'], $1)
|
124
119
|
end
|
125
120
|
|
@@ -135,21 +130,21 @@ module Junoser
|
|
135
130
|
' "full-name" (quote | arg),'])
|
136
131
|
end
|
137
132
|
|
138
|
-
str.gsub!(/(rule\(:juniper_policy_options\) do\s*)c\(/) { "#{$1}c(" }
|
139
133
|
str.gsub!(/(rule\(:control_route_filter_type\) do\s*)s\(\s*arg,/) { "#{$1}b(" }
|
140
134
|
str.gsub!(/(rule\(:control_source_address_filter_type\) do\s*)s\(\s*arg,/) { "#{$1}b(" }
|
141
135
|
str.gsub!(/^(rule\(:trace_file_type\) do\s*)c\(\s*arg,/) { "#{$1}sca(" }
|
142
136
|
str.gsub!(/^(rule\(:archive_object\) do\s*)c\(/) { "#{$1}sc(" }
|
137
|
+
str.gsub!(/^(rule\(:rib_group_inet_type\) do)\s*c\(\s*arg/) do
|
138
|
+
format([$1,
|
139
|
+
' ca(',
|
140
|
+
' a(arg, arg)'], '')
|
141
|
+
end
|
143
142
|
|
144
143
|
str.gsub!(/^(\s*)c\(\s*arg,$/) { "#{$1}ca(" }
|
145
144
|
|
146
145
|
str
|
147
146
|
end
|
148
147
|
|
149
|
-
def omit_label(str, label, content)
|
150
|
-
str.gsub(/(\s*)"#{label}" \(\s*#{content}\s*\)/) { "#{$1}#{content}" }
|
151
|
-
end
|
152
|
-
|
153
148
|
def format(str, offset=OFFSET)
|
154
149
|
case str
|
155
150
|
when String
|
@@ -166,25 +161,34 @@ require 'parslet'
|
|
166
161
|
module Junoser
|
167
162
|
class Parser < Parslet::Parser
|
168
163
|
def parse_lines(config)
|
169
|
-
lines = config.split("\\n")
|
164
|
+
lines = config.split("\\n").map(&:strip)
|
170
165
|
lines_without_deactivate = lines.reject {|l| l =~ /^deactivate/ }
|
171
166
|
|
172
167
|
lines.inject(true) do |passed, line|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
168
|
+
passed & parse_line(line, lines_without_deactivate)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def parse_line(line, lines_without_deactivate)
|
173
|
+
if line =~ /^deactivate/
|
174
|
+
if lines_without_deactivate.grep(/^\#{line.sub(/^deactivate/, 'set')}/).empty?
|
175
|
+
$stderr.puts %(Corresponding "set" statement is not found: \#{line})
|
176
|
+
return false
|
177
|
+
else
|
178
|
+
return true
|
179
179
|
end
|
180
|
+
end
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
rescue Parslet::ParseFailed
|
185
|
-
$stderr.puts "Invalid syntax: \#{line}"
|
186
|
-
false
|
182
|
+
begin
|
183
|
+
if line =~ /(.*)\\s+apply-groups\\s+\\S+\$/
|
184
|
+
return \$1 == 'set' ? true : parse(\$1)
|
187
185
|
end
|
186
|
+
|
187
|
+
parse line
|
188
|
+
true
|
189
|
+
rescue Parslet::ParseFailed
|
190
|
+
$stderr.puts "Invalid syntax: \#{line}"
|
191
|
+
false
|
188
192
|
end
|
189
193
|
end
|
190
194
|
|
data/lib/junoser/version.rb
CHANGED
data/lib/junoser/xsd/base.rb
CHANGED
@@ -39,6 +39,10 @@ module Junoser
|
|
39
39
|
@oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/flag[text()="oneliner"]').empty?
|
40
40
|
end
|
41
41
|
|
42
|
+
def nokeyword?
|
43
|
+
@nokeyword ||= !xml.xpath('./xsd:annotation/xsd:appinfo/flag[text()="nokeyword"]').empty?
|
44
|
+
end
|
45
|
+
|
42
46
|
def has_single_child_of?(klass)
|
43
47
|
config.size == 1 && config.first.is_a?(klass)
|
44
48
|
end
|
data/lib/junoser/xsd/element.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'junoser/xsd/base'
|
2
2
|
require 'junoser/xsd/complex_type'
|
3
|
+
require 'junoser/xsd/simple_type'
|
3
4
|
|
4
5
|
module Junoser
|
5
6
|
module Xsd
|
@@ -17,7 +18,7 @@ module Junoser
|
|
17
18
|
when 'complexType'
|
18
19
|
Junoser::Xsd::ComplexType.new(child, depth: @depth+1)
|
19
20
|
when 'simpleType'
|
20
|
-
|
21
|
+
Junoser::Xsd::SimpleType.new(child, depth: @depth+1)
|
21
22
|
else
|
22
23
|
raise "ERROR: unknown element: #{child.name}"
|
23
24
|
end
|
@@ -26,9 +27,13 @@ module Junoser
|
|
26
27
|
|
27
28
|
def to_s
|
28
29
|
str = case
|
30
|
+
when nokeyword? && content.empty?
|
31
|
+
format('arg')
|
32
|
+
when nokeyword?
|
33
|
+
content
|
29
34
|
when content.empty?
|
30
35
|
format(label)
|
31
|
-
when content =~
|
36
|
+
when content =~ /\A *arg\z/
|
32
37
|
format("#{label} arg")
|
33
38
|
when label
|
34
39
|
format("#{label} (", content, ')')
|
data/lib/junoser/xsd/parsable.rb
CHANGED
@@ -22,7 +22,7 @@ module Junoser
|
|
22
22
|
|
23
23
|
def remove_unused
|
24
24
|
xpath('/xsd:schema/*[self::xsd:import]').remove
|
25
|
-
xpath('//xsd:element[@ref="undocumented" or @ref="junos:comment"]').remove
|
25
|
+
xpath('//xsd:element[@ref="undocumented" or @ref="junos:comment" or @name="apply-advanced"]').remove
|
26
26
|
self
|
27
27
|
end
|
28
28
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'junoser/xsd/base'
|
2
2
|
require 'junoser/xsd/enumeration'
|
3
|
+
require 'junoser/xsd/simple_type'
|
3
4
|
|
4
5
|
module Junoser
|
5
6
|
module Xsd
|
@@ -17,10 +18,13 @@ module Junoser
|
|
17
18
|
case child.name
|
18
19
|
when 'enumeration'
|
19
20
|
Junoser::Xsd::Enumeration.new(child, depth: @depth+1)
|
21
|
+
when 'simpleType'
|
22
|
+
Junoser::Xsd::SimpleType.new(child, depth: @depth+1)
|
23
|
+
when 'attribute'
|
20
24
|
else
|
21
25
|
raise "ERROR: unknown element: #{child.name}"
|
22
26
|
end
|
23
|
-
}
|
27
|
+
}.compact
|
24
28
|
end
|
25
29
|
|
26
30
|
def to_s
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'junoser/xsd/base'
|
2
|
+
require 'junoser/xsd/restriction'
|
3
|
+
require 'junoser/xsd/union'
|
4
|
+
|
5
|
+
module Junoser
|
6
|
+
module Xsd
|
7
|
+
class SimpleType
|
8
|
+
include Base
|
9
|
+
|
10
|
+
def config
|
11
|
+
@config ||= children.map {|child|
|
12
|
+
case child.name
|
13
|
+
when 'restriction'
|
14
|
+
Junoser::Xsd::Restriction.new(child, depth: @depth+1)
|
15
|
+
when 'union'
|
16
|
+
Junoser::Xsd::Union.new(child, depth: @depth+1)
|
17
|
+
else
|
18
|
+
raise "ERROR: unknown element: #{child.name}"
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
format(config.first.to_s.strip)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'junoser/xsd/base'
|
2
|
+
|
3
|
+
module Junoser
|
4
|
+
module Xsd
|
5
|
+
class Union
|
6
|
+
include Base
|
7
|
+
|
8
|
+
def config
|
9
|
+
@config ||= children.map {|child|
|
10
|
+
case child.name
|
11
|
+
when 'simpleType'
|
12
|
+
Junoser::Xsd::SimpleType.new(child, depth: @depth+1)
|
13
|
+
else
|
14
|
+
raise "ERROR: unknown element: #{child.name}"
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
format(config.first.to_s.strip)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
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.
|
4
|
+
version: 0.3.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: 2017-10-
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- bin/console
|
99
99
|
- bin/setup
|
100
|
+
- example/vmx-17.2R1.13.rb
|
100
101
|
- example/vsrx-12.1.x47.rb
|
101
102
|
- exe/junoser
|
102
103
|
- junoser.gemspec
|
@@ -121,6 +122,8 @@ files:
|
|
121
122
|
- lib/junoser/xsd/restriction.rb
|
122
123
|
- lib/junoser/xsd/sequence.rb
|
123
124
|
- lib/junoser/xsd/simple_content.rb
|
125
|
+
- lib/junoser/xsd/simple_type.rb
|
126
|
+
- lib/junoser/xsd/union.rb
|
124
127
|
- lib/underscorable.rb
|
125
128
|
homepage: https://github.com/codeout/junoser
|
126
129
|
licenses: []
|