stack-kicker 0.0.19 → 0.0.20

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/bin/stack-kicker CHANGED
@@ -56,6 +56,12 @@ class App
56
56
  Stack.delete_all(config)
57
57
  when 'secgroup-sync'
58
58
  Stack.secgroup_sync(config)
59
+ when 'ssh'
60
+ debug { "ssh-host = #{options['ssh-host']}" }
61
+ debug { "ssh-user = #{options['ssh-user']}" }
62
+ debug { "ssh-command = #{options['ssh-command']}" }
63
+
64
+ Stack.ssh(config, options['sshhost'], options['ssh-user'], options['ssh-command'] )
59
65
  else
60
66
  error "Sorry, #{task} hasn't been implemented yet"
61
67
  end
@@ -76,9 +82,12 @@ class App
76
82
  #
77
83
 
78
84
  options[:stackfile] = 'Stackfile'
85
+ options['ssh-user'] = ENV['USER']
79
86
  on("--stackfile Stackfile", "Specify an alternative Stackfile")
80
87
  on("--stack mystack", "Specify the stack in Stackfile that you want to work with")
88
+ on("--ssh-host HOST", "Specify a single host, if none supplied, all hosts are executed against")
81
89
  on("--ssh-user USER", "User to be used for SSH access")
90
+ on("--ssh-command \"do/something\"", "Command to be run over ssh")
82
91
  on("--skip-secgroup-sync-deletes", "Skip deletes during secgroup-sync, handy for running multiple stacks in the one account with overlapping group names")
83
92
 
84
93
  arg :task, "task to be performed validate|configure-knife|show-stacks|show-stack|show-running|build|replace|delete|secgroup-sync|ssh"
@@ -1,5 +1,5 @@
1
1
  module Stack
2
2
  module Kicker
3
- VERSION = "0.0.19"
3
+ VERSION = "0.0.20"
4
4
  end
5
5
  end
data/lib/stack.rb CHANGED
@@ -64,8 +64,8 @@ module Stack
64
64
  end
65
65
 
66
66
  def Stack.show_stack(config)
67
- # syntax_check is a light weight check that doesn't talk to OpenStalk
68
- Stack.syntax_check(config)
67
+ # check_config is a light weight check that doesn't talk to OpenStalk
68
+ Stack.check_config(config)
69
69
  # generate an array of hostnames that this stack would create
70
70
  hostnames = Stack.generate_server_names(config)
71
71
 
@@ -130,7 +130,7 @@ module Stack
130
130
  end
131
131
 
132
132
  # check that all the required config items are set
133
- def Stack.syntax_check(config)
133
+ def Stack.check_config(config)
134
134
  if config['REGION'].nil? || config['USERNAME'].nil? || config['PASSWORD'].nil? || config['AUTH_URL'].nil? || config['TENANT_NAME'].nil? &&
135
135
  config['REGION'].empty? || config['USERNAME'].empty? || config['PASSWORD'].empty? || config['AUTH_URL'].empty? || config['TENANT_NAME'].empty?
136
136
  Logger.error { "REGION, USERNAME, PASSWORD, AUTH_URL & TENANT_NAME must all be set" }
@@ -162,7 +162,10 @@ module Stack
162
162
  # validate that all our OpenStack creds, image_id, flavors, keys etc are valid
163
163
  def Stack.validate(config)
164
164
 
165
- Stack.syntax_check(config)
165
+ Stack.check_config(config)
166
+
167
+ # populate the config & then walk through the AZs verifying the config
168
+ Stack.populate_config(config)
166
169
 
167
170
  # check that the ssh-key is loaded, otherwise most post-install scripts will fail
168
171
  # this lazily assumes that the :key_pair name matches the file the keys were loaded
@@ -180,9 +183,6 @@ module Stack
180
183
  end
181
184
  end
182
185
 
183
- # populate the config & then walk through the AZs verifying the config
184
- Stack.populate_config(config)
185
-
186
186
  # Check that we have valid details for each AZ
187
187
  config[:azs].each do |az|
188
188
 
@@ -229,7 +229,8 @@ module Stack
229
229
 
230
230
  def Stack.generate_knife_rb(config)
231
231
  # generate a project/.chef/knife.rb from our config
232
- # (assumes the chef server is running for public IP access etc)
232
+
233
+ Stack.check_config(config)
233
234
 
234
235
  # find the chef server, if we need to
