mirror of https://github.com/apache/jclouds.git
Add DNS Name as public address when describe instance response doesn't contain IPAddress
This commit is contained in:
parent
3afe52662b
commit
e513757e1a
|
@ -50,6 +50,7 @@ import org.jclouds.ec2.domain.InstanceState;
|
||||||
import org.jclouds.ec2.domain.RootDeviceType;
|
import org.jclouds.ec2.domain.RootDeviceType;
|
||||||
import org.jclouds.ec2.domain.RunningInstance;
|
import org.jclouds.ec2.domain.RunningInstance;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.util.InetAddresses2;
|
||||||
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -116,6 +117,10 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
Builder<String> addressesBuilder = ImmutableSet.<String> builder();
|
Builder<String> addressesBuilder = ImmutableSet.<String> builder();
|
||||||
if (Strings.emptyToNull(instance.getIpAddress()) != null)
|
if (Strings.emptyToNull(instance.getIpAddress()) != null)
|
||||||
addressesBuilder.add(instance.getIpAddress());
|
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)
|
if (Strings.emptyToNull(instance.getPrivateIpAddress()) != null)
|
||||||
addressesBuilder.add(instance.getPrivateIpAddress());
|
addressesBuilder.add(instance.getPrivateIpAddress());
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() {
|
public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() {
|
||||||
RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
|
RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
|
||||||
|
@ -93,7 +93,22 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId(
|
ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId(
|
||||||
"us-east-1/image").providerId("id").build());
|
"us-east-1/image").providerId("id").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIPAddressIsSetToDnsNameWhenIPAddressIsNull() {
|
||||||
|
RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
|
||||||
|
.instanceState(InstanceState.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().state(NodeState.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")
|
static Location provider = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
|
||||||
.description("us-east-1").build();
|
.description("us-east-1").build();
|
||||||
|
|
||||||
|
@ -140,8 +155,8 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
.privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68"))
|
.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")
|
.imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f")
|
||||||
.location(provider).build();
|
.location(provider).build();
|
||||||
|
|
||||||
assertEquals(parser.apply(server), expected);
|
assertEquals(parser.apply(server).toString(), expected.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue