Class: Chef::Knife::CfnEvents

Inherits:
CfnBase show all
Defined in:
lib/chef/knife/cfn_events.rb

Instance Method Summary collapse

Methods inherited from CfnBase

#connection, included, #is_image_windows?, #locate_config_value, #msg_pair, #validate!

Methods inherited from Chef::Knife

#create_create_def, #create_update_def, #iam_name_from_profile, #ini_parse

Instance Method Details

#runObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/chef/knife/cfn_events.rb', line 72

def run
  $stdout.sync = true

  validate!

  stack_name = @name_args[0]

  if stack_name.nil?
    show_usage
    ui.error("You must specify a stack name")
    exit 1
  end

  events_list = [
    ui.color('Event ID', :bold),
    ui.color('Stack ID', :bold),
    ui.color('Logical Resource Id', :bold),
    ui.color('Physical Resource Id', :bold),
    ui.color('Resource Type', :bold),
    ui.color('Timestamp', :bold),
    ui.color('Resource Status', :bold),
    ui.color('Resource Status Reason', :bold)
  ]
  @name_args.each do |stack_name|
    data = Array.new
    begin
      response = connection.describe_stack_events(stack_name)
      data = response.body['StackEvents']
    rescue Excon::Errors::BadRequest => e
      i= e.response.body.index("<Message>")
      j = e.response.body.index("</Message>")
      if !i.nil? and !j.nil?
        ui.error(e.response.body[i+9,j-i-9])
      else
        print "\n#{e.response.body}"
      end
      exit 1
    else
      data.each do |event|
        events_list << event['EventId']
        events_list << event['StackId']
        events_list << event['LogicalResourceId']
        events_list << event['PhysicalResourceId']
        events_list << event['ResourceType']
        events_list << event['Timestamp'].to_s
        events_list << event['ResourceStatus']
        events_list << event['ResourceStatusReason'].to_s
      end
      puts ui.list(events_list, :uneven_columns_across, 8)
    end
  end
end