Class: AwsClient::CfWrapper

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/cf_wrapper.rb

Constant Summary collapse

STACK_COMPLETE_STATUS =
"CREATE_COMPLETE"
STACK_ROLLLBACK_STATUS =
"ROLLBACK_IN_PROGRESS"
STACK_WAIT_SLEEP_TIME =
3

Instance Attribute Summary

Attributes inherited from Wrapper

#client

Instance Method Summary collapse

Methods inherited from Wrapper

#initialize

Constructor Details

This class inherits a constructor from AwsClient::Wrapper

Instance Method Details

#create_stack(stack_params) ⇒ Object



8
9
10
11
12
# File 'lib/cf_wrapper.rb', line 8

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) ⇒ Object



30
31
32
33
34
# File 'lib/cf_wrapper.rb', line 30

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) ⇒ Object



36
37
38
# File 'lib/cf_wrapper.rb', line 36

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) ⇒ Object



48
49
50
# File 'lib/cf_wrapper.rb', line 48

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) ⇒ Object



44
45
46
# File 'lib/cf_wrapper.rb', line 44

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) ⇒ Object



19
20
21
22
23
24
# File 'lib/cf_wrapper.rb', line 19

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) ⇒ Object



26
27
28
# File 'lib/cf_wrapper.rb', line 26

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) ⇒ Object



40
41
42
# File 'lib/cf_wrapper.rb', line 40

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) ⇒ Object



14
15
16
17
# File 'lib/cf_wrapper.rb', line 14

def stack_status_for(stack_name)
  stack_info = stack_info_for(stack_name)
  return stack_info_for(stack_name).stack_status
end

#wait_for_stack(stack_name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cf_wrapper.rb', line 52

def wait_for_stack(stack_name)
  puts "Waiting for stack to spin up"
  status = ""
  while status != STACK_COMPLETE_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"
end