stack-kicker 0.0.21 → 0.0.22
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/stack-kicker/version.rb +1 -1
- data/lib/stack.rb +145 -129
- metadata +2 -2
data/lib/stack-kicker/version.rb
CHANGED
data/lib/stack.rb
CHANGED
@@ -57,9 +57,11 @@ module Stack
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def Stack.show_stacks(stackfile = 'Stackfile')
|
60
|
-
# our
|
61
|
-
|
62
|
-
|
60
|
+
# evaluate our Stackfile, but only the once
|
61
|
+
if defined?(StackConfig::Stacks).nil?
|
62
|
+
config_raw = File.read(stackfile)
|
63
|
+
eval(config_raw)
|
64
|
+
end
|
63
65
|
|
64
66
|
Logger.info { "Stacks:" }
|
65
67
|
StackConfig::Stacks.each do |name, details|
|
@@ -77,14 +79,20 @@ module Stack
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def Stack.select_stack(stackfile = 'Stackfile', stack_name)
|
80
|
-
# our
|
81
|
-
|
82
|
-
|
82
|
+
# evaluate our Stackfile, but only the once
|
83
|
+
if defined?(StackConfig::Stacks).nil?
|
84
|
+
config_raw = File.read(stackfile)
|
85
|
+
eval(config_raw)
|
86
|
+
end
|
83
87
|
|
84
88
|
# if there is only one stack defined in the Stackfile, load it:
|
85
89
|
if StackConfig::Stacks.count == 1 && stack_name.nil?
|
86
90
|
stack_name = StackConfig::Stacks.keys[0]
|
87
91
|
Logger.info { "Defaulting to #{stack_name} as there is a single stack defined and no stack named" }
|
92
|
+
elsif stack_name.nil?
|
93
|
+
Logger.info { "You didn't specify a stack, and there are multiple stacks defined in #{stackfile}" }
|
94
|
+
Stack.show_stacks(stackfile)
|
95
|
+
exit
|
88
96
|
end
|
89
97
|
|
90
98
|
# returns a config object, injecting the name into the returned config
|
@@ -135,42 +143,48 @@ module Stack
|
|
135
143
|
|
136
144
|
# check that all the required config items are set
|
137
145
|
def Stack.check_config(config)
|
138
|
-
if config[
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
# load defaults for any items not configured
|
145
|
-
Stack.populate_config(config)
|
146
|
+
if config[:checked].nil?
|
147
|
+
if config['REGION'].nil? || config['USERNAME'].nil? || config['PASSWORD'].nil? || config['AUTH_URL'].nil? || config['TENANT_NAME'].nil? &&
|
148
|
+
config['REGION'].empty? || config['USERNAME'].empty? || config['PASSWORD'].empty? || config['AUTH_URL'].empty? || config['TENANT_NAME'].empty?
|
149
|
+
Logger.error { "REGION, USERNAME, PASSWORD, AUTH_URL & TENANT_NAME must all be set" }
|
150
|
+
exit
|
151
|
+
end
|
146
152
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
# validation.pem to to exist
|
151
|
-
dot_chef_abs = File.absolute_path(File.join(config[:stackhome], config[:dot_chef]))
|
152
|
-
if !File.directory?(dot_chef_abs)
|
153
|
-
Logger.warn "#{dot_chef_abs} doesn't exist"
|
153
|
+
if config[:roles].nil?
|
154
|
+
Logger.error { "No roles defined in #{config[:name]}, aborting." }
|
155
|
+
exit
|
154
156
|
end
|
155
157
|
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
# load defaults for any items not configured
|
159
|
+
Stack.populate_config(config)
|
160
|
+
|
161
|
+
if config[:provisioner] == 'chef'
|
162
|
+
# check that we have semi-sensible Chef setup
|
163
|
+
# at a bare minimum, we need the directory where we're going to download
|
164
|
+
# validation.pem to to exist
|
165
|
+
dot_chef_abs = File.absolute_path(File.join(config[:stackhome], config[:dot_chef]))
|
166
|
+
if !File.directory?(dot_chef_abs)
|
167
|
+
Logger.warn "#{dot_chef_abs} doesn't exist"
|
168
|
+
end
|
169
|
+
|
170
|
+
# Check we have a #{dot_chef_abs}/.chef/knife.rb
|
171
|
+
knife_rb_abs = dot_chef_abs + '/knife.rb'
|
172
|
+
if File.exists?(knife_rb_abs)
|
173
|
+
Logger.info "Found #{knife_rb_abs}, lets hope it contains something sensible"
|
174
|
+
else
|
175
|
+
Logger.warn "#{knife_rb_abs} doesn't exist, please run 'stack-kicker configure-knife <stack-name>'"
|
176
|
+
end
|
162
177
|
end
|
163
178
|
end
|
179
|
+
config[:checked] = true
|
164
180
|
end
|
165
181
|
|
166
182
|
# validate that all our OpenStack creds, image_id, flavors, keys etc are valid
|
167
183
|
def Stack.validate(config)
|
168
184
|
|
185
|
+
# check & populate the config with defaults for anything not specified.
|
169
186
|
Stack.check_config(config)
|
170
187
|
|
171
|
-
# populate the config & then walk through the AZs verifying the config
|
172
|
-
Stack.populate_config(config)
|
173
|
-
|
174
188
|
# check that the ssh-key is loaded, otherwise most post-install scripts will fail
|
175
189
|
# this lazily assumes that the :key_pair name matches the file the keys were loaded
|
176
190
|
# from
|
@@ -313,133 +327,135 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
|
|
313
327
|
# config[:role_details] contains built out role details with defaults filled in from stack defaults
|
314
328
|
# config[:node_details] contains node details built out from role_details
|
315
329
|
|
316
|
-
if config[:
|
317
|
-
config[:find_file_paths]
|
318
|
-
|
330
|
+
if config[:populated].nil?
|
331
|
+
if config[:find_file_paths].nil?
|
332
|
+
config[:find_file_paths] = Array.new
|
333
|
+
end
|
319
334
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
335
|
+
# set some sensible defaults to the stack-wide defaults if they haven't been set in the Stackfile.
|
336
|
+
if config[:provisioner].nil?
|
337
|
+
Logger.warn { "Defaulting to chef for config[:provisioner] "}
|
338
|
+
config[:provisioner] = 'chef'
|
339
|
+
end
|
325
340
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
341
|
+
if config[:dot_chef].nil?
|
342
|
+
Logger.warn { "Defaulting to .chef for config[:dot_chef] "}
|
343
|
+
config[:dot_chef] = '.chef'
|
344
|
+
end
|
330
345
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
346
|
+
if config[:chef_environment].nil?
|
347
|
+
Logger.warn { "Defaulting to _default for config[:chef_environment]" }
|
348
|
+
config[:chef_environment] = '_default'
|
349
|
+
end
|
335
350
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
351
|
+
if config[:chef_validation_pem].nil?
|
352
|
+
Logger.warn { "Defaulting to .chef/validation.pem for config[:chef_validation_pem]" }
|
353
|
+
config[:chef_validation_pem] = '.chef/validation.pem'
|
354
|
+
end
|
355
|
+
chef_validation_pem_abs = Stack.find_file(config, config[:chef_validation_pem])
|
356
|
+
# only store the abs if we found it...
|
357
|
+
config[:chef_validation_pem] = chef_validation_pem_abs unless chef_validation_pem_abs.nil?
|
343
358
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
359
|
+
if config[:name_template].nil?
|
360
|
+
Logger.warn { "Defaulting to '%s-%s-%s%04d' for config[:name_template]" }
|
361
|
+
config[:name_template] = '%s-%s-%s%04d'
|
362
|
+
end
|
348
363
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
364
|
+
if config[:site_template].nil?
|
365
|
+
Logger.warn { "Defaulting to '%s' for config[:site_template]" }
|
366
|
+
config[:site_template] = '%s'
|
367
|
+
end
|
353
368
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
369
|
+
if config[:global_service_name].nil?
|
370
|
+
Logger.error { "Defaulting to 'UNKNOWN' for config[:global_service_name]" }
|
371
|
+
config[:site_template] = 'UNKNOWN'
|
372
|
+
end
|
358
373
|
|
359
|
-
|
360
|
-
|
361
|
-
|
374
|
+
if config[:metadata].nil?
|
375
|
+
config[:metadata] = Hash.new
|
376
|
+
end
|
362
377
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
378
|
+
if config[:node_details].nil?
|
379
|
+
Logger.debug { "Initializing config[:node_details] and config[:azs]" }
|
380
|
+
config[:node_details] = Hash.new
|
381
|
+
config[:azs] = Array.new
|
367
382
|
|
368
|
-
|
369
|
-
|
383
|
+
config[:roles].each do |role,role_details|
|
384
|
+
Logger.debug { "Setting defaults for #{role}" }
|
370
385
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
386
|
+
# default to 1 node of this role if :count isn't set
|
387
|
+
if role_details[:count].nil?
|
388
|
+
role_details[:count] = 1
|
389
|
+
end
|
375
390
|
|
376
|
-
|
377
|
-
|
378
|
-
|
391
|
+
if (role_details[:data_dir].nil?)
|
392
|
+
role_details[:data_dir] = '/dummy'
|
393
|
+
end
|
379
394
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
395
|
+
# Has the cloud_config_yaml been overridden?
|
396
|
+
if (role_details[:cloud_config_yaml])
|
397
|
+
role_details[:cloud_config_yaml] = Stack.find_file(config, role_details[:cloud_config_yaml])
|
398
|
+
else
|
399
|
+
role_details[:cloud_config_yaml] = Stack.find_file(config, 'cloud-config.yaml')
|
400
|
+
end
|
386
401
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
402
|
+
# Has the default bootstrap script been overridden
|
403
|
+
if (role_details[:bootstrap])
|
404
|
+
if (role_details[:bootstrap].empty?)
|
405
|
+
Logger.debug { "role_details[:bootstrap] is empty, ignoring" }
|
406
|
+
else
|
407
|
+
role_details[:bootstrap] = Stack.find_file(config, role_details[:bootstrap])
|
408
|
+
end
|
391
409
|
else
|
392
|
-
role_details[:bootstrap] = Stack.find_file(config,
|
410
|
+
role_details[:bootstrap] = Stack.find_file(config, 'chef-client-bootstrap-excl-validation-pem.sh')
|
393
411
|
end
|
394
|
-
else
|
395
|
-
role_details[:bootstrap] = Stack.find_file(config, 'chef-client-bootstrap-excl-validation-pem.sh')
|
396
|
-
end
|
397
412
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
413
|
+
# we default to the role name for the security group unless explicitly set
|
414
|
+
if role_details[:security_group].nil?
|
415
|
+
role_details[:security_group] = role.to_s
|
416
|
+
end
|
402
417
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
418
|
+
# default to execing post install scripts in stackhome is a cwd wasn't set
|
419
|
+
# (cwd is calculated relative to stackhome)
|
420
|
+
if role_details[:post_install_cwd].nil?
|
421
|
+
role_details[:post_install_cwd] = '/.'
|
422
|
+
end
|
408
423
|
|
409
|
-
|
410
|
-
|
411
|
-
|
424
|
+
if role_details[:post_install_args].nil?
|
425
|
+
role_details[:post_install_args] = ''
|
426
|
+
end
|
412
427
|
|
413
|
-
|
414
|
-
|
415
|
-
|
428
|
+
(1..role_details[:count]).each do |p|
|
429
|
+
Logger.debug { "Populating the config[:role_details][:azs] array with AZ" }
|
430
|
+
role_details[:azs] = Array.new if role_details[:azs].nil?
|
416
431
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
432
|
+
# is there an az set for this node?
|
433
|
+
if role_details[:azs][p-1].nil?
|
434
|
+
# inherit the global az
|
435
|
+
Logger.debug { "Inheriting the AZ for #{role} (#{config['REGION']})" }
|
436
|
+
role_details[:azs][p-1] = config['REGION']
|
437
|
+
end
|
423
438
|
|
424
|
-
|
425
|
-
|
439
|
+
# add this AZ to the AZ list, we'll dedupe later
|
440
|
+
config[:azs] << role_details[:azs][p-1]
|
426
441
|
|
427
|
-
|
428
|
-
|
429
|
-
|
442
|
+
hostname = Stack.generate_hostname(config, role, p)
|
443
|
+
Logger.debug { "Setting node_details for #{hostname}, using element #{p}-1 from #{role_details[:azs]}" }
|
444
|
+
config[:node_details][hostname] = { :az => role_details[:azs][p-1], :region => role_details[:azs][p-1], :role => role }
|
445
|
+
end
|
430
446
|
end
|
431
447
|
end
|
432
|
-
|
433
|
-
config[:azs].uniq!
|
448
|
+
config[:azs].uniq!
|
434
449
|
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
450
|
+
# if set the region specific settings from the global settings if not already specified
|
451
|
+
config[:azs].each do |az|
|
452
|
+
# we store region spefic stuff in hash
|
453
|
+
config[az] = Hash.new if config[az].nil?
|
439
454
|
|
440
|
-
|
455
|
+
config[az]['image_id'] = config['image_id'] if config[az]['image_id'].nil?
|
456
|
+
end
|
441
457
|
end
|
442
|
-
|
458
|
+
config[:populated] = true
|
443
459
|
config[:node_details]
|
444
460
|
end
|
445
461
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stack-kicker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|