Sha256: 8685effd3be6279d6ad7011a3cab3739d799abea46c23a16e84139b8224e299b

Contents?: true

Size: 1.95 KB

Versions: 26

Compression:

Stored size: 1.95 KB

Contents

class Lono::Sets::Instances
  class Delete < Base
    include Lono::AwsServices
    include Lono::Utils::Sure

    def initialize(options={})
      @options = options
      @stack = options[:stack]
    end

    def run
      validate!

      sure?("Are you sure you want to delete the #{@stack} instances?", long_desc)

      # delete_stack_instances resp has operation_id
      # Could also use that to poll for status with the list_stack_set_operation_results
      # api. Currently, Instance::Status class not using this info. If we need will add the logic.
      resp = cfn.delete_stack_instances(
        options = {
          stack_set_name: @stack,
          accounts: accounts,
          regions: regions,
          retain_stacks: false,
        }
      )
      operation_id = resp.operation_id

      # Status tailing handled by caller
      o = @options.merge(
        filter: requested,
        start_on_outdated: false,
        operation_id: operation_id,
      )
      Lono::Sets::Status::Instance::Base.show_time_progress = true
      Lono::Sets::Status::Instance::Base.delay_factor = accounts.size * regions.size
      instances_status = Status.new(o)
      instances_status.run(to: "deleted") unless @options[:noop] # returns success: true or false
    end

    def long_desc
      total = accounts.size * regions.size
      <<~EOL
      These stack instances will be deleted:

          accounts: #{accounts.join(',')}
          regions: #{regions.join(',')}

      Number of stack instances to be deleted: #{total}
      EOL
    end

    def validate!
      invalid = (regions.blank? || accounts.blank?) && !@options[:all]
      if invalid
        puts "ERROR: You must provide --accounts and --regions or --all.".color(:red)
        exit 1
      end
    end

    def accounts
      @options[:all] ? stack_instances.map(&:account).uniq : @options[:accounts]
    end

    def regions
      @options[:all] ? stack_instances.map(&:region).uniq : @options[:regions]
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
lono-7.4.11 lib/lono/sets/instances/delete.rb
lono-7.4.10 lib/lono/sets/instances/delete.rb
lono-7.4.9 lib/lono/sets/instances/delete.rb
lono-7.4.8 lib/lono/sets/instances/delete.rb
lono-7.4.7 lib/lono/sets/instances/delete.rb
lono-7.4.6 lib/lono/sets/instances/delete.rb
lono-7.4.5 lib/lono/sets/instances/delete.rb
lono-7.4.4 lib/lono/sets/instances/delete.rb
lono-7.4.3 lib/lono/sets/instances/delete.rb
lono-7.4.2 lib/lono/sets/instances/delete.rb
lono-7.4.1 lib/lono/sets/instances/delete.rb
lono-7.4.0 lib/lono/sets/instances/delete.rb
lono-7.3.2 lib/lono/sets/instances/delete.rb
lono-7.3.1 lib/lono/sets/instances/delete.rb
lono-7.3.0 lib/lono/sets/instances/delete.rb
lono-7.2.3 lib/lono/sets/instances/delete.rb
lono-7.2.2 lib/lono/sets/instances/delete.rb
lono-7.2.1 lib/lono/sets/instances/delete.rb
lono-7.2.0 lib/lono/sets/instances/delete.rb
lono-7.1.0 lib/lono/sets/instances/delete.rb