Class: Lono::Sets::Status::Instances
- Inherits:
-
Object
- Object
- Lono::Sets::Status::Instances
show all
- Includes:
- AwsServices, TimeSpent
- Defined in:
- lib/lono/sets/status/instances.rb
Constant Summary
collapse
- @@aws_cli_command_shown =
false
Instance Method Summary
collapse
Methods included from TimeSpent
#show_time_spent
#pretty_time
#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts
#rollback_complete?, #testing_update?
#find_stack_set, #stack_set_exists?
#find_stack, #stack_exists?
Constructor Details
#initialize(options = {}) ⇒ Instances
Returns a new instance of Instances.
6
7
8
9
10
|
# File 'lib/lono/sets/status/instances.rb', line 6
def initialize(options={})
@options = options
@stack, @operation_id = options[:stack], options[:operation_id]
@show_time_spent = options[:show_time_spent].nil? ? true : options[:show_time_spent]
end
|
Instance Method Details
#completed?(status) ⇒ Boolean
describe_stack_set_operation stack_set_operation.status is one of RUNNING, SUCCEEDED, FAILED, STOPPING, STOPPED
92
93
94
95
|
# File 'lib/lono/sets/status/instances.rb', line 92
def completed?(status)
completed_statuses = %w[SUCCEEDED FAILED STOPPED]
completed_statuses.include?(status)
end
|
#instances ⇒ Object
106
107
108
|
# File 'lib/lono/sets/status/instances.rb', line 106
def instances
stack_instances.map { |stack_instance| Instance.new(stack_instance) }
end
|
#latest_operation_id ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/lono/sets/status/instances.rb', line 128
def latest_operation_id
resp = cfn.list_stack_set_operations(
stack_set_name: @stack,
max_results: 1,
)
resp.summaries.first.operation_id
end
|
#operation_id ⇒ Object
124
125
126
|
# File 'lib/lono/sets/status/instances.rb', line 124
def operation_id
@operation_id ||= latest_operation_id
end
|
#show ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/lono/sets/status/instances.rb', line 22
def show
if stack_instances.empty?
puts " There are 0 stack instances associated with the \#{@stack} stack set.\n Use `lono set_instances deploy` to add stack instances. Example:\n\n lono set_instances deploy \#{@stack} --accounts 111 --regions us-west-2 us-east-2\n\n EOL\n return\n end\n\n threads = start_wait_for_instances_threads\n wait_until_stack_set_operation_complete\n threads.map(&:join)\nend\n"
|
#show_aws_cli_command(operation_id) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/lono/sets/status/instances.rb', line 77
def show_aws_cli_command(operation_id)
return if @@aws_cli_command_shown
command = "aws cloudformation describe-stack-set-operation --stack-set-name #{@stack} --operation-id #{operation_id}"
puts " Here is also the cli command to check:\n\n \#{command}\n\n EOL\n @@aws_cli_command_shown = true\nend\n"
|
#stack_instances ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/lono/sets/status/instances.rb', line 110
def stack_instances
resp = cfn.list_stack_instances(stack_set_name: @stack)
summaries = resp.summaries
filter = @options[:filter]
return summaries unless filter
summaries.reject do |s|
intersect = [[s.account, s.region]] & filter
intersect.empty?
end
end
|
#start_wait_for_instances_threads ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/lono/sets/status/instances.rb', line 40
def start_wait_for_instances_threads
with_instances do |instance|
Thread.new { sleep 5; instance.show }
end
end
|
#wait(to = "completed") ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/lono/sets/status/instances.rb', line 12
def wait(to="completed")
puts "Stack Instance statuses... (takes a while)"
puts "You can also check with StackSets console at the Operations Tab."
wait_until_outdated if @options[:start_on_outdated]
threads = start_wait_for_instances_threads
wait_until_stack_set_operation_complete
threads.map(&:join)
end
|
#wait_until_outdated ⇒ Object
If we dont wait until OUTDATED, during a ‘lono sets deploy` it’ll immediately think that the instance statuses are done
98
99
100
101
102
103
104
|
# File 'lib/lono/sets/status/instances.rb', line 98
def wait_until_outdated
outdated = false
until outdated
outdated = stack_instances.detect { |stack_instance| stack_instance.status == "OUTDATED" }
sleep 5
end
end
|
#wait_until_stack_set_operation_complete ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/lono/sets/status/instances.rb', line 55
def wait_until_stack_set_operation_complete
status, stack_set_operation = nil, nil
until completed?(status)
resp = cfn.describe_stack_set_operation(
stack_set_name: @stack,
operation_id: operation_id,
)
stack_set_operation = resp.stack_set_operation
status = stack_set_operation.status
show_aws_cli_command(stack_set_operation.operation_id)
unless completed?(status)
sleep 5
end
end
if @show_time_spent
show_time_spent(stack_set_operation)
puts "Stack set operation completed."
end
end
|
#with_instances ⇒ Object
48
49
50
51
52
53
|
# File 'lib/lono/sets/status/instances.rb', line 48
def with_instances
stack_instances.map do |stack_instance|
instance = Instance.new(stack_instance)
yield(instance)
end
end
|