class Lono::Sets::Status::Instances
Public Class Methods
new(options={})
click to toggle source
# 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
Public Instance Methods
completed?(status)
click to toggle source
describe_stack_set_operation stack_set_operation.status is one of RUNNING, SUCCEEDED, FAILED, STOPPING, STOPPED
# File lib/lono/sets/status/instances.rb, line 92 def completed?(status) completed_statuses = %w[SUCCEEDED FAILED STOPPED] completed_statuses.include?(status) end
instances()
click to toggle source
# File lib/lono/sets/status/instances.rb, line 106 def instances stack_instances.map { |stack_instance| Instance.new(stack_instance) } end
latest_operation_id()
click to toggle source
# 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()
click to toggle source
# File lib/lono/sets/status/instances.rb, line 124 def operation_id @operation_id ||= latest_operation_id end
show()
click to toggle source
# File lib/lono/sets/status/instances.rb, line 22 def show if stack_instances.empty? # Note: no access to @blueprint here puts <<~EOL There are 0 stack instances associated with the #{@stack} stack set. Use `lono set_instances deploy` to add stack instances. Example: lono set_instances deploy #{@stack} --accounts 111 --regions us-west-2 us-east-2 EOL return end threads = start_wait_for_instances_threads wait_until_stack_set_operation_complete threads.map(&:join) end
show_aws_cli_command(operation_id)
click to toggle source
# 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 <<~EOL Here is also the cli command to check: #{command} EOL @@aws_cli_command_shown = true end
stack_instances()
click to toggle source
# 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 is really only used internally. So it's fine to keep it as complex data structure since that's what we # build it up as in Lono::SetInstances::Deploy filter = @options[:filter] # [["112233445566", "us-west-1"],["112233445566", "us-west-2"]] return summaries unless filter summaries.reject do |s| intersect = [[s.account, s.region]] & filter intersect.empty? end end
start_wait_for_instances_threads()
click to toggle source
# File lib/lono/sets/status/instances.rb, line 40 def start_wait_for_instances_threads # Tricky: extra sleep so that the show_aws_cli_command in wait_until_stack_set_operation_complete # shows up first. Quickest way to implement. with_instances do |instance| Thread.new { sleep 5; instance.show } end end
wait(to="completed")
click to toggle source
# 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 # start the the tailer here so the show_aws_cli_command shows up threads.map(&:join) end
wait_until_outdated()
click to toggle source
If we dont wait until OUTDATED, during a `lono sets deploy` it'll immediately think that the instance statuses are done
# 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()
click to toggle source
# 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) # puts "DEBUG: wait_until_stack_set_operation_complete" unless completed?(status) sleep 5 end end if @show_time_spent # or else it double shows from `lono sets deploy`. Do want it to show for `lono set_instances sync` though show_time_spent(stack_set_operation) puts "Stack set operation completed." end end
with_instances() { |instance| ... }
click to toggle source
# 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