5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/opsworks/cli/subcommands/instances.rb', line 5
def self.included(thor)
thor.class_eval do
desc 'instances:status [--stack STACK]',
'Display instance status for a stack'
option :stack, type: :array
define_method 'instances:status' do
stacks = parse_stacks(options)
stacks.each do |stack|
stack.instances.each do |instance|
say [
stack.name,
instance.hostname,
instance.status
].join("\t")
end
end
end
desc 'instances:wait [--timeout TIMEOUT] [--stack STACK]',
'Wait for all instances to settle'
option :timeout, type: :numeric, default: 300
option :stack, type: :array
define_method 'instances:wait' do
deadline = Time.now + options[:timeout]
stacks = parse_stacks(options)
loop do
stacks = stacks.reject(&:settled?)
break if stacks.empty?
if Time.now > deadline
raise "Stacks did not settle: #{stacks.map(&:name).join(' ')}"
end
sleep 5
end
end
desc 'instances:setup [--stack STACK]',
'Retry setup on any instances where it failed'
option :stack, type: :array
define_method 'instances:setup' do
stacks = parse_stacks(options)
stacks.each do |stack|
stack.instances.each do |instance|
next unless instance.setup_failed?
say "Running setup on #{stack.name} #{instance.hostname}"
stack.create_deployment(
command: { name: 'setup' },
instance_ids: [instance.id]
)
end
end
end
end
end
|