Class: AwsClient::CfWrapper
Constant Summary
collapse
- STACK_COMPLETE_STATUS =
"CREATE_COMPLETE"
- STACK_UPDATE_COMPLETE_STATUS =
"UPDATE_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
Instance Method Details
#create_stack(stack_params) ⇒ Object
9
10
11
12
13
|
# 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) ⇒ Object
39
40
41
42
43
|
# 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) ⇒ Object
45
46
47
|
# 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) ⇒ Object
57
58
59
|
# 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) ⇒ Object
53
54
55
|
# 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) ⇒ Object
28
29
30
31
32
33
|
# 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) ⇒ Object
35
36
37
|
# 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) ⇒ Object
49
50
51
|
# 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) ⇒ Object
23
24
25
26
|
# 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) ⇒ Object
16
17
18
19
20
21
|
# 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) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# 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
|