lib/kumogata/client.rb in kumogata-0.3.2 vs lib/kumogata/client.rb in kumogata-0.3.3
- old
+ new
@@ -105,15 +105,20 @@
end
private ###########################################################
def open_template(path_or_url)
+ format = @options.format || (ruby_template?(path_or_url) ? :ruby : :json)
+
open(path_or_url) do |f|
- if ruby_template?(path_or_url)
+ case format
+ when :ruby
evaluate_template(f)
- else
+ when :json
JSON.parse(f.read)
+ else
+ raise "Unknown format: #{format}"
end
end
end
def ruby_template?(path_or_url)
@@ -322,20 +327,45 @@
resource_summaries_for(stack)
end
end
def while_in_progress(stack, complete_status)
+ event_log = {}
+
while stack.status =~ /_IN_PROGRESS\Z/
- print '.'.intense_black unless @options.debug?
+ print_event_log(stack, event_log)
sleep 1
end
+ print_event_log(stack, event_log)
completed = (stack.status == complete_status)
Kumogata.logger.info(completed ? 'Successfully' : 'Failed')
return completed
end
+ def print_event_log(stack, event_log)
+ events_for(stack).sort_by {|i| i['Timestamp'] }.each do |event|
+ event_id = event['EventId']
+
+ unless event_log[event_id]
+ event_log[event_id] = event
+
+ timestamp = event['Timestamp']
+ summary = {}
+
+ ['LogicalResourceId', 'ResourceStatus', 'ResourceStatusReason'].map do |k|
+ summary[k] = event[k]
+ end
+
+ puts [
+ timestamp.getlocal.strftime('%Y/%m/%d %H:%M:%S %Z'),
+ summary.to_json.colorize_as(:json),
+ ].join(': ')
+ end
+ end
+ end
+
def build_create_options
opts = {}
add_parameters(opts)
[:capabilities, :disable_rollback, :notify, :timeout].each do |k|
@@ -375,10 +405,10 @@
end
def update_deletion_policy(template)
if @options.delete_stack? or @options.deletion_policy_retain?
template['Resources'].each do |k, v|
- v['DeletionPolicy'] = 'Retain'
+ v['DeletionPolicy'] ||= 'Retain'
end
end
end
def add_encryption_password(template)