construqt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/lib/construqt/addresses.rb +204 -0
  3. data/lib/construqt/bgps.rb +164 -0
  4. data/lib/construqt/cables.rb +47 -0
  5. data/lib/construqt/firewalls.rb +247 -0
  6. data/lib/construqt/flavour/ciscian/ciscian.rb +687 -0
  7. data/lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb +235 -0
  8. data/lib/construqt/flavour/ciscian/dialect_hp-2510g.rb +114 -0
  9. data/lib/construqt/flavour/delegates.rb +448 -0
  10. data/lib/construqt/flavour/flavour.rb +97 -0
  11. data/lib/construqt/flavour/mikrotik/flavour_mikrotik.rb +417 -0
  12. data/lib/construqt/flavour/mikrotik/flavour_mikrotik_bgp.rb +134 -0
  13. data/lib/construqt/flavour/mikrotik/flavour_mikrotik_interface.rb +79 -0
  14. data/lib/construqt/flavour/mikrotik/flavour_mikrotik_ipsec.rb +65 -0
  15. data/lib/construqt/flavour/mikrotik/flavour_mikrotik_result.rb +182 -0
  16. data/lib/construqt/flavour/mikrotik/flavour_mikrotik_schema.rb +355 -0
  17. data/lib/construqt/flavour/plantuml/plantuml.rb +462 -0
  18. data/lib/construqt/flavour/ubuntu/flavour_ubuntu.rb +381 -0
  19. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_bgp.rb +117 -0
  20. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_dns.rb +97 -0
  21. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_firewall.rb +300 -0
  22. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_ipsec.rb +144 -0
  23. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_opvn.rb +60 -0
  24. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb +537 -0
  25. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb +115 -0
  26. data/lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb +52 -0
  27. data/lib/construqt/flavour/unknown/unknown.rb +175 -0
  28. data/lib/construqt/hostid.rb +42 -0
  29. data/lib/construqt/hosts.rb +98 -0
  30. data/lib/construqt/interfaces.rb +166 -0
  31. data/lib/construqt/ipsecs.rb +64 -0
  32. data/lib/construqt/networks.rb +81 -0
  33. data/lib/construqt/regions.rb +32 -0
  34. data/lib/construqt/resource.rb +42 -0
  35. data/lib/construqt/services.rb +53 -0
  36. data/lib/construqt/tags.rb +61 -0
  37. data/lib/construqt/templates.rb +37 -0
  38. data/lib/construqt/tests/test_addresses.rb +50 -0
  39. data/lib/construqt/tests/test_bgps.rb +24 -0
  40. data/lib/construqt/tests/test_hostid.rb +32 -0
  41. data/lib/construqt/tests/test_hosts.rb +23 -0
  42. data/lib/construqt/tests/test_utils.rb +76 -0
  43. data/lib/construqt/users.rb +19 -0
  44. data/lib/construqt/util.rb +163 -0
  45. data/lib/construqt/version.rb +3 -0
  46. data/lib/construqt/vlans.rb +51 -0
  47. data/lib/construqt.rb +92 -0
  48. metadata +105 -0
