Class: Automan::Cloudformation::Terminator

Inherits:
Base
  • Object
show all
Defined in:
lib/automan/cloudformation/terminator.rb

Constant Summary

Constants included from Mixins::AwsCaller

Mixins::AwsCaller::S3_PROTO

Instance Attribute Summary

Attributes inherited from Base

#logger, #wait

Attributes included from Mixins::AwsCaller

#as, #cfn, #eb, #ec, #ec2, #elb, #r53, #rds, #s3

Instance Method Summary collapse

Methods inherited from Base

add_option, #log_options, #wait_until

Methods included from Mixins::AwsCaller

#account, #configure_aws, #looks_like_s3_path?, #parse_s3_path, #s3_object_exists?, #s3_read

Constructor Details

#initialize(options = {}) ⇒ Terminator

Returns a new instance of Terminator.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/automan/cloudformation/terminator.rb', line 7

def initialize(options={})
  @wait_for_completion = false
  super
  @wait = Wait.new({
    delay: 60,
    attempts: 20, # 20 x 60s == 20m
    debug: true,
    rescuer:  WaitRescuer.new(),
    logger:   @logger
  })
end

Instance Method Details

#delete_stack(stack_name) ⇒ Object



23
24
25
# File 'lib/automan/cloudformation/terminator.rb', line 23

def delete_stack(stack_name)
  cfn.stacks[stack_name].delete
end

#stack_deleted?(stack_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/automan/cloudformation/terminator.rb', line 31

def stack_deleted?(stack_name)
  return true if !stack_exists?(stack_name)

  case stack_status(stack_name)
  when 'DELETE_COMPLETE'
    true
  when 'DELETE_FAILED'
    raise StackDeletionError, "#{stack_name} failed to delete"
  else
    false
  end
end

#stack_exists?(stack_name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/automan/cloudformation/terminator.rb', line 19

def stack_exists?(stack_name)
  cfn.stacks[stack_name].exists?
end

#stack_status(stack_name) ⇒ Object



27
28
29
# File 'lib/automan/cloudformation/terminator.rb', line 27

def stack_status(stack_name)
  cfn.stacks[stack_name].status
end

#terminateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/automan/cloudformation/terminator.rb', line 44

def terminate
  log_options

  if !stack_exists? name
    logger.warn "Stack #{name} does not exist. Doing nothing."
    return
  end

  logger.info "terminating stack #{name}"
  delete_stack name

  if wait_for_completion
    logger.info "waiting for stack #{name} to be deleted"
    wait_until { stack_deleted? name }
  end
end