construqt 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/construqt/addresses.rb +204 -0
- data/lib/construqt/bgps.rb +164 -0
- data/lib/construqt/cables.rb +47 -0
- data/lib/construqt/firewalls.rb +247 -0
- data/lib/construqt/flavour/ciscian/ciscian.rb +687 -0
- data/lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb +235 -0
- data/lib/construqt/flavour/ciscian/dialect_hp-2510g.rb +114 -0
- data/lib/construqt/flavour/delegates.rb +448 -0
- data/lib/construqt/flavour/flavour.rb +97 -0
- data/lib/construqt/flavour/mikrotik/flavour_mikrotik.rb +417 -0
- data/lib/construqt/flavour/mikrotik/flavour_mikrotik_bgp.rb +134 -0
- data/lib/construqt/flavour/mikrotik/flavour_mikrotik_interface.rb +79 -0
- data/lib/construqt/flavour/mikrotik/flavour_mikrotik_ipsec.rb +65 -0
- data/lib/construqt/flavour/mikrotik/flavour_mikrotik_result.rb +182 -0
- data/lib/construqt/flavour/mikrotik/flavour_mikrotik_schema.rb +355 -0
- data/lib/construqt/flavour/plantuml/plantuml.rb +462 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu.rb +381 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_bgp.rb +117 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_dns.rb +97 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_firewall.rb +300 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_ipsec.rb +144 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_opvn.rb +60 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb +537 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb +115 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb +52 -0
- data/lib/construqt/flavour/unknown/unknown.rb +175 -0
- data/lib/construqt/hostid.rb +42 -0
- data/lib/construqt/hosts.rb +98 -0
- data/lib/construqt/interfaces.rb +166 -0
- data/lib/construqt/ipsecs.rb +64 -0
- data/lib/construqt/networks.rb +81 -0
- data/lib/construqt/regions.rb +32 -0
- data/lib/construqt/resource.rb +42 -0
- data/lib/construqt/services.rb +53 -0
- data/lib/construqt/tags.rb +61 -0
- data/lib/construqt/templates.rb +37 -0
- data/lib/construqt/tests/test_addresses.rb +50 -0
- data/lib/construqt/tests/test_bgps.rb +24 -0
- data/lib/construqt/tests/test_hostid.rb +32 -0
- data/lib/construqt/tests/test_hosts.rb +23 -0
- data/lib/construqt/tests/test_utils.rb +76 -0
- data/lib/construqt/users.rb +19 -0
- data/lib/construqt/util.rb +163 -0
- data/lib/construqt/version.rb +3 -0
- data/lib/construqt/vlans.rb +51 -0
- data/lib/construqt.rb +92 -0
- metadata +105 -0
@@ -0,0 +1,448 @@
|
|
1
|
+
|
2
|
+
module Construqt
|
3
|
+
module Flavour
|
4
|
+
module Delegate
|
5
|
+
def delegate
|
6
|
+
throw "you need a delegate #{self.class.name}" unless @delegate
|
7
|
+
@delegate
|
8
|
+
end
|
9
|
+
|
10
|
+
def delegate=(a)
|
11
|
+
throw "delegate needs to be !nil" unless a
|
12
|
+
@delegate = a
|
13
|
+
end
|
14
|
+
|
15
|
+
def tags
|
16
|
+
@tags || []
|
17
|
+
end
|
18
|
+
|
19
|
+
def tags=(tags)
|
20
|
+
@tags = tags
|
21
|
+
end
|
22
|
+
|
23
|
+
def description
|
24
|
+
self.delegate.description
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_name
|
28
|
+
self.delegate.default_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
self.delegate.name
|
33
|
+
end
|
34
|
+
|
35
|
+
def address
|
36
|
+
self.delegate.address
|
37
|
+
end
|
38
|
+
|
39
|
+
def template
|
40
|
+
self.delegate.template
|
41
|
+
end
|
42
|
+
|
43
|
+
def host
|
44
|
+
self.delegate.host
|
45
|
+
end
|
46
|
+
|
47
|
+
def priority
|
48
|
+
self.delegate.priority
|
49
|
+
end
|
50
|
+
|
51
|
+
def clazz
|
52
|
+
#binding.pry
|
53
|
+
self.delegate.clazz
|
54
|
+
end
|
55
|
+
|
56
|
+
def cable=(a)
|
57
|
+
self.delegate.cable = a
|
58
|
+
end
|
59
|
+
|
60
|
+
def cable
|
61
|
+
self.delegate.cable
|
62
|
+
end
|
63
|
+
|
64
|
+
def simple_name
|
65
|
+
self.class.name[self.class.name.rindex(':')+1..-1]
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_config(host, my)
|
69
|
+
# binding.pry if host && host.name == "ct-iar1-ham"
|
70
|
+
# binding.pry if self.class.name[self.class.name.rindex(':')+1..-1] == "DeviceDelegate"
|
71
|
+
#binding.pry
|
72
|
+
Flavour.call_aspects("#{simple_name}.build_config", host, my||self)
|
73
|
+
self.delegate.build_config(host, my||self)
|
74
|
+
end
|
75
|
+
|
76
|
+
def ident
|
77
|
+
self._ident.gsub(/[^0-9a-zA-Z_]/, '_')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class OpvnDelegate
|
82
|
+
include Delegate
|
83
|
+
def initialize(opvn)
|
84
|
+
self.delegate = opvn
|
85
|
+
end
|
86
|
+
|
87
|
+
def _ident
|
88
|
+
"Opvn_#{self.host.name}_#{self.name}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def network
|
92
|
+
self.delegate.network
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class GreDelegate
|
97
|
+
include Delegate
|
98
|
+
def initialize(gre)
|
99
|
+
self.delegate = gre
|
100
|
+
end
|
101
|
+
|
102
|
+
def _ident
|
103
|
+
"Gre_#{self.host.name}_#{self.name}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class HostDelegate
|
108
|
+
include Delegate
|
109
|
+
def initialize(host)
|
110
|
+
#binding.pry
|
111
|
+
#Construqt.logger.debug "HostDelegate.new(#{host.name})"
|
112
|
+
self.delegate = host
|
113
|
+
|
114
|
+
@users = host.users || host.region.users
|
115
|
+
end
|
116
|
+
|
117
|
+
def _ident
|
118
|
+
#binding.pry
|
119
|
+
"Host_#{self.name}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def region
|
123
|
+
self.delegate.region
|
124
|
+
end
|
125
|
+
|
126
|
+
def result
|
127
|
+
self.delegate.result
|
128
|
+
end
|
129
|
+
|
130
|
+
def flavour
|
131
|
+
self.delegate.flavour
|
132
|
+
end
|
133
|
+
|
134
|
+
def interfaces
|
135
|
+
self.delegate.interfaces
|
136
|
+
end
|
137
|
+
|
138
|
+
def id=(id)
|
139
|
+
self.delegate.id = id
|
140
|
+
end
|
141
|
+
|
142
|
+
def id
|
143
|
+
self.delegate.id
|
144
|
+
end
|
145
|
+
|
146
|
+
def configip=(id)
|
147
|
+
self.delegate.configip = id
|
148
|
+
end
|
149
|
+
|
150
|
+
def configip
|
151
|
+
self.delegate.configip
|
152
|
+
end
|
153
|
+
|
154
|
+
def users
|
155
|
+
@users
|
156
|
+
end
|
157
|
+
|
158
|
+
def commit
|
159
|
+
#header_clazzes = {:host => self } # host class need also a header call
|
160
|
+
#footer_clazzes = {:host => self } # host class need also a header call
|
161
|
+
#self.interfaces.values.each do |iface|
|
162
|
+
# header_clazzes[iface.class.name] ||= iface if iface.delegate.respond_to? :header
|
163
|
+
# footer_clazzes[iface.class.name] ||= iface if iface.delegate.respond_to? :footer
|
164
|
+
#end
|
165
|
+
#binding.pry
|
166
|
+
self.flavour.pre_clazzes do |key, clazz|
|
167
|
+
Flavour.call_aspects("#{key}.header", self, nil)
|
168
|
+
clazz.header(self) if clazz.respond_to? :header
|
169
|
+
end
|
170
|
+
Flavour.call_aspects("host.commit", self, nil)
|
171
|
+
self.result.commit
|
172
|
+
|
173
|
+
self.flavour.pre_clazzes do |key, clazz|
|
174
|
+
Flavour.call_aspects("#{key}.footer", self, nil)
|
175
|
+
clazz.footer(self) if clazz.respond_to? :footer
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
class DeviceDelegate
|
181
|
+
include Delegate
|
182
|
+
def initialize(device)
|
183
|
+
self.delegate = device
|
184
|
+
end
|
185
|
+
|
186
|
+
def _ident
|
187
|
+
#binding.pry
|
188
|
+
#Construqt.logger.debug "DeviceDelegate::_ident:#{attached.delegate.name}"
|
189
|
+
"Device_#{delegate.host.name}_#{self.name}"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
class VrrpDelegate
|
194
|
+
include Delegate
|
195
|
+
def initialize(vrrp)
|
196
|
+
#binding.pry
|
197
|
+
self.delegate = vrrp
|
198
|
+
end
|
199
|
+
|
200
|
+
def _ident
|
201
|
+
"Vrrp_#{self.name}_#{self.delegate.interfaces.map{|i| "#{i.host.name}_#{i.name}"}.join("_")}"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class BridgeDelegate
|
206
|
+
include Delegate
|
207
|
+
def initialize(bridge)
|
208
|
+
self.delegate = bridge
|
209
|
+
end
|
210
|
+
|
211
|
+
def _ident
|
212
|
+
"Bridge_#{self.host.name}_#{self.name}"
|
213
|
+
end
|
214
|
+
|
215
|
+
def interfaces
|
216
|
+
self.delegate.interfaces
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class BondDelegate
|
221
|
+
include Delegate
|
222
|
+
def initialize(bond)
|
223
|
+
self.delegate = bond
|
224
|
+
end
|
225
|
+
|
226
|
+
def _ident
|
227
|
+
"Bond_#{self.host.name}_#{self.name}"
|
228
|
+
end
|
229
|
+
|
230
|
+
def interfaces
|
231
|
+
self.delegate.interfaces
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
class VlanDelegate
|
236
|
+
include Delegate
|
237
|
+
def initialize(vlan)
|
238
|
+
self.delegate = vlan
|
239
|
+
end
|
240
|
+
|
241
|
+
def interfaces
|
242
|
+
self.delegate.interfaces
|
243
|
+
end
|
244
|
+
|
245
|
+
def vlan_id
|
246
|
+
self.delegate.vlan_id
|
247
|
+
end
|
248
|
+
|
249
|
+
def _ident
|
250
|
+
"Vlan_#{self.host.name}_#{self.name}"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
class TemplateDelegate
|
255
|
+
include Delegate
|
256
|
+
def initialize(template)
|
257
|
+
self.delegate = template
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
class InterfaceDelegate
|
262
|
+
include Delegate
|
263
|
+
def initialize(interface)
|
264
|
+
self.delegate = interface
|
265
|
+
end
|
266
|
+
|
267
|
+
def clazz
|
268
|
+
self.delegate.clazz
|
269
|
+
end
|
270
|
+
|
271
|
+
def _ident
|
272
|
+
self.clazz.ident
|
273
|
+
# "#{self.delegate.clazz.name}_#{self.name}"
|
274
|
+
end
|
275
|
+
|
276
|
+
def name
|
277
|
+
self.delegate.name
|
278
|
+
end
|
279
|
+
|
280
|
+
def address
|
281
|
+
self.delegate.address
|
282
|
+
end
|
283
|
+
|
284
|
+
def priority
|
285
|
+
self.delegate.priority
|
286
|
+
end
|
287
|
+
|
288
|
+
def host
|
289
|
+
self.delegate.host
|
290
|
+
end
|
291
|
+
|
292
|
+
def network
|
293
|
+
self.delegate.network
|
294
|
+
end
|
295
|
+
|
296
|
+
def cable
|
297
|
+
self.delegate.cable
|
298
|
+
end
|
299
|
+
|
300
|
+
def cable=(a)
|
301
|
+
self.delegate.cable = a
|
302
|
+
end
|
303
|
+
|
304
|
+
def template
|
305
|
+
self.delegate.template
|
306
|
+
end
|
307
|
+
|
308
|
+
def interfaces
|
309
|
+
self.delegate.interfaces
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
class IpsecDelegate
|
314
|
+
include Delegate
|
315
|
+
def initialize(ipsec)
|
316
|
+
self.delegate = ipsec
|
317
|
+
end
|
318
|
+
|
319
|
+
def host
|
320
|
+
self.delegate.host
|
321
|
+
end
|
322
|
+
|
323
|
+
def my
|
324
|
+
self.delegate.my
|
325
|
+
end
|
326
|
+
|
327
|
+
def remote
|
328
|
+
self.delegate.remote
|
329
|
+
end
|
330
|
+
|
331
|
+
def other=(a)
|
332
|
+
self.delegate.other = a
|
333
|
+
end
|
334
|
+
|
335
|
+
def other
|
336
|
+
self.delegate.other
|
337
|
+
end
|
338
|
+
|
339
|
+
def cfg=(a)
|
340
|
+
self.delegate.cfg = a
|
341
|
+
end
|
342
|
+
|
343
|
+
def cfg
|
344
|
+
self.delegate.cfg
|
345
|
+
end
|
346
|
+
|
347
|
+
def interface=(a)
|
348
|
+
self.delegate.interface = a
|
349
|
+
end
|
350
|
+
|
351
|
+
def interface
|
352
|
+
self.delegate.interface
|
353
|
+
end
|
354
|
+
|
355
|
+
def _ident
|
356
|
+
"Ipsec_#{cfg.left.interface.name}_#{cfg.right.interface.name}"
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
class BgpDelegate
|
361
|
+
include Delegate
|
362
|
+
def initialize(bgp)
|
363
|
+
self.delegate = bgp
|
364
|
+
end
|
365
|
+
|
366
|
+
def once(host)
|
367
|
+
self.delegate.once(host)
|
368
|
+
end
|
369
|
+
|
370
|
+
def as
|
371
|
+
self.delegate.as
|
372
|
+
end
|
373
|
+
|
374
|
+
def my
|
375
|
+
self.delegate.my
|
376
|
+
end
|
377
|
+
|
378
|
+
def host
|
379
|
+
self.delegate.host
|
380
|
+
end
|
381
|
+
|
382
|
+
def other=(a)
|
383
|
+
self.delegate.other = a
|
384
|
+
end
|
385
|
+
|
386
|
+
def other
|
387
|
+
self.delegate.other
|
388
|
+
end
|
389
|
+
|
390
|
+
def cfg=(a)
|
391
|
+
self.delegate.cfg = a
|
392
|
+
end
|
393
|
+
|
394
|
+
def cfg
|
395
|
+
self.delegate.cfg
|
396
|
+
end
|
397
|
+
|
398
|
+
def _ident
|
399
|
+
"Bgp_#{cfg.left.host.name}_#{cfg.left.my.name}_#{cfg.right.host.name}_#{cfg.right.my.name}"
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
# class ResultDelegate
|
404
|
+
# include Delegate
|
405
|
+
# def initialize(result)
|
406
|
+
# self.delegate = result
|
407
|
+
# end
|
408
|
+
#
|
409
|
+
# class Result
|
410
|
+
# include Delegate
|
411
|
+
# def initialize(result)
|
412
|
+
# #puts "Result=>#{self.class.name} #{result}"
|
413
|
+
# self.delegate = result
|
414
|
+
# end
|
415
|
+
#
|
416
|
+
# def add(*args)
|
417
|
+
# delegate.add(*args)
|
418
|
+
# end
|
419
|
+
#
|
420
|
+
# # def commit
|
421
|
+
# # Flavour.call_aspects("#{key}.header", host, nil)
|
422
|
+
# # clazz.header(host)
|
423
|
+
#
|
424
|
+
# # binding.pry
|
425
|
+
# # delegate.commit
|
426
|
+
# # host = delegate.host
|
427
|
+
# # clazzes = {}
|
428
|
+
# # host.flavour.pre_clazzes { |key, clazz| clazzes[key] = host.flavour.clazz(key) }
|
429
|
+
# # clazzes.each do |key, clazz|
|
430
|
+
# # Flavour.call_aspects("#{key}.header", host, nil)
|
431
|
+
# # clazz.header(host)
|
432
|
+
# # end
|
433
|
+
#
|
434
|
+
# # Flavour.call_aspects("result.commit", nil, delegate)
|
435
|
+
# # delegate.commit
|
436
|
+
# # clazzes.each do |key, clazz|
|
437
|
+
# # Flavour.call_aspects("#{key}.footer", host, nil)
|
438
|
+
# # clazz.footer(host)
|
439
|
+
# # end
|
440
|
+
# # end
|
441
|
+
# end
|
442
|
+
#
|
443
|
+
# def create(host)
|
444
|
+
# Result.new(self.delegate.new(host))
|
445
|
+
# end
|
446
|
+
# end
|
447
|
+
end
|
448
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
module Construqt
|
3
|
+
module Flavour
|
4
|
+
|
5
|
+
@flavours = {}
|
6
|
+
|
7
|
+
class FlavourDelegate
|
8
|
+
attr_reader :flavour
|
9
|
+
def initialize(flavour)
|
10
|
+
@flavour = flavour
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@flavour.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def clazzes
|
18
|
+
ret = {
|
19
|
+
"opvn" => OpvnDelegate,
|
20
|
+
"gre" => GreDelegate,
|
21
|
+
"host" => HostDelegate,
|
22
|
+
"device"=> DeviceDelegate,
|
23
|
+
"vrrp" => VrrpDelegate,
|
24
|
+
"bridge" => BridgeDelegate,
|
25
|
+
"bond" => BondDelegate,
|
26
|
+
"vlan" => VlanDelegate,
|
27
|
+
#"result" => ResultDelegate,
|
28
|
+
"template" => TemplateDelegate
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def pre_clazzes(&block)
|
33
|
+
@flavour.clazzes.each do |key, clazz|
|
34
|
+
block.call(key, clazz)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# def clazz(name)
|
39
|
+
# delegate = self.clazzes[name]
|
40
|
+
# throw "class not found #{name}" unless delegate
|
41
|
+
# flavour = @flavour.clazz(name)
|
42
|
+
# throw "class not found #{name}" unless flavour
|
43
|
+
# delegate.new(flavour)
|
44
|
+
# end
|
45
|
+
|
46
|
+
def create_host(name, cfg)
|
47
|
+
HostDelegate.new(@flavour.create_host(name, cfg))
|
48
|
+
end
|
49
|
+
|
50
|
+
# def create_result(name, cfg)
|
51
|
+
# HostDelegate.new(@flavour.create_host(name, cfg))
|
52
|
+
# end
|
53
|
+
|
54
|
+
def create_interface(dev_name, cfg)
|
55
|
+
clazzes[cfg['clazz']].new(@flavour.create_interface(dev_name, cfg))
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_bgp(cfg)
|
59
|
+
BgpDelegate.new(@flavour.create_bgp(cfg))
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_ipsec(cfg)
|
63
|
+
IpsecDelegate.new(@flavour.create_ipsec(cfg))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.add(flavour)
|
68
|
+
Construqt.logger.info "setup flavour #{flavour.name}"
|
69
|
+
@flavours[flavour.name.downcase] = FlavourDelegate.new(flavour)
|
70
|
+
end
|
71
|
+
|
72
|
+
@aspects = []
|
73
|
+
def self.add_aspect(aspect)
|
74
|
+
Construqt.logger.info "setup aspect #{aspect.name}"
|
75
|
+
@aspects << aspect
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.del_aspect(aspect)
|
79
|
+
@aspects = @aspects.select{|a| a.name != aspect }
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.call_aspects(type, *args)
|
83
|
+
@aspects.each { |aspect| aspect.call(type, *args) }
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.find(name)
|
87
|
+
ret = @flavours[name.downcase]
|
88
|
+
throw "flavour #{name} not found" unless ret
|
89
|
+
ret
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.parser(flavour, dialect, prefix = nil)
|
93
|
+
@flavours[flavour].flavour::Result.new(OpenStruct.new(:dialect => dialect, :fname => prefix, :interfaces => {}))
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|