Class: Awry::Cfn

Inherits:
Cli
  • Object
show all
Defined in:
lib/awry/cfn.rb

Constant Summary collapse

COLORS =
{
  CREATE_COMPLETE: :green,
  CREATE_FAILED: :red,
  CREATE_IN_PROGRESS: :yellow,
  DELETE_COMPLETE: :green,
  DELETE_FAILED: :red,
  DELETE_IN_PROGRESS: :yellow,
  DELETE_SKIPPED: :yellow,
  DELETED: :red,
  ROLLBACK_COMPLETE: :red,
  ROLLBACK_IN_PROGRESS: :red,
  UPDATE_COMPLETE: :green,
  UPDATE_COMPLETE_CLEANUP_IN_PROGRESS: :yellow,
  UPDATE_FAILED: :red,
  UPDATE_IN_PROGRESS: :yellow,
}
STATUSES =

stack statuses that are not DELETE_COMPLETE

%i[
  CREATE_IN_PROGRESS CREATE_FAILED CREATE_COMPLETE
  DELETE_IN_PROGRESS DELETE_FAILED
  REVIEW_IN_PROGRESS
  ROLLBACK_IN_PROGRESS ROLLBACK_FAILED ROLLBACK_COMPLETE
  UPDATE_IN_PROGRESS UPDATE_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_COMPLETE
  UPDATE_ROLLBACK_IN_PROGRESS UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_ROLLBACK_COMPLETE
]

Instance Method Summary collapse

Instance Method Details

#delete(name) ⇒ Object



83
84
85
86
87
# File 'lib/awry/cfn.rb', line 83

def delete(name)
  if yes?("Really delete stack #{name}?", :yellow)
    client.delete_stack(stack_name: name)
  end
end

#events(name) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/awry/cfn.rb', line 91

def events(name)
  events = client.describe_stack_events(stack_name: name).map(&:stack_events).flatten
  events = events.first(options[:number]) if options[:number]
  events.map do |e|
    [ e.timestamp, color(e.resource_status), e.resource_type, e.logical_resource_id, e.resource_status_reason ]
  end.tap do |list|
    print_table list.reverse
  end
end

#limitsObject



102
103
104
105
106
107
108
# File 'lib/awry/cfn.rb', line 102

def limits
  client...map do |l|
    [l.name, l.value]
  end.tap do |list|
    print_table list.sort
  end
end

#ls(prefix = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/awry/cfn.rb', line 39

def ls(prefix = nil)
  client.list_stacks(stack_status_filter: STATUSES).map(&:stack_summaries).flatten.tap do |stacks|
    stacks.select! { |s| s.stack_name.start_with?(prefix) } if prefix
  end.map do |s|
    [s.stack_name, s.creation_time, color(s.stack_status), s.template_description]
  end.tap do |list|
    print_table list.sort
  end
end

#outputs(name) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/awry/cfn.rb', line 59

def outputs(name)
  client.describe_stacks(stack_name: name).stacks.first.outputs.each_with_object({}) do |o, hash|
    hash[o.output_key] = o.output_value
  end.tap do |hash|
    print_table hash.sort
  end
end

#parameters(name) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/awry/cfn.rb', line 50

def parameters(name)
  client.describe_stacks(stack_name: name).stacks.first.parameters.each_with_object({}) do |p, h|
    h[p.parameter_key] = p.parameter_value
  end.tap do |hash|
    print_table hash.sort
  end
end

#resources(name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/awry/cfn.rb', line 69

def resources(name)
  client.list_stack_resources(stack_name: name).map(&:stack_resource_summaries).flatten.tap do |resources|
    if options[:match]
      regexp = Regexp.new(options[:match], Regexp::IGNORECASE)
      resources.select! { |r| regexp.match(r.resource_type) }
    end
  end.map do |r|
    [ r.logical_resource_id, r.resource_type, color(r.resource_status), r.physical_resource_id ]
  end.tap do |list|
    print_table list.sort
  end
end