@@ -0,0 +1,235 @@
1
+ module Construqt
2
+ module Flavour
3
+ module Ciscian
4
+ module DlinkDgs15xx
5
+
6
+ class HostNameVerb < PatternBasedVerb
7
+ def self.section
8
+ "snmp-server name"
9
+ end
10
+
11
+ def self.find_regex(variable)
12
+ {
13
+ "name" => "(.*)"
14
+ }[variable]
15
+ end
16
+
17
+ def self.patterns
18
+ ["snmp-server name {+name}"]
19
+ end
20
+ end
21
+
22
+ class MtuVerb < PatternBasedVerb
23
+ def self.section
24
+ "max-rcv-frame-size"
25
+ end
26
+
27
+ def self.find_regex(variable)
28
+ {
29
+ "frame-size" => "(.*)"
30
+ }[variable]
31
+ end
32
+
33
+ def self.patterns
34
+ ["max-rcv-frame-size {+framesize}"]
35
+ end
36
+ end
37
+
38
+ class SwitchPortTrunkAllowedVlan < PatternBasedVerb
39
+ def self.section
40
+ "switchport trunk allowed vlan"
41
+ end
42
+
43
+ def self.patterns
44
+ ["no switchport trunk allowed vlan", "switchport trunk allowed vlan {=vlans}"]
45
+ end
46
+ end
47
+
48
+ class ChannelGroupVerb < PatternBasedVerb
49
+ def self.section
50
+ "channel-group"
51
+ end
52
+
53
+ def self.patterns
54
+ ["no channel-group", "channel-group {+channel} mode active"]
55
+ end
56
+ end
57
+
58
+ class Ipv4RouteVerb < PatternBasedVerb
59
+ def self.section
60
+ "ip route"
61
+ end
62
+
63
+ def self.find_regex(variable)
64
+ {
65
+ "routedefs" => "(\\S+\\s+\\S+\\s+\\S+)"
66
+ }[variable]
67
+ end
68
+
69
+ def self.patterns
70
+ ["no ip route {-routedefs}", "ip route {+routedefs}"]
71
+ end
72
+ end
73
+
74
+ class Comment
75
+ def self.parse_line(line, lines, section, result)
76
+ line.to_s.empty? || line.to_s.start_with?("#")
77
+ end
78
+ end
79
+
80
+ class WtfEnd
81
+ def self.parse_line(line, lines, section, result)
82
+ section.kind_of?(Result) && ["end"].include?(line.to_s)
83
+ end
84
+ end
85
+
86
+ class Line
87
+ def self.parse_line(line, lines, section, result)
88
+ return false unless ['line '].find{|i| line.to_s.start_with?(i) }
89
+ section.add(line) do |_section|
90
+ while line = lines.shift
91
+ break if result.dialect.block_end?(line.to_s)
92
+ result.parse_line(line, lines, _section, result)
93
+ end
94
+ end
95
+ true
96
+ end
97
+ end
98
+
99
+ class ConfigureTerminal
100
+ def self.parse_line(line, lines, section, result)
101
+ return false unless ['configure terminal'].find{|i| line.to_s.start_with?(i) }
102
+ while line = lines.shift
103
+ break if result.dialect.block_end?(line.to_s)
104
+ result.parse_line(line, lines, section, result)
105
+ end
106
+ true
107
+ end
108
+ end
109
+
110
+ class Dialect
111
+ def self.name
112
+ 'dlink-dgs15xx'
113
+ end
114
+
115
+ def initialize(result)
116
+ @result=result
117
+ end
118
+
119
+ def block_end?(line)
120
+ ['end','exit'].include?(line.strip)
121
+ end
122
+
123
+ def add_host(host)
124
+ end
125
+
126
+ def add_device(device)
127
+ @result.add("interface #{expand_device_name(device)}") do |section|
128
+ section.add("flowcontrol").add("off")
129
+ section.add("max-rcv-frame-size").add(device.delegate.mtu)
130
+ section.add("snmp trap").add("link-status")
131
+ section.add("switchport mode").add("trunk")
132
+ end
133
+ end
134
+
135
+ def clear_interface(line)
136
+ line.to_s.split(/\s+/).map do |i|
137
+ split = /^([^0-9]+)([0-9].*)$/.match(i)
138
+ split ? split[1..-1] : i
139
+ end.flatten.join(' ')
140
+ end
141
+
142
+ def parse_line(line, lines, section, result)
143
+ [
144
+ WtfEnd,
145
+ ConfigureTerminal,
146
+ Line,
147
+ Comment,
148
+ HostNameVerb,
149
+ MtuVerb,
150
+ SwitchPortTrunkAllowedVlan,
151
+ ChannelGroupVerb,
152
+ Ipv4RouteVerb
153
+ ].find do |i|
154
+ i.parse_line(line, lines, section, result)
155
+ end
156
+ end
157
+
158
+ def expand_device_name(device)
159
+ return device.delegate.dev_name if device.delegate.dev_name
160
+ pattern = (({
161
+ "po" => "port-channel %s",
162
+ "ge" => "ethernet 1/0/%s",
163
+ "te" => "ethernet 1/0/%s"
164
+ })[device.name[0..1]])
165
+ throw "device not expandable #{device.name}" unless pattern
166
+ pattern%device.name[2..-1]
167
+ end
168
+
169
+ def commit
170
+ @result.add("snmp-server name", Ciscian::SingleValueVerb).add(@result.host.name)
171
+ @result.host.interfaces.values.each do |iface|
172
+ next unless iface.delegate.address
173
+ iface.delegate.address.routes.each do |route|
174
+ ip = route.dst.ipv6? ? "ipv6" : "ip"
175
+ @result.add("#{ip} route #{route.dst.to_string} vlan#{iface.delegate.vlan_id} #{route.via.to_s}", Ciscian::SingleValueVerb)
176
+ end
177
+ end
178
+ end
179
+
180
+ def add_device(device)
181
+ @result.add("interface #{expand_device_name(device)}") do |section|
182
+ section.add("flowcontrol").add("off")
183
+ section.add("max-rcv-frame-size").add(device.delegate.mtu)
184
+ section.add("snmp trap").add("link-status")
185
+ section.add("switchport mode").add("trunk")
186
+ end
187
+ end
188
+
189
+ def add_bond(bond)
190
+ bond.interfaces.each do |iface|
191
+ @result.add("interface #{expand_device_name(iface)}") do |section|
192
+ section.add("channel-group", ChannelGroupVerb).add({"{+channel}" => [bond.name[2..-1]]})
193
+ end
194
+ end
195
+ end
196
+
197
+ def add_vlan(vlan)
198
+ @result.add("vlan #{vlan.delegate.vlan_id}") do |section|
199
+ next unless vlan.delegate.description && !vlan.delegate.description.empty?
200
+ throw "vlan name too long, max 32 chars" if vlan.delegate.description.length > 32
201
+ section.add("name").add(vlan.delegate.description)
202
+ end
203
+ @result.add("interface vlan #{vlan.delegate.vlan_id}") do |section|
204
+ if vlan.delegate.address
205
+ if vlan.delegate.address.first_ipv4
206
+ section.add("ip address").add(vlan.delegate.address.first_ipv4.to_string)
207
+ elsif vlan.delegate.address.dhcpv4?
208
+ section.add("ip address").add("dhcp-bootp")
209
+ end
210
+ if vlan.delegate.address.first_ipv6
211
+ section.add("ipv6 address").add(vlan.delegate.address.first_ipv6.to_string)
212
+ elsif vlan.delegate.address.dhcpv6?
213
+ section.add("ipv6 address").add("dhcp-bootp")
214
+ end
215
+ end
216
+ end
217
+
218
+ vlan_id=vlan.delegate.vlan_id
219
+ vlan.interfaces.each do |iface|
220
+ @result.add("interface #{expand_device_name(iface)}") do |section|
221
+ if iface.template.is_tagged?(vlan_id)
222
+ section.add("switchport trunk allowed vlan", Ciscian::RangeVerb).add(vlan_id)
223
+ else
224
+ section.add("switchport trunk native vlan").add(vlan_id)
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ Construqt::Flavour::Ciscian.add_dialect(Dialect)
232
+ end
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,114 @@
1
+ module Construqt
2
+ module Flavour
3
+ module Ciscian
4
+ class Hp2510g
5
+ def self.name
6
+ 'hp-2510g'
7
+ end
8
+
9
+ def initialize(result)
10
+ @result=result
11
+ end
12
+
13
+ def commit
14
+ end
15
+
16
+ def expand_device_name(device)
17
+ return device.delegate.dev_name if device.delegate.dev_name
18
+ pattern = (({
19
+ "po" => "Trk%s",
20
+ "ge" => "ethernet %s"
21
+ })[device.name[0..1]])
22
+ throw "device not expandable #{device.name}" unless pattern
23
+ pattern%device.name[2..-1]
24
+ end
25
+
26
+ def add_host(host)
27
+ @result.add("hostname", Ciscian::SingleValueVerb).add(@result.host.name)
28
+ @result.add("max-vlans", Ciscian::SingleValueVerb).add(64)
29
+ @result.add("snmp-server community \"public\" Unrestricted", Ciscian::SingleValueVerb)
30
+ @result.host.interfaces.values.each do |iface|
31
+ next unless iface.delegate.address
32
+ iface.delegate.address.routes.each do |route|
33
+ @result.add("ip route #{route.dst.to_s} #{route.dst.netmask} #{route.via.to_s}", Ciscian::SingleValueVerb)
34
+ end
35
+ end
36
+ end
37
+
38
+ def add_device(device)
39
+ end
40
+
41
+ def add_bond(bond)
42
+ throw "not implemented yet"
43
+ end
44
+
45
+ def add_vlan(vlan)
46
+ @result.add("vlan #{vlan.delegate.vlan_id}") do |section|
47
+ next unless vlan.delegate.description && !vlan.delegate.description.empty?
48
+ throw "vlan name too long, max 32 chars" if vlan.delegate.description.length > 32
49
+ section.add("name", Ciscian::SingleValueVerb).add(vlan.delegate.description)
50
+
51
+
52
+ vlan.interfaces.each do |port|
53
+ section.add({
54
+ true => "tagged",
55
+ false => "untagged"
56
+ }[port.template.is_tagged?(vlan.vlan_id)], Ciscian::RangeVerb).add(port.delegate.number)
57
+ end
58
+
59
+ if vlan.delegate.address
60
+ if vlan.delegate.address.first_ipv4
61
+ section.add("ip address").add(vlan.delegate.address.first_ipv4.to_string)
62
+ elsif vlan.delegate.address.dhcpv4?
63
+ section.add("ip address").add("dhcp-bootp")
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ def parse_line(line, lines, section, result)
70
+ [TrunkVerb, Tagged
71
+ ].find do |i|
72
+ i.parse_line(line, lines, section, result)
73
+ end
74
+ end
75
+
76
+ def clear_interface(line)
77
+ line.to_s.split(/\s+/).map do |i|
78
+ split = /^([^0-9]+)([0-9].*)$/.match(i)
79
+ split ? split[1..-1] : i
80
+ end.flatten.join(' ')
81
+ end
82
+
83
+ def block_end?(line)
84
+ ['end','exit'].include?(line.strip)
85
+ end
86
+
87
+
88
+ class Tagged < PatternBasedVerb
89
+ def self.section
90
+ "tagged"
91
+ end
92
+
93
+ def self.patterns
94
+ ["tagged {+ports}", "no tagged {-ports}", "untagged {+uports}", "no untagged {-uports}"]
95
+ end
96
+ end
97
+
98
+ class TrunkVerb < PatternBasedVerb
99
+ def self.section
100
+ "trunk"
101
+ end
102
+
103
+ def self.patterns
104
+ ["no trunk {-ports}", "trunk {+ports} Trk{*channel} Trunk"]
105
+ end
106
+ end
107
+
108
+
109
+ end
110
+
111
+ Construqt::Flavour::Ciscian.add_dialect(Hp2510g)
112
+ end
113
+ end
114
+ end