lib/cf_wrapper.rb in aws_client-0.0.2 vs lib/cf_wrapper.rb in aws_client-0.0.3

- old
+ new

@@ -1,18 +1,27 @@ module AwsClient class CfWrapper < Wrapper STACK_COMPLETE_STATUS = "CREATE_COMPLETE" + STACK_UPDATE_COMPLETE_STATUS = "UPDATE_COMPLETE" STACK_ROLLLBACK_STATUS = "ROLLBACK_IN_PROGRESS" STACK_WAIT_SLEEP_TIME = 3 def create_stack(stack_params) puts "Creating stack with the following parameters: #{stack_params.inspect}" response = client.create_stack(stack_params) wait_for_stack(stack_params[:stack_name]) end + # http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#update_stack-instance_method + def update_stack(stack_params) + puts "Updating stack with the following parameters: #{stack_params.inspect}" + response = client.update_stack(stack_params) + is_update = true + wait_for_stack(stack_params[:stack_name], is_update) + end + def stack_status_for(stack_name) stack_info = stack_info_for(stack_name) return stack_info_for(stack_name).stack_status end @@ -47,20 +56,22 @@ def physical_resource_id_for(stack_name, resource_name) resource_data_for_resource_name(stack_name, resource_name).physical_resource_id end - def wait_for_stack(stack_name) - puts "Waiting for stack to spin up" + def wait_for_stack(stack_name, is_update = false) + puts "Waiting for stack" status = "" - while status != STACK_COMPLETE_STATUS + end_status = is_update ? STACK_UPDATE_COMPLETE_STATUS : STACK_COMPLETE_STATUS + + while status != end_status status = stack_status_for(stack_name) puts "'#{stack_name}' stack status: #{status}" raise "Rollback in progress - CF build failed" if status == STACK_ROLLLBACK_STATUS sleep(STACK_WAIT_SLEEP_TIME) end - puts "Stack is up. Ready for bootstrapping" + puts "Stack is ready." end end end