Class: Lono::Cfn::Delete

Inherits:
Object
  • Object
show all
Includes:
AwsService, Util
Defined in:
lib/lono/cfn/delete.rb

Instance Method Summary collapse

Methods included from Util

#are_you_sure?

Methods included from AwsService

#cfn, #stack_exists?, #testing_update?

Constructor Details

#initialize(stack_name, options = {}) ⇒ Delete

Returns a new instance of Delete.



5
6
7
8
# File 'lib/lono/cfn/delete.rb', line 5

def initialize(stack_name, options={})
  @stack_name = switch_current(stack_name)
  @options = options
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lono/cfn/delete.rb', line 10

def run
  message = "Deleted #{@stack_name} stack."
  if @options[:noop]
    puts "NOOP #{message}"
  else
    are_you_sure?(@stack_name, :delete)

    if stack_exists?(@stack_name)
      cfn.delete_stack(stack_name: @stack_name)
      puts message
    else
      puts "#{@stack_name.inspect} stack does not exist".colorize(:red)
    end
  end

  return unless @options[:wait]
  start_time = Time.now
  status.wait
  took = Time.now - start_time
  puts "Time took for stack deletion: #{status.pretty_time(took).green}."
end

#statusObject



32
33
34
# File 'lib/lono/cfn/delete.rb', line 32

def status
  @status ||= Lono::Cfn::Status.new(@stack_name)
end

#switch_current(stack_name) ⇒ Object



36
37
38
# File 'lib/lono/cfn/delete.rb', line 36

def switch_current(stack_name)
  Lono::Cfn::Current.name!(stack_name)
end