Skip to content

Commit

Permalink
Much better way to get an instance's internal IP.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Sep 29, 2010
1 parent 95af0c5 commit dcf97a3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/rubber/cloud/aws.rb
Expand Up @@ -38,8 +38,9 @@ def describe_instances(instance_id=nil)
instance = {}
instance[:id] = item.instanceId
instance[:external_host] = item.dnsName
instance[:external_ip] = IPSocket.getaddress(instance[:external_host]) rescue nil
instance[:external_ip] = item.ipAddress
instance[:internal_host] = item.privateDnsName
instance[:internal_ip] = item.privateIpAddress
instance[:state] = item.instanceState.name
instance[:zone] = item.placement.availabilityZone
instance[:platform] = item.platform || 'linux'
Expand Down
13 changes: 1 addition & 12 deletions lib/rubber/recipes/rubber/instances.rb
Expand Up @@ -239,6 +239,7 @@ def refresh_instance(instance_alias)
instance_item.external_host = instance[:external_host]
instance_item.external_ip = instance[:external_ip]
instance_item.internal_host = instance[:internal_host]
instance_item.internal_ip = instance[:internal_ip]
instance_item.zone = instance[:zone]
instance_item.platform = instance[:platform]
rubber_instances.save()
Expand Down Expand Up @@ -270,18 +271,6 @@ def refresh_instance(instance_alias)
# re-load the roles since we may have just defined new ones
load_roles() unless env.disable_auto_roles

# There's no good way to get the internal IP for a Windows host, so just set it to the external
# and let the router handle mapping to the internal network.
if instance_item.windows?
instance_item.internal_ip = instance_item.external_ip
else
# Connect to newly created instance and grab its internal ip
# so that we can update all aliases
direct_connection(instance_item.external_ip) do
instance_item.internal_ip = capture(print_ip_command).strip
end
end

rubber_instances.save()

# Add the aliases for this instance to all other hosts
Expand Down

0 comments on commit dcf97a3

Please sign in to comment.