lib/kumogata/client.rb in kumogata-0.3.9 vs lib/kumogata/client.rb in kumogata-0.3.10

- old
+ new

@@ -1,20 +1,24 @@ class Kumogata::Client def initialize(options) @options = options @options = Hashie::Mash.new(@options) unless @options.kind_of?(Hashie::Mash) @cloud_formation = AWS::CloudFormation.new + @post_processing = Kumogata::PostProcessing.new(@options) end def create(path_or_url, stack_name = nil) validate_stack_name(stack_name) @options.delete_stack = false if stack_name template = open_template(path_or_url) update_deletion_policy(template) add_encryption_password(template) - create_stack(template, stack_name) + + outputs = create_stack(template, stack_name) + @post_processing.run(:create, outputs) + nil end def validate(path_or_url) template = open_template(path_or_url) @@ -39,11 +43,14 @@ template = open(path_or_url) do |f| evaluate_template(f) end add_encryption_password(template) - update_stack(template, stack_name) + + outputs = update_stack(template, stack_name) + @post_processing.run(:update, outputs) + nil end def delete(stack_name) validate_stack_name(stack_name) @@ -139,20 +146,30 @@ else v.to_s end end - Dslh.eval(template.read, { + template = Dslh.eval(template.read, { :key_conv => key_converter, :value_conv => value_converter, :scope_hook => proc {|scope| define_template_func(scope, template.path) }, :filename => template.path, }) + + @post_processing.fetch!(template) + + return template end + def evaluate_after_trigger(template) + triggers = template.delete('_after') + return {} unless triggers + + end + def devaluate_template(template) exclude_key = proc do |k| k = k.to_s.gsub('::', '__') k !~ /\A[_a-z]\w+\Z/i and k !~ %r|\A/\S*\Z| end @@ -201,10 +218,19 @@ value = Dslh::ScopeBlock.nest(binding, 'block') end @__hash__[path] = value end + + def _post(options = {}, &block) + commands = Dslh::ScopeBlock.nest(binding, 'block') + + @__hash__[:_post] = { + :options => options, + :commands => commands, + } + end EOS end def create_stack(template, stack_name) unless stack_name @@ -235,10 +261,12 @@ if @options.delete_stack? delete_stack(stack_name) end output_result(stack_name, outputs, summaries) + + return outputs end def update_stack(template, stack_name) stack = @cloud_formation.stacks[stack_name] stack.status @@ -255,10 +283,12 @@ end outputs = outputs_for(stack) summaries = resource_summaries_for(stack) output_result(stack_name, outputs, summaries) + + return outputs end def delete_stack(stack_name) stack = @cloud_formation.stacks[stack_name] stack.status @@ -330,9 +360,11 @@ resource_summaries_for(stack) end end def while_in_progress(stack, complete_status, event_log) + # XXX: Status does not change if you have been memoized. + # Should be forcibly disabled memoization? while stack.status =~ /_IN_PROGRESS\Z/ print_event_log(stack, event_log) sleep 1 end