Class: Chef::Knife::CloudformationEvents
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::CloudformationEvents
- Includes:
- KnifeCloudformation::Knife::Base
- Defined in:
- lib/chef/knife/cloudformation_events.rb
Overview
Cloudformation list command
Instance Method Summary collapse
-
#_run ⇒ Object
Run the events list action.
-
#default_attributes ⇒ Array<String>
Default attributes for events.
-
#get_events(stack, last_id = nil) ⇒ Array<Hash>
Fetch events from stack.
Methods included from KnifeCloudformation::Knife::Base
Instance Method Details
#_run ⇒ Object
Run the events list action
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/knife/cloudformation_events.rb', line 46 def _run name = name_args.first ui.info "Cloud Formation Events for Stack: #{ui.color(name, :bold)}\n" stack = provider.connection.stacks.get(name) last_id = nil if(stack) events = get_events(stack) things_output(name, events, 'events') last_id = events.last ? events.last[:id] : nil if(Chef::Config[:knife][:cloudformation][:poll]) cycle_events = true while(cycle_events) cycle_events = stack.in_progress? sleep(Chef::Config[:knife][:cloudformation][:poll_delay] || 10) stack.events.reload events = get_events(stack, last_id) unless(events.empty?) last_id = events.last[:id] things_output(nil, events, 'events', :no_title, :ignore_empty_output) end nest_stacks = stack.resources.all.find_all do |resource| resource.state.to_s.end_with?('in_progress') && resource.type == 'AWS::CloudFormation::Stack' end if(nest_stacks) nest_stacks.each do |nest_stack| begin poll_stack(nest_stack.id) ui.info "Complete event listing for nested stack (#{nest_stack.name})" rescue => e ui.warn "Error encountered on event listing for nested stack - #{e} (#{nest_stack.name})" end end end stack.reload end # Extra to see completion things_output(nil, get_events(stack, last_id), 'events', :no_title, :ignore_empty_output) end else ui.fatal "Failed to locate requested stack: #{ui.color(name, :bold, :red)}" raise "Failed to locate stack: #{name}!" end end |
#default_attributes ⇒ Array<String>
112 113 114 |
# File 'lib/chef/knife/cloudformation_events.rb', line 112 def default_attributes %w(time resource_logical_id resource_status resource_status_reason) end |
#get_events(stack, last_id = nil) ⇒ Array<Hash>
Fetch events from stack
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/chef/knife/cloudformation_events.rb', line 96 def get_events(stack, last_id=nil) get_things do stack_events = stack.events.all if(last_id) start_index = stack_events.index{|event| event.id == last_id} events = stack_events.slice(0, start_index.to_i) else events = stack_events end events.map do |event| Mash.new(event.attributes) end end end |