diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 465354da55..acb16fe549 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -50,6 +50,7 @@ import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.logging.Logger; +import org.jclouds.util.InetAddresses2; import org.jclouds.util.InetAddresses2.IsPrivateIPAddress; import com.google.common.annotations.VisibleForTesting; @@ -122,6 +123,10 @@ public class RunningInstanceToNodeMetadata implements Function addressesBuilder = ImmutableSet.builder(); if (Strings.emptyToNull(instance.getIpAddress()) != null) addressesBuilder.add(instance.getIpAddress()); + //Add dnsName (if available) to addresses, when the IPAddress is null + // happens on Eucalyptus sometimes. + else if(Strings.emptyToNull(instance.getDnsName()) != null) + addressesBuilder.add(instance.getDnsName()); if (Strings.emptyToNull(instance.getPrivateIpAddress()) != null) addressesBuilder.add(instance.getPrivateIpAddress()); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index d25ae27d54..f677c320d6 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -72,7 +72,7 @@ public class RunningInstanceToNodeMetadataTest { } } - + @Test public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") @@ -98,7 +98,22 @@ public class RunningInstanceToNodeMetadataTest { ImmutableSet. of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); } - + + @Test + public void testIPAddressIsSetToDnsNameWhenIPAddressIsNull() { + RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") + .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").dnsName("jclouds-1-1-1-1.jclouds.org").build(); + + RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet. of(), ImmutableSet + . of(), ImmutableSet. of(), ImmutableMap. of()); + + assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses( + ImmutableSet. of()).publicAddresses(ImmutableSet.of("jclouds-1-1-1-1.jclouds.org")).id("us-east-1/id").imageId( + "us-east-1/image").providerId("id").build().toString()); + + } + + static Location provider = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1") .description("us-east-1").build(); @@ -145,7 +160,7 @@ public class RunningInstanceToNodeMetadataTest { .privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f") .location(provider).build(); - + assertEquals(parser.apply(server).toString(), expected.toString()); } @@ -246,7 +261,7 @@ public class RunningInstanceToNodeMetadataTest { final ImmutableSet locations, final Set images, Map credentialStore) { Map instanceToNodeStatus = EC2ComputeServiceDependenciesModule.toPortableNodeStatus; - + CacheLoader getRealImage = new CacheLoader() { @Override