235
236
  if config[:chef_server_hostname].nil? || config[:chef_server_private].nil? || config[:chef_server_public]
@@ -299,7 +300,7 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
299
300
  end
300
301
 
301
302
  def Stack.generate_server_names(config)
302
- Stack.populate_config(config)
303
+ Stack.check_config(config)
303
304
  config[:hostnames] = config[:node_details].keys
304
305
  config[:hostnames]
305
306
  end
@@ -332,7 +333,9 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
332
333
  Logger.warn { "Defaulting to .chef/validation.pem for config[:chef_validation_pem]" }
333
334
  config[:chef_validation_pem] = '.chef/validation.pem'
334
335
  end
335
- config[:chef_validation_pem] = Stack.find_file(config, config[:chef_validation_pem])
336
+ chef_validation_pem_abs = Stack.find_file(config, config[:chef_validation_pem])
337
+ # only store the abs if we found it...
338
+ config[:chef_validation_pem] = chef_validation_pem_abs unless chef_validation_pem_abs.nil?
336
339
 
337
340
  if config[:name_template].nil?
338
341
  Logger.warn { "Defaulting to '%s-%s-%s%04d' for config[:name_template]" }
@@ -441,7 +444,7 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
441
444
  def Stack.get_all_instances(config, refresh = false)
442
445
  if config[:all_instances].nil? || refresh
443
446
  # we need to get the server list for each AZ mentioned in the config[:roles][:role][:azs], this is populated by Stack.populate_config
444
- Stack.populate_config(config)
447
+ Stack.check_config(config)
445
448
 
446
449
  # get the current list of servers from OpenStack & generate a hash, keyed on name
447
450
  servers = Hash.new
@@ -523,8 +526,15 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
523
526
  end
524
527
  end
525
528
 
529
+ # ssh to a host, or all hosts
526
530
  def Stack.ssh(config, hostname = nil, user = ENV['USER'], command = nil)
527
- # ssh to a host, or all hosts
531
+ # check that we have something to run
532
+ if command.nil?
533
+ Logger.error "No command passed to Stack.ssh!"
534
+ end
535
+
536
+ # sanity check our config, load defaults etc
537
+ Stack.check_config(config)
528
538
 
529
539
  # get all running instances
530
540
  servers = Stack.get_our_instances(config)
@@ -546,7 +556,7 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
546
556
  def Stack.get_our_instances(config)
547
557
  Logger.debug { ">>> Stack.get_our_instances" }
548
558
  # build an hash of running instances that match our generated hostnames
549
- node_details = Stack.populate_config(config)
559
+ Stack.check_config(config)
550
560
 
551
561
  # get all of our hostnames
552
562
  hostnames = Stack.generate_server_names(config)
@@ -559,7 +569,7 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
559
569
  hostnames.each do |hostname|
560
570
  if (servers.include?(hostname))
561
571
  # return the instance details merged with the node_details (info like role)
562
- running[hostname] = servers[hostname].merge(node_details[hostname])
572
+ running[hostname] = servers[hostname].merge(config[:node_details][hostname])
563
573
  end
564
574
  end
565
575
 
@@ -570,7 +580,7 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
570
580
 
571
581
  def Stack.delete_node(config, node)
572
582
  # this also populates out unspecified defaults, like az
573
- Stack.populate_config(config)
583
+ Stack.check_config(config)
574
584
  # get info about all instances running in our account & AZs
575
585
  Stack.get_all_instances(config)
576
586
 
@@ -585,10 +595,8 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
585
595
  end
586
596
 
587
597
  def Stack.delete_all(config)
588
- # check that we have OS_* vars loaded etc
589
- Stack.syntax_check(config)
590
598
  # this also populates out unspecified defaults, like az
591
- Stack.populate_config(config)
599
+ Stack.check_config(config)
592
600
 
593
601
  # get the list of nodes we consider 'ours', i.e. with hostnames that match
594
602
  # those generated by this stack
@@ -907,6 +915,7 @@ cookbook_path [ '<%=config[:stackhome]%>/cookbooks' ]
907
915
 
908
916
  if filename_fqp.empty?
909
917
  Logger.warn "couldn't find #{filename} in #{dirs}"
918
+ filename_fqp = nil
910
919
  end
911
920
  filename_fqp
912
921
  end
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.19
4
+ version: 0.0.20
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-14 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc