class AwsClient::CfWrapper

Constants

STACK_COMPLETE_STATUS
STACK_ROLLLBACK_STATUS
STACK_UPDATE_COMPLETE_STATUS
STACK_WAIT_SLEEP_TIME

Public Instance Methods

create_stack(stack_params) click to toggle source
# File lib/cf_wrapper.rb, line 9
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
ec2_server_stack_resource_for_node_name(stack_name, node_name) click to toggle source
# File lib/cf_wrapper.rb, line 39
def ec2_server_stack_resource_for_node_name(stack_name, node_name)
  server_resources = ec2_server_stack_resources(stack_name)
  server_resource = server_resources.select{|s| s.logical_resource_id == node_name}
  return server_resource
end
ec2_server_stack_resources(stack_name) click to toggle source
# File lib/cf_wrapper.rb, line 45
def ec2_server_stack_resources(stack_name)
  stack_resources_by_stack_name_and_resource_type(stack_name, "AWS::EC2::Instance")
end
physical_resource_id_for(stack_name, resource_name) click to toggle source
# File lib/cf_wrapper.rb, line 57
def physical_resource_id_for(stack_name, resource_name)
  resource_data_for_resource_name(stack_name, resource_name).physical_resource_id
end
resource_data_for_resource_name(stack_name, resource_name) click to toggle source
# File lib/cf_wrapper.rb, line 53
def resource_data_for_resource_name(stack_name, resource_name)
  stack_resources_for_stack(stack_name).select{|r| r.logical_resource_id == resource_name }.first
end
stack_info_for(stack_name) click to toggle source
# File lib/cf_wrapper.rb, line 28
def stack_info_for(stack_name)
  page = client.describe_stacks  
  stack_info = page.data.stacks.select{|stack| stack["stack_name"] == stack_name }
  raise "Cannot find CF stack named '#{stack_name}'" unless stack_info.any?
  return stack_info.last
end
stack_resources_by_stack_name_and_resource_type(stack_name, resource_type) click to toggle source
# File lib/cf_wrapper.rb, line 35
def stack_resources_by_stack_name_and_resource_type(stack_name, resource_type)
  return stack_resources_for_stack(stack_name).select{|r| r.resource_type == resource_type }  
end
stack_resources_for_stack(stack_name) click to toggle source
# File lib/cf_wrapper.rb, line 49
def stack_resources_for_stack(stack_name)
  @resources ||= client.describe_stack_resources("stack_name" => stack_name).data[:stack_resources]
end
stack_status_for(stack_name) click to toggle source
# File lib/cf_wrapper.rb, line 23
def stack_status_for(stack_name)
  stack_info = stack_info_for(stack_name)
  return stack_info_for(stack_name).stack_status
end
update_stack(stack_params) click to toggle source

docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#update_stack-instance_method

# File lib/cf_wrapper.rb, line 16
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
wait_for_stack(stack_name, is_update = false) click to toggle source
# File lib/cf_wrapper.rb, line 61
def wait_for_stack(stack_name, is_update = false)
  puts "Waiting for stack"
  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 ready."
end