mirror of https://github.com/apache/jclouds.git
Fix: "auto" no longer being assigned to public IP of the node when the node has been started.
This commit is contained in:
parent
fd1a5dd04c
commit
efdf8b23bb
|
@ -123,7 +123,9 @@ public class ElasticStackComputeServiceAdapter implements
|
||||||
Server toCreate = small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()).cpu(
|
Server toCreate = small(name, drive.getUuid(), defaultVncPassword).mem(template.getHardware().getRam()).cpu(
|
||||||
(int) (template.getHardware().getProcessors().get(0).getSpeed())).build();
|
(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
|
// store the credentials so that later functions can use them
|
||||||
credentialStore.put(from.getUuid() + "", new Credentials(template.getImage().getDefaultCredentials().identity,
|
credentialStore.put(from.getUuid() + "", new Credentials(template.getImage().getDefaultCredentials().identity,
|
||||||
from.getVnc().getPassword()));
|
from.getVnc().getPassword()));
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class ServerInfoToNodeMetadata implements Function<ServerInfo, NodeMetada
|
||||||
.processors(ImmutableList.of(new Processor(1, from.getCpu()))).ram(from.getMem())
|
.processors(ImmutableList.of(new Processor(1, from.getCpu()))).ram(from.getMem())
|
||||||
.volumes((List) ImmutableList.of(Iterables.transform(from.getDevices().values(), deviceToVolume))).build());
|
.volumes((List) ImmutableList.of(Iterables.transform(from.getDevices().values(), deviceToVolume))).build());
|
||||||
builder.state(serverStatusToNodeState.get(from.getStatus()));
|
builder.state(serverStatusToNodeState.get(from.getStatus()));
|
||||||
builder.publicAddresses(ImmutableSet.<String> of(from.getVnc().getIp()));
|
builder.publicAddresses(ImmutableSet.<String> of(from.getNics().get(0).getDhcp()));
|
||||||
builder.privateAddresses(ImmutableSet.<String> of());
|
builder.privateAddresses(ImmutableSet.<String> of());
|
||||||
builder.credentials(credentialStore.get(from.getUuid()));
|
builder.credentials(credentialStore.get(from.getUuid()));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
|
@ -53,13 +53,10 @@ public class MapToNICs implements Function<Map<String, String>, List<NIC>> {
|
||||||
String key = String.format("nic:%d", id);
|
String key = String.format("nic:%d", id);
|
||||||
if (!from.containsKey(key + ":model"))
|
if (!from.containsKey(key + ":model"))
|
||||||
break NIC;
|
break NIC;
|
||||||
NIC.Builder nicBuilder = new NIC.Builder();
|
|
||||||
|
|
||||||
if (apiVersion.equals("2.0")) {
|
NIC.Builder nicBuilder = new NIC.Builder();
|
||||||
nicBuilder.dhcp(from.get(key + ":dhcp:ip"));
|
final String ip = getDhcpIp(from, key);
|
||||||
} else {
|
nicBuilder.dhcp(ip);
|
||||||
nicBuilder.dhcp(from.get(key + ":dhcp"));
|
|
||||||
}
|
|
||||||
nicBuilder.model(Model.fromValue(from.get(key + ":model")));
|
nicBuilder.model(Model.fromValue(from.get(key + ":model")));
|
||||||
nicBuilder.vlan(from.get(key + ":vlan"));
|
nicBuilder.vlan(from.get(key + ":vlan"));
|
||||||
nicBuilder.mac(from.get(key + ":mac"));
|
nicBuilder.mac(from.get(key + ":mac"));
|
||||||
|
@ -67,6 +64,17 @@ public class MapToNICs implements Function<Map<String, String>, List<NIC>> {
|
||||||
nicBuilder.block(Splitter.on(' ').split(from.get(key + ":block")));
|
nicBuilder.block(Splitter.on(' ').split(from.get(key + ":block")));
|
||||||
nics.add(nicBuilder.build());
|
nics.add(nicBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
return nics.build();
|
return nics.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDhcpIp(Map<String, String> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,32 +18,23 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.elasticstack.functions;
|
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.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class MapToServerInfo implements Function<Map<String, String>, ServerInfo> {
|
public class MapToServerInfo implements Function<Map<String, String>, ServerInfo> {
|
||||||
private String apiVersion;
|
|
||||||
private final Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices;
|
private final Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices;
|
||||||
private final Function<Map<String, String>, ServerMetrics> mapToMetrics;
|
private final Function<Map<String, String>, ServerMetrics> mapToMetrics;
|
||||||
private final Function<Map<String, String>, List<NIC>> mapToNICs;
|
private final Function<Map<String, String>, List<NIC>> mapToNICs;
|
||||||
|
@ -51,7 +42,6 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
||||||
@Inject
|
@Inject
|
||||||
public MapToServerInfo(Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices,
|
public MapToServerInfo(Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices,
|
||||||
Function<Map<String, String>, ServerMetrics> mapToMetrics, Function<Map<String, String>, List<NIC>> mapToNICs) {
|
Function<Map<String, String>, ServerMetrics> mapToMetrics, Function<Map<String, String>, List<NIC>> mapToNICs) {
|
||||||
this.apiVersion = apiVersion;
|
|
||||||
this.mapToDevices = mapToDevices;
|
this.mapToDevices = mapToDevices;
|
||||||
this.mapToMetrics = mapToMetrics;
|
this.mapToMetrics = mapToMetrics;
|
||||||
this.mapToNICs = mapToNICs;
|
this.mapToNICs = mapToNICs;
|
||||||
|
|
|
@ -104,6 +104,11 @@ public class MapToServerInfoTest {
|
||||||
private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()),
|
private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()),
|
||||||
new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs("1.0"));
|
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() {
|
public void testEmptyMapReturnsNull() {
|
||||||
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.<String, String> of()), null);
|
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.<String, String> of()), null);
|
||||||
}
|
}
|
||||||
|
@ -137,6 +142,7 @@ public class MapToServerInfoTest {
|
||||||
.name("adriancole.test")
|
.name("adriancole.test")
|
||||||
.vnc(new VNC("83.222.249.221", "XXXXXXXX", false))
|
.vnc(new VNC("83.222.249.221", "XXXXXXXX", false))
|
||||||
.nics(ImmutableSet.of(new NIC.Builder()
|
.nics(ImmutableSet.of(new NIC.Builder()
|
||||||
|
.dhcp("auto")
|
||||||
.model(Model.E1000)
|
.model(Model.E1000)
|
||||||
.block(
|
.block(
|
||||||
ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22",
|
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 {
|
public void testNew2() throws IOException {
|
||||||
|
|
||||||
Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply(
|
Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply(
|
||||||
Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server2.txt"))).get(0);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue