mirror of https://github.com/apache/jclouds.git
JCLOUDS-350 rebuild server for Openstack NOVA added more options: password, name, ipv6 and ipv4 addresses.
This commit is contained in:
parent
1c9d1676cd
commit
fb11c1fc1a
|
@ -31,21 +31,33 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
* @author Inbar Stolberg
|
||||||
*/
|
*/
|
||||||
public class RebuildServerOptions implements MapBinder {
|
public class RebuildServerOptions implements MapBinder {
|
||||||
@Inject
|
@Inject
|
||||||
private BindToJsonPayload jsonBinder;
|
private BindToJsonPayload jsonBinder;
|
||||||
String imageRef;
|
String imageRef;
|
||||||
|
String name;
|
||||||
|
String adminPass;
|
||||||
|
String accessIPv4;
|
||||||
|
String accessIPv6;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||||
Map<String, String> image = Maps.newHashMap();
|
Map<String, String> image = Maps.newHashMap();
|
||||||
if (imageRef != null)
|
if (imageRef != null)
|
||||||
image.put("imageRef", imageRef);
|
image.put("imageRef", imageRef);
|
||||||
|
if (name != null)
|
||||||
|
image.put("name", name);
|
||||||
|
if (adminPass != null)
|
||||||
|
image.put("adminPass", adminPass);
|
||||||
|
if (accessIPv4 != null)
|
||||||
|
image.put("accessIPv4", accessIPv4);
|
||||||
|
if (accessIPv6 != null)
|
||||||
|
image.put("accessIPv6", accessIPv6);
|
||||||
|
|
||||||
|
|
||||||
return jsonBinder.bindToRequest(request, ImmutableMap.of("rebuild", image));
|
return jsonBinder.bindToRequest(request, ImmutableMap.of("rebuild", image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +77,26 @@ public class RebuildServerOptions implements MapBinder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RebuildServerOptions name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RebuildServerOptions adminPass(String adminPass) {
|
||||||
|
this.adminPass = adminPass;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RebuildServerOptions ipv4Address(String ipv4Address) {
|
||||||
|
this.accessIPv4 = ipv4Address;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RebuildServerOptions ipv6Address(String iPv6Address) {
|
||||||
|
this.accessIPv6 = iPv6Address;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,5 +106,37 @@ public class RebuildServerOptions implements MapBinder {
|
||||||
RebuildServerOptions options = new RebuildServerOptions();
|
RebuildServerOptions options = new RebuildServerOptions();
|
||||||
return options.withImage(ref);
|
return options.withImage(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RebuildServerOptions#name(String)
|
||||||
|
*/
|
||||||
|
public static RebuildServerOptions name(String name) {
|
||||||
|
RebuildServerOptions options = new RebuildServerOptions();
|
||||||
|
return options.name(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RebuildServerOptions#adminPass(String)
|
||||||
|
*/
|
||||||
|
public static RebuildServerOptions adminPass(String adminPass) {
|
||||||
|
RebuildServerOptions options = new RebuildServerOptions();
|
||||||
|
return options.adminPass(adminPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RebuildServerOptions#ipv4Address(String)
|
||||||
|
*/
|
||||||
|
public static RebuildServerOptions ipv4Address(String ipv4Address) {
|
||||||
|
RebuildServerOptions options = new RebuildServerOptions();
|
||||||
|
return options.ipv4Address(ipv4Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RebuildServerOptions#ipv6Address(String)
|
||||||
|
*/
|
||||||
|
public static RebuildServerOptions ipv6Address(String ipv6Address) {
|
||||||
|
RebuildServerOptions options = new RebuildServerOptions();
|
||||||
|
return options.ipv6Address(ipv6Address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.jclouds.openstack.nova.v2_0.NovaApi;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||||
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
|
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
||||||
|
import org.jclouds.openstack.nova.v2_0.options.RebuildServerOptions;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest;
|
import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest;
|
||||||
|
@ -229,6 +230,28 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
|
||||||
new ParseCreatedServerTest().expectedWithDiskConfig(Server.DISK_CONFIG_MANUAL).toString());
|
new ParseCreatedServerTest().expectedWithDiskConfig(Server.DISK_CONFIG_MANUAL).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRebuildServerWhenResponseIs202() throws Exception {
|
||||||
|
String serverId = "52415800-8b69-11e0-9b19-734f565bc83b";
|
||||||
|
HttpRequest rebuildServer = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId +"/action")
|
||||||
|
.addHeader("Accept", "*/*")
|
||||||
|
.addHeader("X-Auth-Token", authToken)
|
||||||
|
.payload(payloadFromStringWithContentType(
|
||||||
|
"{\"rebuild\":{\"adminPass\":\"password\",\"imageRef\":\"1234\",\"name\":\"newName\",\"accessIPv4\":\"1.1.1.1\",\"accessIPv6\":\"fe80::100\"}}","application/json"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse rebuildServerResponse = HttpResponse.builder().statusCode(202).build();
|
||||||
|
|
||||||
|
NovaApi apiRebuildServer = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
|
responseWithKeystoneAccess, rebuildServer, rebuildServerResponse);
|
||||||
|
|
||||||
|
RebuildServerOptions options = new RebuildServerOptions().withImage("1234").name("newName").adminPass("password").ipv4Address("1.1.1.1").ipv6Address("fe80::100");
|
||||||
|
|
||||||
|
apiRebuildServer.getServerApiForZone("az-1.region-a.geo-1").rebuild(serverId, options);
|
||||||
|
}
|
||||||
|
|
||||||
public void testCreateImageWhenResponseIs2xx() throws Exception {
|
public void testCreateImageWhenResponseIs2xx() throws Exception {
|
||||||
String serverId = "123";
|
String serverId = "123";
|
||||||
String imageId = "456";
|
String imageId = "456";
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.jclouds.openstack.nova.v2_0.domain.Server;
|
||||||
import org.jclouds.openstack.nova.v2_0.domain.ServerCreated;
|
import org.jclouds.openstack.nova.v2_0.domain.ServerCreated;
|
||||||
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
|
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
|
||||||
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
|
||||||
|
import org.jclouds.openstack.nova.v2_0.options.RebuildServerOptions;
|
||||||
import org.jclouds.openstack.v2_0.domain.Link.Relation;
|
import org.jclouds.openstack.v2_0.domain.Link.Relation;
|
||||||
import org.jclouds.openstack.v2_0.domain.Resource;
|
import org.jclouds.openstack.v2_0.domain.Resource;
|
||||||
import org.jclouds.openstack.v2_0.predicates.LinkPredicates;
|
import org.jclouds.openstack.v2_0.predicates.LinkPredicates;
|
||||||
|
@ -105,6 +106,51 @@ public class ServerApiLiveTest extends BaseNovaApiLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRebuildServer() {
|
||||||
|
|
||||||
|
String serverId = null;
|
||||||
|
|
||||||
|
for (String zoneId : zones) {
|
||||||
|
ServerApi serverApi = api.getServerApiForZone(zoneId);
|
||||||
|
try {
|
||||||
|
serverId = createServer(zoneId, Server.Status.ACTIVE).getId();
|
||||||
|
|
||||||
|
Server server = serverApi.get(serverId);
|
||||||
|
|
||||||
|
assertEquals(server.getStatus(), Server.Status.ACTIVE);
|
||||||
|
|
||||||
|
RebuildServerOptions options = new RebuildServerOptions().
|
||||||
|
withImage(server.getImage().getId()).
|
||||||
|
name("newName").
|
||||||
|
adminPass("password").
|
||||||
|
ipv4Address("1.1.1.1").
|
||||||
|
ipv6Address("fe80::100");
|
||||||
|
|
||||||
|
serverApi.rebuild(serverId, options);
|
||||||
|
|
||||||
|
Server rebuiltServer = serverApi.get(serverId);
|
||||||
|
|
||||||
|
assertEquals("newName", rebuiltServer.getName());
|
||||||
|
assertEquals("1.1.1.1", rebuiltServer.getAccessIPv4());
|
||||||
|
assertEquals("fe80::100", rebuiltServer.getAccessIPv6());
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
serverApi.delete(serverId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Server createServer(String regionId, Server.Status serverStatus) {
|
||||||
|
ServerApi serverApi = api.getServerApiForZone(regionId);
|
||||||
|
CreateServerOptions options = new CreateServerOptions();
|
||||||
|
ServerCreated server = serverApi.create(hostName, imageIdForZone(regionId), flavorRefForZone(regionId), options);
|
||||||
|
|
||||||
|
blockUntilServerInState(server.getId(), serverApi, serverStatus);
|
||||||
|
|
||||||
|
return serverApi.get(server.getId());
|
||||||
|
}
|
||||||
|
|
||||||
private Server createServer(String regionId, String availabilityZoneId, Server.Status serverStatus) {
|
private Server createServer(String regionId, String availabilityZoneId, Server.Status serverStatus) {
|
||||||
ServerApi serverApi = api.getServerApiForZone(regionId);
|
ServerApi serverApi = api.getServerApiForZone(regionId);
|
||||||
CreateServerOptions options = new CreateServerOptions();
|
CreateServerOptions options = new CreateServerOptions();
|
||||||
|
|
Loading…
Reference in New Issue