lib/kumogata/client.rb in kumogata-0.2.8 vs lib/kumogata/client.rb in kumogata-0.2.9
- old
+ new
@@ -60,10 +60,15 @@
def export(stack_name)
template = export_template(stack_name)
devaluate_template(template).chomp
end
+ def show_events(stack_name)
+ events = describe_events(stack_name)
+ JSON.pretty_generate(events)
+ end
+
def show_outputs(stack_name)
outputs = describe_outputs(stack_name)
JSON.pretty_generate(outputs)
end
@@ -190,11 +195,11 @@
stack = @cloud_formation.stacks.create(stack_name, template.to_json, build_create_options)
unless while_in_progress(stack, 'CREATE_COMPLETE')
errmsgs = ['Create failed']
errmsgs << stack_name
- errmsgs << sstack.tatus_reason if stack.status_reason
+ errmsgs << stack.status_reason if stack.status_reason
raise errmsgs.join(': ')
end
outputs = outputs_for(stack)
summaries = resource_summaries_for(stack)
@@ -214,11 +219,11 @@
Kumogata.logger.info("Updating stack: #{stack_name}".green)
unless while_in_progress(stack, 'UPDATE_COMPLETE')
errmsgs = ['Update failed']
errmsgs << stack_name
- errmsgs << sstack.tatus_reason if stack.status_reason
+ errmsgs << stack.status_reason if stack.status_reason
raise errmsgs.join(': ')
end
outputs = outputs_for(stack)
summaries = resource_summaries_for(stack)
@@ -243,11 +248,11 @@
end
unless completed
errmsgs = ['Delete failed']
errmsgs << stack_name
- errmsgs << sstack.tatus_reason if stack.status_reason
+ errmsgs << stack.status_reason if stack.status_reason
raise errmsgs.join(': ')
end
end
def describe_stacks(stack_name)
@@ -270,10 +275,18 @@
stack = @cloud_formation.stacks[stack_name]
stack.status
JSON.parse(stack.template)
end
+ def describe_events(stack_name)
+ AWS.memoize do
+ stack = @cloud_formation.stacks[stack_name]
+ stack.status
+ events_for(stack)
+ end
+ end
+
def describe_outputs(stack_name)
AWS.memoize do
stack = @cloud_formation.stacks[stack_name]
stack.status
outputs_for(stack)
@@ -337,10 +350,34 @@
end
Kumogata.logger.info('Template validated successfully'.green)
end
+ def events_for(stack)
+ stack.events.map do |event|
+ event_hash = {}
+
+ [
+ :event_id,
+ :logical_resource_id,
+ :physical_resource_id,
+ :resource_properties,
+ :resource_status,
+ :resource_status_reason,
+ :resource_type,
+ :stack,
+ :stack_id,
+ :stack_name,
+ :timestamp,
+ ].each do |k|
+ event_hash[camelize(k)] = event.send(k)
+ end
+
+ event_hash
+ end
+ end
+
def outputs_for(stack)
outputs_hash = {}
stack.outputs.each do |output|
outputs_hash[output.key] = output.value
@@ -359,15 +396,11 @@
:resource_type,
:resource_status,
:resource_status_reason,
:last_updated_timestamp
].each do |k|
- camelcase = k.to_s.split(/[-_]/).map {|i|
- i[0, 1].upcase + i[1..-1].downcase
- }.join
-
- summary_hash[camelcase] = summary[k]
+ summary_hash[camelize(k)] = summary[k]
end
summary_hash
end
end
@@ -389,7 +422,13 @@
'StackName' => stack_name,
'Outputs' => outputs,
'StackResourceSummaries' => summaries,
})
end
+ end
+
+ def camelize(str)
+ str.to_s.split(/[-_]/).map {|i|
+ i[0, 1].upcase + i[1..-1].downcase
+ }.join
end
end