Merge pull request #705 from vijaykiran/issue-968

Issue 968:
This commit is contained in:
Adrian Cole 2012-07-09 16:36:57 -07:00
commit 333b77c628
2 changed files with 24 additions and 4 deletions

View File

@ -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<RunningInstance,
Builder<String> 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());

View File

@ -99,6 +99,21 @@ public class RunningInstanceToNodeMetadataTest {
"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.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses(
ImmutableSet.<String> 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();