Class: Lono::Sets::Instances::Delete

Inherits:
Base show all
Includes:
AwsServices, Utils::Sure
Defined in:
lib/lono/sets/instances/delete.rb

Instance Method Summary collapse

Methods included from Utils::Sure

#sure?

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods inherited from Base

#requested, #stack_instances

Methods inherited from Base

#build_options, #exit_unless_updatable!, #operation_preferences

Methods inherited from Cfn::Base

#capabilities, #check_registration, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #exit_unless_updatable!, #generate_all, #pretty_path, #prompt_for_iam, #quit, #rerun_with_iam?, #set_template_url!, #show_options, #stack_status, #starting_message, #status, #tags

Methods inherited from AbstractBase

#reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

#initialize(options = {}) ⇒ Delete

Returns a new instance of Delete.



6
7
8
9
# File 'lib/lono/sets/instances/delete.rb', line 6

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

Instance Method Details

#accountsObject



61
62
63
# File 'lib/lono/sets/instances/delete.rb', line 61

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

#long_descObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lono/sets/instances/delete.rb', line 41

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

#regionsObject



65
66
67
# File 'lib/lono/sets/instances/delete.rb', line 65

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

#runObject



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
# File 'lib/lono/sets/instances/delete.rb', line 11

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

#validate!Object



53
54
55
56
57
58
59
# File 'lib/lono/sets/instances/delete.rb', line 53

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