construqt 0.0.4 → 0.0.5
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 +4 -4
- data/lib/construqt/flavour/ciscian/ciscian.rb +57 -5
- data/lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb +141 -3
- data/lib/construqt/flavour/ciscian/dialect_hp-2510g.rb +11 -12
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu.rb +1 -0
- data/lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb +3 -0
- data/lib/construqt/networks.rb +1 -1
- data/lib/construqt/resource.rb +10 -0
- data/lib/construqt/reverse.rb +43 -0
- data/lib/construqt/util.rb +3 -0
- data/lib/construqt/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2115258ebfdfcd8677388f8d16094791d24c8f73
|
4
|
+
data.tar.gz: 2a0e2a30f18d8c0cca7f8f15db806685e60e517b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc4dcecb64df68474a1a3475bb39202ba60e1cb02c3ac60607ce85afba3fd9b6d85a4b841ce8325d353a55f8ba592a90a14d150cbe62349c17bb0823cbf95a4
|
7
|
+
data.tar.gz: f0bb62e3236746fd6cccd2333ba213524c86d6fb8169c1371b83175d53704c1337e45f1611acc81cf54ff084e643aebc5fb7269b0460ee98358462f81ff96622
|
@@ -34,6 +34,7 @@ module Construqt
|
|
34
34
|
@to_s = str
|
35
35
|
@nr = nr
|
36
36
|
end
|
37
|
+
|
37
38
|
def <=>(other)
|
38
39
|
a = self.to_s
|
39
40
|
b = other.to_s
|
@@ -44,27 +45,33 @@ module Construqt
|
|
44
45
|
ret = match_a[2].to_i<=>match_b[2].to_i if ret==0
|
45
46
|
ret
|
46
47
|
end
|
48
|
+
|
47
49
|
# def hash
|
48
50
|
# self.to_s.hash
|
49
51
|
# end
|
50
52
|
end
|
53
|
+
|
51
54
|
def initialize(lines)
|
52
55
|
@lines = []
|
53
56
|
lines.each_with_index do |line, idx|
|
54
57
|
@lines << Line.new(line.strip, idx)
|
55
58
|
end
|
59
|
+
|
56
60
|
@pos = 0
|
57
61
|
end
|
62
|
+
|
58
63
|
def shift
|
59
64
|
@pos += 1
|
60
65
|
@lines[@pos-1]
|
61
66
|
end
|
62
67
|
end
|
68
|
+
|
63
69
|
def parse(lines)
|
64
70
|
lines = Lines.new(lines)
|
65
71
|
while line = lines.shift
|
66
72
|
parse_line(line, lines, self, self)
|
67
73
|
end
|
74
|
+
|
68
75
|
self
|
69
76
|
end
|
70
77
|
|
@@ -92,6 +99,7 @@ module Construqt
|
|
92
99
|
section = @sections[key]
|
93
100
|
block += section.serialize
|
94
101
|
end
|
102
|
+
|
95
103
|
Util.write_str(block.join("\n"), File.join(@host.name, "#{@host.fname||self.dialect.class.name}.cfg"))
|
96
104
|
end
|
97
105
|
|
@@ -103,7 +111,10 @@ module Construqt
|
|
103
111
|
@sections[section_key] ||= clazz.new(section_key)
|
104
112
|
if Result.starts_with_no(section.to_s)
|
105
113
|
@sections[section_key].no
|
114
|
+
else
|
115
|
+
@sections[section_key].yes
|
106
116
|
end
|
117
|
+
|
107
118
|
yield(@sections[section_key]) if block_given?
|
108
119
|
@sections[section_key]
|
109
120
|
end
|
@@ -150,6 +161,11 @@ module Construqt
|
|
150
161
|
self
|
151
162
|
end
|
152
163
|
|
164
|
+
def yes
|
165
|
+
@no=nil
|
166
|
+
self
|
167
|
+
end
|
168
|
+
|
153
169
|
def self.parse_line(line, lines, section, result)
|
154
170
|
regexp = line.to_s.strip.end_with?("\"") ? /^(.*) (\"[^"]+\")$/ : /^(.*) ([^\s"]+)$/
|
155
171
|
if (line.to_s.strip =~ regexp)
|
@@ -172,6 +188,7 @@ module Construqt
|
|
172
188
|
# clazz=verb
|
173
189
|
# verb=clazz.section_key
|
174
190
|
# end
|
191
|
+
|
175
192
|
self.sections[Result.normalize_section_key(verb.to_s)] ||= clazz.new(verb)
|
176
193
|
end
|
177
194
|
|
@@ -197,6 +214,7 @@ module Construqt
|
|
197
214
|
end
|
198
215
|
end
|
199
216
|
end
|
217
|
+
|
200
218
|
return true
|
201
219
|
end
|
202
220
|
end
|
@@ -207,6 +225,7 @@ module Construqt
|
|
207
225
|
verb = sections[key]
|
208
226
|
block << verb.serialize.map{|i| " #{i}"}
|
209
227
|
end
|
228
|
+
|
210
229
|
block
|
211
230
|
end
|
212
231
|
|
@@ -220,6 +239,11 @@ module Construqt
|
|
220
239
|
@no
|
221
240
|
end
|
222
241
|
|
242
|
+
def yes
|
243
|
+
@no=nil
|
244
|
+
self
|
245
|
+
end
|
246
|
+
|
223
247
|
def serialize
|
224
248
|
block=[]
|
225
249
|
block << "#{@no}#{section.to_s}"
|
@@ -227,6 +251,7 @@ module Construqt
|
|
227
251
|
block += render_verbs(self.sections)
|
228
252
|
block << "exit"
|
229
253
|
end
|
254
|
+
|
230
255
|
block
|
231
256
|
end
|
232
257
|
|
@@ -250,6 +275,7 @@ module Construqt
|
|
250
275
|
delta.sections[comp.section] = comp
|
251
276
|
end
|
252
277
|
end
|
278
|
+
|
253
279
|
return [delta]
|
254
280
|
end
|
255
281
|
end
|
@@ -273,6 +299,11 @@ module Construqt
|
|
273
299
|
self
|
274
300
|
end
|
275
301
|
|
302
|
+
def yes
|
303
|
+
@no=nil
|
304
|
+
self
|
305
|
+
end
|
306
|
+
|
276
307
|
def serialize
|
277
308
|
if @no
|
278
309
|
["#{@no}#{section}"]
|
@@ -301,8 +332,8 @@ module Construqt
|
|
301
332
|
end
|
302
333
|
|
303
334
|
def add(value)
|
304
|
-
throw "must be a number \'#{value}\'" unless /^\d+$/.match(value.to_s)
|
305
|
-
self.values << value
|
335
|
+
#throw "must be a number \'#{value}\'" unless /^\d+$/.match(value.to_s)
|
336
|
+
self.values << value #.to_i
|
306
337
|
self
|
307
338
|
end
|
308
339
|
|
@@ -311,6 +342,11 @@ module Construqt
|
|
311
342
|
self
|
312
343
|
end
|
313
344
|
|
345
|
+
def yes
|
346
|
+
@no=nil
|
347
|
+
self
|
348
|
+
end
|
349
|
+
|
314
350
|
def self.compare(nu, old)
|
315
351
|
return [nu] unless old
|
316
352
|
return [old.no] unless nu
|
@@ -339,6 +375,9 @@ module Construqt
|
|
339
375
|
self.changes=[]
|
340
376
|
end
|
341
377
|
|
378
|
+
def yes
|
379
|
+
end
|
380
|
+
|
342
381
|
def add(entry)
|
343
382
|
changes << entry
|
344
383
|
self
|
@@ -355,6 +394,7 @@ module Construqt
|
|
355
394
|
patterns.each do |pattern|
|
356
395
|
variables+=find_variables(pattern)
|
357
396
|
end
|
397
|
+
|
358
398
|
return variables
|
359
399
|
end
|
360
400
|
|
@@ -388,6 +428,7 @@ module Construqt
|
|
388
428
|
var_regex = "#{Construqt::Util::PORTS_DEF_REGEXP}" unless var_regex
|
389
429
|
regex=regex.gsub(var, var_regex)
|
390
430
|
end
|
431
|
+
|
391
432
|
regex=regex.gsub(" ", "\\s+")
|
392
433
|
regex="^"+regex+"$"
|
393
434
|
if (matchdata=line.match(regex))
|
@@ -399,9 +440,11 @@ module Construqt
|
|
399
440
|
values[variables[i-1]]=[matchdata[i]]
|
400
441
|
end
|
401
442
|
end
|
443
|
+
|
402
444
|
return values
|
403
445
|
end
|
404
446
|
end
|
447
|
+
|
405
448
|
return false
|
406
449
|
end
|
407
450
|
|
@@ -453,6 +496,7 @@ module Construqt
|
|
453
496
|
end
|
454
497
|
end
|
455
498
|
end
|
499
|
+
|
456
500
|
return key_var
|
457
501
|
end
|
458
502
|
|
@@ -533,6 +577,7 @@ module Construqt
|
|
533
577
|
end
|
534
578
|
end
|
535
579
|
end
|
580
|
+
|
536
581
|
output_patterns << empty_pattern if output_patterns.empty? && !empty_pattern.nil?
|
537
582
|
return output_patterns
|
538
583
|
end
|
@@ -550,14 +595,18 @@ module Construqt
|
|
550
595
|
sets.each do |key_val,value_sets|
|
551
596
|
determine_output_patterns(value_sets).each do |pattern|
|
552
597
|
index = 0
|
553
|
-
i=0
|
598
|
+
i = 0
|
554
599
|
begin
|
555
600
|
substitution=false
|
556
601
|
result = pattern
|
557
|
-
i+=1
|
602
|
+
i += 1
|
558
603
|
self.class.find_variables(pattern).each do |v|
|
559
604
|
if (group)
|
560
|
-
|
605
|
+
if self.class.is_value?(v) || self.class.is_key_value?(v)
|
606
|
+
result = result.gsub(v, value_sets[v].to_s) unless value_sets[v].nil? || value_sets[v].to_s.empty?
|
607
|
+
else
|
608
|
+
result = result.gsub(v, Construqt::Util.createRangeDefinition(value_sets[v])) unless value_sets[v].nil? || value_sets[v].empty?
|
609
|
+
end
|
561
610
|
else
|
562
611
|
if (index < value_sets[v].length)
|
563
612
|
result = result.gsub(v, value_sets[v][index])
|
@@ -565,11 +614,13 @@ module Construqt
|
|
565
614
|
end
|
566
615
|
end
|
567
616
|
end
|
617
|
+
|
568
618
|
buffer << result if self.class.find_variables(result).empty?
|
569
619
|
index+=1
|
570
620
|
end while substitution
|
571
621
|
end
|
572
622
|
end
|
623
|
+
|
573
624
|
return buffer
|
574
625
|
end
|
575
626
|
end
|
@@ -582,6 +633,7 @@ module Construqt
|
|
582
633
|
def header(host)
|
583
634
|
"# this is a generated file do not edit!!!!!"
|
584
635
|
end
|
636
|
+
|
585
637
|
def footer(host)
|
586
638
|
"# this is a generated file do not edit!!!!!"
|
587
639
|
end
|
@@ -3,6 +3,8 @@ module Construqt
|
|
3
3
|
module Ciscian
|
4
4
|
module DlinkDgs15xx
|
5
5
|
|
6
|
+
|
7
|
+
|
6
8
|
class HostNameVerb < PatternBasedVerb
|
7
9
|
def self.section
|
8
10
|
"snmp-server name"
|
@@ -55,6 +57,44 @@ module Construqt
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
60
|
+
class EnablePasswordVerb < SingleValueVerb
|
61
|
+
def self.section
|
62
|
+
"enable password level"
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.patterns
|
66
|
+
["no channel-group", "enable password level {+admin} {+level} {+pw_hash}"]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class UserNamePasswordVerb < SingleValueVerb
|
71
|
+
def self.section
|
72
|
+
"user XXXXX password"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.patterns
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class UserNamePrivilegeVerb < SingleValueVerb
|
80
|
+
def self.section
|
81
|
+
"user XXXX privilege"
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.patterns
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class PasswordVerb < SingleValueVerb
|
89
|
+
def self.section
|
90
|
+
"password"
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.patterns
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
58
98
|
class Ipv4RouteVerb < PatternBasedVerb
|
59
99
|
def self.section
|
60
100
|
"ip route"
|
@@ -167,6 +207,105 @@ module Construqt
|
|
167
207
|
end
|
168
208
|
|
169
209
|
def commit
|
210
|
+
[
|
211
|
+
"aaa",
|
212
|
+
"service password-encryption",
|
213
|
+
"no ip http server",
|
214
|
+
"debug reboot on-error",
|
215
|
+
"no debug enable"
|
216
|
+
].each do |verb|
|
217
|
+
@result.add(verb, Ciscian::SingleValueVerb)
|
218
|
+
end
|
219
|
+
|
220
|
+
["line console", "line telnet", "line ssh"].each do |section|
|
221
|
+
@result.add(section) { |_section| _section.add("line") }
|
222
|
+
end
|
223
|
+
|
224
|
+
#@result.host.interfaces.values.each do |iface|
|
225
|
+
# @result.add(k
|
226
|
+
#end
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
# "enable password level 15 7 <>"
|
232
|
+
# "username root password 7 <>"
|
233
|
+
# "username root password 15"
|
234
|
+
#
|
235
|
+
# "autoconfig",
|
236
|
+
# ["clock timezone", "+ 1"],
|
237
|
+
# "no clock summer-time"
|
238
|
+
# "sntp interval 720"
|
239
|
+
# "ddp report-timer 30",
|
240
|
+
# "debug"
|
241
|
+
# "debug reboot"
|
242
|
+
# "dim"
|
243
|
+
# "ignore"
|
244
|
+
# "instance 16 vlans"
|
245
|
+
# no power-saving link-detection
|
246
|
+
# no dim led
|
247
|
+
# no power-saving hibernation
|
248
|
+
# no power-saving dim-led
|
249
|
+
# no power-saving port-shutdown
|
250
|
+
#
|
251
|
+
#
|
252
|
+
# "ddp"
|
253
|
+
# "no power-saving eee"
|
254
|
+
# "no snmp-server trap-sending"
|
255
|
+
# "no speed"
|
256
|
+
# "spanning-tree guard"
|
257
|
+
# "spanning-tree mst hello-time"
|
258
|
+
#
|
259
|
+
#
|
260
|
+
# "ip arp gratuitous"
|
261
|
+
# "ip dhcp relay information option format circuit-id default"
|
262
|
+
# "ip dhcp relay information option format remote-id default"
|
263
|
+
# "ip dhcp relay information policy replace"
|
264
|
+
# "ip domain"
|
265
|
+
# "ip http service-port"
|
266
|
+
# "ip http timeout-policy idle"
|
267
|
+
# "ip ssh"
|
268
|
+
# "ip telnet"
|
269
|
+
# "ip telnet service-port"
|
270
|
+
# "port-channel load-balance"
|
271
|
+
# "power-saving"
|
272
|
+
# "service"
|
273
|
+
#
|
274
|
+
# "snmp-server community private view CommunityView"
|
275
|
+
# "snmp-server community public view CommunityView"
|
276
|
+
# "snmp-server contact"
|
277
|
+
# "snmp-server enable traps rmon falling-alarm"
|
278
|
+
# "snmp-server enable traps snmp rising-alarm"
|
279
|
+
# "snmp-server engineID local"
|
280
|
+
# "snmp-server group initial"
|
281
|
+
# "snmp-server group initial v3 noauth read restricted notify"
|
282
|
+
# "snmp-server group private v1 read CommunityView write CommunityView notify"
|
283
|
+
# "snmp-server group private v2c read CommunityView write CommunityView notify"
|
284
|
+
# "snmp-server group public v1 read CommunityView notify"
|
285
|
+
# "snmp-server group public v2c read CommunityView notify"
|
286
|
+
# "snmp-server location"
|
287
|
+
# "snmp-server response"
|
288
|
+
# "snmp-server service-port"
|
289
|
+
# "snmp-server user initial"
|
290
|
+
# "snmp-server user initial initial"
|
291
|
+
# "snmp-server view CommunityView 1"
|
292
|
+
# "snmp-server view CommunityView 1.3.6.1.6.3"
|
293
|
+
# "snmp-server view CommunityView 1.3.6.1.6.3.1"
|
294
|
+
# "snmp-server view restricted 1.3.6.1.2.1.1"
|
295
|
+
# "snmp-server view restricted 1.3.6.1.2.1.11"
|
296
|
+
# "snmp-server view restricted 1.3.6.1.6.3.10.2.1"
|
297
|
+
# "snmp-server view restricted 1.3.6.1.6.3.11.2.1"
|
298
|
+
# "snmp-server view restricted 1.3.6.1.6.3.15.1.1"
|
299
|
+
# "sntp"
|
300
|
+
# "sntp interval"
|
301
|
+
# "spanning-tree mode"
|
302
|
+
# "spanning-tree mst"
|
303
|
+
# "ssh user root authentication-method"
|
304
|
+
# "username root password 7"
|
305
|
+
# "username root privilege"
|
306
|
+
#
|
307
|
+
|
308
|
+
|
170
309
|
@result.add("snmp-server name", Ciscian::SingleValueVerb).add(@result.host.name)
|
171
310
|
@result.host.interfaces.values.each do |iface|
|
172
311
|
next unless iface.delegate.address
|
@@ -218,9 +357,8 @@ module Construqt
|
|
218
357
|
vlan_id=vlan.delegate.vlan_id
|
219
358
|
vlan.interfaces.each do |iface|
|
220
359
|
@result.add("interface #{expand_device_name(iface)}") do |section|
|
221
|
-
|
222
|
-
|
223
|
-
else
|
360
|
+
section.add("switchport trunk allowed vlan", Ciscian::RangeVerb).add(vlan_id)
|
361
|
+
unless iface.template.is_tagged?(vlan_id)
|
224
362
|
section.add("switchport trunk native vlan").add(vlan_id)
|
225
363
|
end
|
226
364
|
end
|
@@ -13,12 +13,13 @@ module Construqt
|
|
13
13
|
def commit
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def expand_vlan_device_name(device)
|
17
|
+
expand_device_name(device, { "po" => "Trk%s", "ge" => "%s" })
|
18
|
+
end
|
19
|
+
|
20
|
+
def expand_device_name(device, map={ "po" => "Trk%s", "ge" => "ethernet %s" })
|
17
21
|
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
|
+
pattern = map[device.name[0..1]]
|
22
23
|
throw "device not expandable #{device.name}" unless pattern
|
23
24
|
pattern%device.name[2..-1]
|
24
25
|
end
|
@@ -39,21 +40,21 @@ module Construqt
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def add_bond(bond)
|
42
|
-
|
43
|
+
@result.add("trunk", TrunkVerb).add("{+ports}" => bond.interfaces.map{|i| i.delegate.number }, "{*channel}" => bond.delegate.number)
|
44
|
+
@result.add("spanning-tree #{expand_vlan_device_name(bond)} priority 4")
|
43
45
|
end
|
44
46
|
|
45
47
|
def add_vlan(vlan)
|
46
|
-
@result.add("vlan #{vlan.delegate.vlan_id}") do |section|
|
48
|
+
@result.add("vlan #{vlan.delegate.vlan_id} jumbo") do |section|
|
47
49
|
next unless vlan.delegate.description && !vlan.delegate.description.empty?
|
48
50
|
throw "vlan name too long, max 32 chars" if vlan.delegate.description.length > 32
|
49
51
|
section.add("name", Ciscian::SingleValueVerb).add(vlan.delegate.description)
|
50
|
-
|
51
|
-
|
52
52
|
vlan.interfaces.each do |port|
|
53
|
+
|
53
54
|
section.add({
|
54
55
|
true => "tagged",
|
55
56
|
false => "untagged"
|
56
|
-
}[port.template.is_tagged?(vlan.vlan_id)], Ciscian::RangeVerb).add(port
|
57
|
+
}[port.template.is_tagged?(vlan.vlan_id)], Ciscian::RangeVerb).add(expand_vlan_device_name(port))
|
57
58
|
end
|
58
59
|
|
59
60
|
if vlan.delegate.address
|
@@ -104,8 +105,6 @@ module Construqt
|
|
104
105
|
["no trunk {-ports}", "trunk {+ports} Trk{*channel} Trunk"]
|
105
106
|
end
|
106
107
|
end
|
107
|
-
|
108
|
-
|
109
108
|
end
|
110
109
|
|
111
110
|
Construqt::Flavour::Ciscian.add_dialect(Hp2510g)
|
@@ -282,6 +282,7 @@ auth requisite pam_deny.so
|
|
282
282
|
PAM
|
283
283
|
#binding.pry
|
284
284
|
host.delegate.files && host.delegate.files.each do |file|
|
285
|
+
next if file.kind_of?(Construqt::Resources::SkipFile)
|
285
286
|
if host.result.replace(nil, file.data, file.right, *file.path)
|
286
287
|
Construqt.logger.warn("the file #{file.path} was overriden!")
|
287
288
|
end
|
@@ -553,6 +553,9 @@ then
|
|
553
553
|
fi
|
554
554
|
BASH
|
555
555
|
out += @result.map do |fname, block|
|
556
|
+
if host.files
|
557
|
+
next [] if host.files.find{|file| file.path == fname && file.kind_of?(Construqt::Resources::SkipFile) }
|
558
|
+
end
|
556
559
|
text = block.flatten.select{|i| !(i.nil? || i.strip.empty?) }.join("\n")
|
557
560
|
next if text.strip.empty?
|
558
561
|
Util.write_str(text, @host.name, fname)
|
data/lib/construqt/networks.rb
CHANGED
data/lib/construqt/resource.rb
CHANGED
@@ -12,6 +12,10 @@ module Construqt
|
|
12
12
|
attr_accessor :data
|
13
13
|
end
|
14
14
|
|
15
|
+
class SkipFile
|
16
|
+
attr_accessor :path
|
17
|
+
end
|
18
|
+
|
15
19
|
def initialize(region)
|
16
20
|
@region = region
|
17
21
|
@files = {}
|
@@ -21,6 +25,12 @@ module Construqt
|
|
21
25
|
add_file(IO.read(src_fname), right, key, *path)
|
22
26
|
end
|
23
27
|
|
28
|
+
def add_skip_file(fname)
|
29
|
+
sf = SkipFile.new
|
30
|
+
sf.path = fname
|
31
|
+
sf
|
32
|
+
end
|
33
|
+
|
24
34
|
def add_file(data, right, key, *path)
|
25
35
|
throw "need a key" unless key
|
26
36
|
throw "need a path #{key}" if path.empty?
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'linux/ip/addr'
|
3
|
+
require 'linux/ip/route'
|
4
|
+
CONSTRUQT_PATH=ENV['CONSTRUQT_PATH']||'..'
|
5
|
+
["#{CONSTRUQT_PATH}/construqt/lib","#{CONSTRUQT_PATH}/ipaddress/lib"].each{|path| $LOAD_PATH.unshift(path) }
|
6
|
+
require 'construqt'
|
7
|
+
|
8
|
+
# ruby lib/construqt/reverse.rb addr ~/addrs routes ~/routes
|
9
|
+
if cp = ARGV.index("addr")
|
10
|
+
addr = Linux::Ip::Addr.parse_from_lines(IO.read(ARGV[cp+1]).lines)
|
11
|
+
else
|
12
|
+
addr = Linux::Ip::Addr.parse
|
13
|
+
end
|
14
|
+
if cp = ARGV.index("routes")
|
15
|
+
routes = Linux::Ip::Route.parse_from_lines(IO.read(ARGV[cp+1]).lines)
|
16
|
+
else
|
17
|
+
routes = Linux::Ip::Route.parse
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_iface(ifaces, routes)
|
21
|
+
ifaces.interfaces.map do |iface|
|
22
|
+
next [] if iface.name == 'lo'
|
23
|
+
next [] if iface.ips.empty?
|
24
|
+
out = <<RUBY
|
25
|
+
region.interfaces.add_device(host, "#{iface.name}", "mtu" => 1500,
|
26
|
+
'mac_address' => #{iface.mac_address},
|
27
|
+
'address' => region.network.addresses.
|
28
|
+
#{Construqt::Util.indent((
|
29
|
+
iface.ips.map{|i| "add_ip('#{i.to_s}')" }+
|
30
|
+
(routes.interfaces[iface.name] ? routes.interfaces[iface.name].select{|i| i.kind_of?(Linux::Ip::Route::IpRoute::ViaRoute) }.map{|i| "add_route('#{i.dst.to_s}', '#{i.via.to_s}')" } : [])).join(".\n"), 22)})
|
31
|
+
RUBY
|
32
|
+
end.join("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
puts <<RUBY
|
36
|
+
region.hosts.add("REVERSE-HOST", "flavour" => "ubuntu") do |host|
|
37
|
+
region.interfaces.add_device(host, "lo", "mtu" => "1500", :description=>"loopback",
|
38
|
+
"address" => region.network.addresses.add_ip(Construqt::Addresses::LOOOPBACK))
|
39
|
+
|
40
|
+
#{render_iface(addr, routes)}
|
41
|
+
|
42
|
+
end
|
43
|
+
RUBY
|
data/lib/construqt/util.rb
CHANGED
data/lib/construqt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: construqt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meno Abels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: construqt-ipaddress
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/construqt/networks.rb
|
80
80
|
- lib/construqt/regions.rb
|
81
81
|
- lib/construqt/resource.rb
|
82
|
+
- lib/construqt/reverse.rb
|
82
83
|
- lib/construqt/services.rb
|
83
84
|
- lib/construqt/tags.rb
|
84
85
|
- lib/construqt/templates.rb
|