Class: Sfn::Command::Events
- Inherits:
-
Sfn::Command
- Object
- Bogo::Cli::Command
- Sfn::Command
- Sfn::Command::Events
- Includes:
- Sfn::CommandModule::Base
- Defined in:
- lib/sfn/command/events.rb
Overview
Events command
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#allowed_attributes ⇒ Array<String>
Allowed attributes for events.
-
#default_attributes ⇒ Array<String>
Default attributes for events.
-
#discover_stacks(stack) ⇒ Object
Discover stacks defined within the resources of given stack.
-
#execute! ⇒ Object
Run the events list action.
-
#get_events(*args) ⇒ Array<Hash>
Fetch events from stack.
Methods included from Sfn::CommandModule::Base
Methods inherited from Sfn::Command
Methods included from Sfn::CommandModule::Callbacks
#api_action!, #callbacks_for, #run_callbacks_for
Constructor Details
This class inherits a constructor from Sfn::Command
Instance Attribute Details
#stack ⇒ Miasma::Models::Orchestration::Stack (readonly)
11 12 13 |
# File 'lib/sfn/command/events.rb', line 11 def stack @stack end |
Instance Method Details
#allowed_attributes ⇒ Array<String>
Returns allowed attributes for events.
99 100 101 102 103 104 105 |
# File 'lib/sfn/command/events.rb', line 99 def allowed_attributes result = super unless(@stacks.size > 1) result.delete('stack_name') end result end |
#default_attributes ⇒ Array<String>
Returns default attributes for events.
94 95 96 |
# File 'lib/sfn/command/events.rb', line 94 def default_attributes %w(stack_name time resource_logical_id resource_status resource_status_reason) end |
#discover_stacks(stack) ⇒ Object
Discover stacks defined within the resources of given stack
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sfn/command/events.rb', line 81 def discover_stacks(stack) stack.resources.reload.all.each do |resource| if(resource.type == 'AWS::CloudFormation::Stack') nested_stack = provider.connection.stacks.get(resource.id) if(nested_stack) @stacks.push(nested_stack).uniq! discover_stacks(nested_stack) end end end end |
#execute! ⇒ Object
Run the events list action
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sfn/command/events.rb', line 14 def execute! name_required! name = name_args.first ui.info "Events for Stack: #{ui.color(name, :bold)}\n" @stacks = [] @stack = provider.connection.stacks.get(name) @stacks << stack discover_stacks(stack) if(stack) api_action!(:api_stack => stack) do table = ui.table(self) do table(:border => false) do events = get_events row(:header => true) do allowed_attributes.each do |attr| width_val = events.map{|e| e[attr].to_s.length}.push(attr.length).max + 2 width_val = width_val > 70 ? 70 : width_val < 20 ? 20 : width_val column attr.split('_').map(&:capitalize).join(' '), :width => width_val end end events.each do |event| row do allowed_attributes.each do |attr| column event[attr] end end end end end.display if(config[:poll]) while(stack.in_progress?) to_wait = config.fetch(:poll_wait_time, 10).to_f while(to_wait > 0) sleep(0.1) to_wait -= 0.1 end stack.reload table.display end end end else ui.fatal "Failed to locate requested stack: #{ui.color(name, :bold, :red)}" raise "Failed to locate stack: #{name}!" end end |
#get_events(*args) ⇒ Array<Hash>
Fetch events from stack
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sfn/command/events.rb', line 66 def get_events(*args) discover_stacks(stack) stack_events = @stacks.map do |stack| stack.events.all.map do |e| e.attributes.merge(:stack_name => stack.name).to_smash end end.flatten.compact.find_all{|e| e[:time] } stack_events.sort do |x,y| Time.parse(x[:time].to_s) <=> Time.parse(y[:time].to_s) end end |