some fixes

This commit is contained in:
amartynov 2015-08-17 17:50:24 +03:00
parent 78d10b6cbf
commit b622919bcf
5 changed files with 17 additions and 16 deletions

View File

@ -13,6 +13,7 @@ module StackCommands
sleep_times.each do |sleep_time| sleep_times.each do |sleep_time|
sleep sleep_time sleep sleep_time
stack.sync_details! stack.sync_details!
puts stack.stack_status
if stack.stack_status != 'CREATE_IN_PROGRESS' if stack.stack_status != 'CREATE_IN_PROGRESS'
mongo.stack_update(stack) mongo.stack_update(stack)
out << "Stack '#{stack.id}' status is now #{stack.stack_status}" out << "Stack '#{stack.id}' status is now #{stack.stack_status}"

View File

@ -59,7 +59,7 @@ module Devops
end end
def sync_details! def sync_details!
self.details = provider_instance.stack_details(self).attributes self.details = provider_instance.stack_details(self)#.attributes
end end
def resources def resources

View File

@ -7,6 +7,10 @@ module Devops
super(attr) super(attr)
end end
def stack_status
details['StackStatus'] if details
end
end end
end end
end end

View File

@ -235,15 +235,16 @@ module Provider
end end
def delete_stack(stack) def delete_stack(stack)
fog_stack(stack).destroy cloud_formation.delete_stack(stack.name)
end end
def stack_details(stack) def stack_details(stack)
fog_stack(stack).details d = cloud_formation.describe_stacks({'StackName' => stack.name}).body['Stacks'][0]['stack']
puts "Details: #{d.inspect}"
end end
def stack_resources(stack) def stack_resources(stack)
fog_stack(stack).resources cloud_formation.describe_stack_resources({'StackName' => stack.name}).body['StackResources']
end end
def stack_resource(stack, resource_id) def stack_resource(stack, resource_id)
@ -252,7 +253,7 @@ module Provider
end end
def stack_servers(stack) def stack_servers(stack)
fog_stack(stack).resources.map{|r| compute.servers.get(r.physical_resource_id)} stack_resources(stack).map{|r| compute.servers.get(r.physical_resource_id)}
end end
private private
@ -306,8 +307,5 @@ module Provider
r r
end end
def fog_stack(stack)
cloud_formation.stacks.get(stack.name, stack.id)
end
end end
end end

View File

@ -200,12 +200,14 @@ module Provider
out << "Stack template: #{stack.stack_template}\n" out << "Stack template: #{stack.stack_template}\n"
out << "Stack parameters: #{stack.parameters}\n" out << "Stack parameters: #{stack.parameters}\n"
out << "Stack template: #{stack.template_body}\n" out << "Stack template: #{stack.template_body}\n"
out.flush
response = orchestration.create_stack( response = orchestration.create_stack(
stack_name: stack.name, stack_name: stack.name,
template: stack.template_body, template: stack.template_body,
parameters: stack.parameters || {} parameters: stack.parameters || {}
) )
stack.id = response[:body]['stack']['id'] stack.id = response[:body]['stack']['id']
out << "Stack id: #{stack.id}\n"
rescue Excon::Errors::Conflict => e rescue Excon::Errors::Conflict => e
raise ProviderErrors::NameConflict raise ProviderErrors::NameConflict
rescue Excon::Errors::BadRequest => br rescue Excon::Errors::BadRequest => br
@ -223,15 +225,15 @@ module Provider
end end
def delete_stack(stack) def delete_stack(stack)
fog_stack(stack).destroy orchestration.delete_stack(Fog::Orchestration::OpenStack::Stack.new({'id' => stack.id, 'stack_name' => stack.name}))
end end
def stack_details(stack) def stack_details(stack)
fog_stack(stack).details orchestration.show_stack_details(stack.name, stack.id).body['stack']
end end
def stack_resources(stack) def stack_resources(stack)
fog_stack(stack).resources orchestration.list_resources(Fog::Orchestration::OpenStack::Stack.new({'id' => stack.id, 'stack_name' => stack.name})).body['resources']
end end
def stack_resource(stack, resource_id) def stack_resource(stack, resource_id)
@ -240,7 +242,7 @@ module Provider
end end
def stack_servers(stack) def stack_servers(stack)
fog_stack(stack).resources.map{|r| compute.servers.get(r.physical_resource_id)} stack_resources(stack).map{|r| compute.servers.get(r['physical_resource_id'])}
end end
private private
@ -268,9 +270,5 @@ module Provider
@connection ||= Fog::Orchestration.new(connection_options) @connection ||= Fog::Orchestration.new(connection_options)
end end
def fog_stack(stack)
orchestration.stacks.get(stack.name, stack.id)
end
end end
end end