properly set chef node name for instances

This commit is contained in:
Anton Chuchkalov 2015-09-16 12:14:01 +03:00
parent 9c21fc0fe4
commit 0dd550c37e
2 changed files with 27 additions and 13 deletions

View File

@ -254,21 +254,29 @@ module Provider
cloud_formation.describe_stack_resources({'StackName' => stack.name}).body['StackResources']
end
def stack_resource(stack, resource_id)
physical_id = fog_stack(stack).resources.get(resource_id).physical_resource_id
compute.servers.get(physical_id)
end
# не работает, не используется
# def stack_resource(stack, resource_id)
# physical_id = fog_stack(stack).resources.get(resource_id).physical_resource_id
# compute.servers.get(physical_id)
# end
def stack_servers(stack)
list = compute.describe_instances({'tag-key' => 'aws:cloudformation:stack-id', 'tag-value' => stack.id}).body["reservationSet"]
list.map do |l|
i = l["instancesSet"][0]
# orchestration.describe_stack_resources возвращает мало информации
list = compute.describe_instances(
'tag-key' => 'aws:cloudformation:stack-id',
'tag-value' => stack.id
).body["reservationSet"]
list.map do |instance|
info = instance["instancesSet"][0]
instance_logical_name = info["tagSet"]["Name"] || info['tagSet']['aws:cloudformation:logical-id']
{
'name' => i["tagSet"]["Name"],
'id' => i["instanceId"],
'key_name' => i["keyName"],
'private_ip' => i["privateIpAddress"],
'public_ip' => i["ipAddress"],
# 'name' => info["tagSet"]["Name"],
'name' => [stack.name, instance_logical_name].join('-'),
'id' => info["instanceId"],
'key_name' => info["keyName"],
'private_ip' => info["privateIpAddress"],
'public_ip' => info["ipAddress"],
}
end
end
@ -277,6 +285,7 @@ module Provider
"stack-#{self.ssh_key}-#{s.project}-#{s.deploy_env}-#{Time.now.to_i}".gsub('_', '-')
end
private
def convert_groups list
res = {}
list.each do |g|
@ -327,5 +336,9 @@ module Provider
r
end
def orchestration
@orchestration ||= Fog::AWS::CloudFormation.new(connection_options)
end
end
end

View File

@ -246,6 +246,7 @@ module Provider
end
def stack_resource(stack, resource_id)
fog_stack = orchestration.stacks.get(stack.name, stack.id)
physical_id = fog_stack(stack).resources.get(resource_id).physical_resource_id
compute.servers.get(physical_id)
end
@ -287,7 +288,7 @@ module Provider
end
def orchestration
@connection ||= Fog::Orchestration.new(connection_options)
@orchestration ||= Fog::Orchestration.new(connection_options)
end
end