diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java index 254a53a88c..ac9110d1bc 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java @@ -126,7 +126,9 @@ public class ElasticStackComputeServiceAdapter implements Server toCreate = small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()).cpu( (int) (template.getHardware().getProcessors().get(0).getSpeed())).build(); - ServerInfo from = client.createAndStartServer(toCreate); + ServerInfo from = client.createServer(toCreate); + client.startServer(from.getUuid()); + from = client.getServerInfo(from.getUuid()); // store the credentials so that later functions can use them credentialStore.put("node#"+ from.getUuid(), new Credentials(template.getImage().getDefaultCredentials().identity, from.getVnc().getPassword())); diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java index 59e868749b..eea5cc077b 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java @@ -18,40 +18,27 @@ */ package org.jclouds.elasticstack.compute.functions; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.collect.FindResourceInSet; -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.VolumeBuilder; -import org.jclouds.domain.Credentials; -import org.jclouds.domain.Location; -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.DriveInfo; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.domain.ServerStatus; - import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.*; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.elasticstack.domain.*; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; /** * @author Adrian Cole @@ -104,7 +91,7 @@ public class ServerInfoToNodeMetadata implements Function of(from.getVnc().getIp())); + builder.publicAddresses(ImmutableSet. of(from.getNics().get(0).getDhcp())); builder.privateAddresses(ImmutableSet. of()); builder.credentials(credentialStore.get("node#"+ from.getUuid())); return builder.build(); diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java index 3c2cce8087..b4a12fd75f 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java @@ -53,13 +53,10 @@ public class MapToNICs implements Function, List> { String key = String.format("nic:%d", id); if (!from.containsKey(key + ":model")) break NIC; + NIC.Builder nicBuilder = new NIC.Builder(); - - if (apiVersion.equals("2.0")) { - nicBuilder.dhcp(from.get(key + ":dhcp:ip")); - } else { - nicBuilder.dhcp(from.get(key + ":dhcp")); - } + final String ip = getDhcpIp(from, key); + nicBuilder.dhcp(ip); nicBuilder.model(Model.fromValue(from.get(key + ":model"))); nicBuilder.vlan(from.get(key + ":vlan")); nicBuilder.mac(from.get(key + ":mac")); @@ -67,6 +64,17 @@ public class MapToNICs implements Function, List> { nicBuilder.block(Splitter.on(' ').split(from.get(key + ":block"))); nics.add(nicBuilder.build()); } + return nics.build(); } + + private String getDhcpIp(Map from, String key) { + if (apiVersion.equals("2.0")) { + final String ip = from.get(key + ":dhcp:ip"); + return (ip == null ? "auto" : ip); + } else { + final String ip = from.get(key + ":dhcp"); + return (ip == null ? "auto" : ip); + } + } } \ No newline at end of file diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java index 3188fc4e99..f9170e9cd9 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java @@ -18,32 +18,23 @@ */ package org.jclouds.elasticstack.functions; +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Maps; +import org.jclouds.elasticstack.domain.*; + +import javax.inject.Inject; +import javax.inject.Singleton; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.elasticstack.domain.Device; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.ServerInfo; -import org.jclouds.elasticstack.domain.ServerMetrics; -import org.jclouds.elasticstack.domain.ServerStatus; -import org.jclouds.elasticstack.domain.VNC; - -import com.google.common.base.Function; -import com.google.common.base.Splitter; -import com.google.common.collect.Maps; -import org.jclouds.rest.annotations.ApiVersion; - /** * @author Adrian Cole */ @Singleton public class MapToServerInfo implements Function, ServerInfo> { - private String apiVersion; private final Function, Map> mapToDevices; private final Function, ServerMetrics> mapToMetrics; private final Function, List> mapToNICs; @@ -51,7 +42,6 @@ public class MapToServerInfo implements Function, ServerInfo @Inject public MapToServerInfo(Function, Map> mapToDevices, Function, ServerMetrics> mapToMetrics, Function, List> mapToNICs) { - this.apiVersion = apiVersion; this.mapToDevices = mapToDevices; this.mapToMetrics = mapToMetrics; this.mapToNICs = mapToNICs; diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java index 9c4aa0d76a..0afdf33548 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java @@ -104,6 +104,11 @@ public class MapToServerInfoTest { private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()), new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs("1.0")); + + private static final MapToServerInfo MAP_TO_DRIVE_2_0 = new MapToServerInfo(new MapToDevices(new DeviceToId()), + new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs("2.0")); + + public void testEmptyMapReturnsNull() { assertEquals(MAP_TO_DRIVE.apply(ImmutableMap. of()), null); } @@ -137,6 +142,7 @@ public class MapToServerInfoTest { .name("adriancole.test") .vnc(new VNC("83.222.249.221", "XXXXXXXX", false)) .nics(ImmutableSet.of(new NIC.Builder() + .dhcp("auto") .model(Model.E1000) .block( ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22", @@ -159,13 +165,12 @@ public class MapToServerInfoTest { } - public void testNew2() throws IOException { Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server2.txt"))).get(0); - assertEquals(MAP_TO_DRIVE.apply(input), NEW); + assertEquals(MAP_TO_DRIVE_2_0.apply(input), NEW); } } \ No newline at end of file