mirror of https://github.com/apache/jclouds.git
Merge pull request #699 from sunf2002/master
Add startServer() and stopServer in serverClient corresponding to openstack API.
This commit is contained in:
commit
88e58a4048
|
@ -60,7 +60,7 @@ public class Server extends Resource {
|
||||||
*/
|
*/
|
||||||
public static enum Status {
|
public static enum Status {
|
||||||
|
|
||||||
ACTIVE, BUILD, REBUILD, SUSPENDED, PAUSED, RESIZE, VERIFY_RESIZE, REVERT_RESIZE, PASSWORD, REBOOT, HARD_REBOOT, DELETED, UNKNOWN, ERROR, UNRECOGNIZED;
|
ACTIVE, BUILD, REBUILD, SUSPENDED, PAUSED, RESIZE, VERIFY_RESIZE, REVERT_RESIZE, PASSWORD, REBOOT, HARD_REBOOT, DELETED, UNKNOWN, ERROR, STOPPED, UNRECOGNIZED;
|
||||||
|
|
||||||
public String value() {
|
public String value() {
|
||||||
return name();
|
return name();
|
||||||
|
|
|
@ -107,6 +107,26 @@ public interface ServerAsyncClient {
|
||||||
@Path("/servers/{id}")
|
@Path("/servers/{id}")
|
||||||
ListenableFuture<Boolean> deleteServer(@PathParam("id") String id);
|
ListenableFuture<Boolean> deleteServer(@PathParam("id") String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ServerClient#startServer
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/servers/{id}/action")
|
||||||
|
@Consumes
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Payload("{\"os-start\":null}")
|
||||||
|
ListenableFuture<Void> startServer(@PathParam("id") String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ServerClient#stopServer
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/servers/{id}/action")
|
||||||
|
@Consumes
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Payload("{\"os-stop\":null}")
|
||||||
|
ListenableFuture<Void> stopServer(@PathParam("id") String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ServerClient#rebootServer
|
* @see ServerClient#rebootServer
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -91,7 +91,23 @@ public interface ServerClient {
|
||||||
* @return True if successful, False otherwise
|
* @return True if successful, False otherwise
|
||||||
*/
|
*/
|
||||||
Boolean deleteServer(String id);
|
Boolean deleteServer(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a server
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the server
|
||||||
|
*/
|
||||||
|
void startServer(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop a server
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the server
|
||||||
|
*/
|
||||||
|
void stopServer(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reboot a server.
|
* Reboot a server.
|
||||||
*
|
*
|
||||||
|
|
|
@ -187,5 +187,99 @@ public class ServerClientExpectTest extends BaseNovaClientExpectTest {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testStopServerWhenResponseIs2xx() throws Exception {
|
||||||
|
String serverId = "123";
|
||||||
|
HttpRequest stopServer = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/action"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder().put("Accept", "*/*")
|
||||||
|
.put("X-Auth-Token", authToken).build())
|
||||||
|
.payload(payloadFromStringWithContentType(
|
||||||
|
"{\"os-stop\":null}", "application/json"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse stopServerResponse = HttpResponse.builder().statusCode(202).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
|
responseWithKeystoneAccess, stopServer, stopServerResponse);
|
||||||
|
|
||||||
|
clientWhenServerExists.getServerClientForZone("az-1.region-a.geo-1").stopServer(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStopServerWhenResponseIs404() throws Exception {
|
||||||
|
String serverId = "123";
|
||||||
|
HttpRequest stopServer = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/action"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder().put("Accept", "*/*")
|
||||||
|
.put("X-Auth-Token", authToken).build())
|
||||||
|
.payload(payloadFromStringWithContentType(
|
||||||
|
"{\"os-stop\":null}", "application/json"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse stopServerResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
|
responseWithKeystoneAccess, stopServer, stopServerResponse);
|
||||||
|
|
||||||
|
try {
|
||||||
|
clientWhenServerExists.getServerClientForZone("az-1.region-a.geo-1").stopServer(serverId);
|
||||||
|
fail("Expected an exception.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStartServerWhenResponseIs2xx() throws Exception {
|
||||||
|
String serverId = "123";
|
||||||
|
HttpRequest startServer = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/action"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder().put("Accept", "*/*")
|
||||||
|
.put("X-Auth-Token", authToken).build())
|
||||||
|
.payload(payloadFromStringWithContentType(
|
||||||
|
"{\"os-start\":null}", "application/json"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse startServerResponse = HttpResponse.builder().statusCode(202).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
|
responseWithKeystoneAccess, startServer, startServerResponse);
|
||||||
|
|
||||||
|
clientWhenServerExists.getServerClientForZone("az-1.region-a.geo-1").startServer(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStartServerWhenResponseIs404() throws Exception {
|
||||||
|
String serverId = "123";
|
||||||
|
HttpRequest startServer = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/" + serverId + "/action"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder().put("Accept", "*/*")
|
||||||
|
.put("X-Auth-Token", authToken).build())
|
||||||
|
.payload(payloadFromStringWithContentType(
|
||||||
|
"{\"os-startp\":null}", "application/json"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse startServerResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||||
|
responseWithKeystoneAccess, startServer, startServerResponse);
|
||||||
|
|
||||||
|
try {
|
||||||
|
clientWhenServerExists.getServerClientForZone("az-1.region-a.geo-1").startServer(serverId);
|
||||||
|
fail("Expected an exception.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue