mirror of https://github.com/apache/jclouds.git
added lifecycle methods to cloudstack
This commit is contained in:
parent
56f1d7266a
commit
634a33fe5f
|
@ -83,6 +83,60 @@ public interface VirtualMachineAsyncClient {
|
|||
@QueryParam("templateid") long templateId, @QueryParam("zoneid") long zoneId,
|
||||
DeployVirtualMachineOptions... options);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#rebootVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "rebootVirtualMachine")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> rebootVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#startVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "startVirtualMachine")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> startVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#stopVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "stopVirtualMachine")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> stopVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#resetPasswordForVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "resetPasswordForVirtualMachine")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> resetPasswordForVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#changeServiceForVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "changeServiceForVirtualMachine")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> changeServiceForVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#updateVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "updateVirtualMachine")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<Long> updateVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#destroyVirtualMachine
|
||||
*/
|
||||
|
|
|
@ -71,6 +71,62 @@ public interface VirtualMachineClient {
|
|||
AsyncCreateResponse deployVirtualMachine(long serviceOfferingId, long templateId, long zoneId,
|
||||
DeployVirtualMachineOptions... options);
|
||||
|
||||
/**
|
||||
* Reboots a virtual machine.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the virtual machine
|
||||
* @return job id related to destroying the VM
|
||||
*/
|
||||
Long rebootVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* Starts a virtual machine.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the virtual machine
|
||||
* @return job id related to destroying the VM
|
||||
*/
|
||||
Long startVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* Stops a virtual machine.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the virtual machine
|
||||
* @return job id related to destroying the VM
|
||||
*/
|
||||
Long stopVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* Resets the password for virtual machine. The virtual machine must be in a "Stopped" state and
|
||||
* the template must already support this feature for this command to take effect.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the virtual machine
|
||||
* @return job id related to destroying the VM
|
||||
*/
|
||||
Long resetPasswordForVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* Changes the service offering for a virtual machine. The virtual machine must be in a "Stopped"
|
||||
* state for this command to take effect.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the virtual machine
|
||||
* @return job id related to destroying the VM
|
||||
*/
|
||||
Long changeServiceForVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* Updates parameters of a virtual machine.
|
||||
*
|
||||
* @param id
|
||||
* The ID of the virtual machine
|
||||
* @return job id related to destroying the VM
|
||||
*/
|
||||
Long updateVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* Destroys a virtual machine. Once destroyed, only the administrator can recover it.
|
||||
*
|
||||
|
|
|
@ -65,8 +65,8 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
|
|||
public void testListVirtualMachinesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("listVirtualMachines",
|
||||
ListVirtualMachinesOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,
|
||||
ListVirtualMachinesOptions.Builder.accountInDomain("adrian", 6).usesVirtualNetwork(true));
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListVirtualMachinesOptions.Builder.accountInDomain(
|
||||
"adrian", 6).usesVirtualNetwork(true));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
|
@ -118,6 +118,108 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest
|
|||
|
||||
}
|
||||
|
||||
public void testRebootVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("rebootVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=rebootVirtualMachine&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testStartVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("startVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=startVirtualMachine&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testStopVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("stopVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=stopVirtualMachine&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testResetPasswordForVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("resetPasswordForVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=resetPasswordForVirtualMachine&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testChangeServiceForVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("changeServiceForVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=changeServiceForVirtualMachine&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testUpdateVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("updateVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=updateVirtualMachine&id=5 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testDestroyVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("destroyVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 5);
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.testng.annotations.AfterGroups;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import static com.google.common.base.Predicates.*;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
|
@ -74,7 +75,8 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
@Override
|
||||
public boolean apply(Template arg0) {
|
||||
return arg0.getZoneId() == zone.getId() && arg0.isFeatured() && arg0.isReady();
|
||||
return arg0.getZoneId() == zone.getId() && arg0.isFeatured() && arg0.isReady()
|
||||
&& arg0.getOSType().equals("Ubuntu 10.04 (64-bit)");
|
||||
}
|
||||
|
||||
}).getId();
|
||||
|
@ -115,12 +117,35 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
return vm;
|
||||
}
|
||||
|
||||
public void testCreateDestroyVirtualMachine() throws Exception {
|
||||
public void testCreateVirtualMachine() throws Exception {
|
||||
vm = createVirtualMachine(client, jobComplete, virtualMachineRunning);
|
||||
assertEquals(vm.getRootDeviceType(), "NetworkFilesystem");
|
||||
assert or(equalTo("NetworkFilesystem"), equalTo("IscsiLUN")).apply(vm.getRootDeviceType()) : vm;
|
||||
checkVm(vm);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateVirtualMachine")
|
||||
public void testLifeCycle() throws Exception {
|
||||
Long job = client.getVirtualMachineClient().stopVirtualMachine(vm.getId());
|
||||
assert jobComplete.apply(job);
|
||||
vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId());
|
||||
assertEquals(vm.getState(), VirtualMachine.State.STOPPED);
|
||||
|
||||
job = client.getVirtualMachineClient().resetPasswordForVirtualMachine(vm.getId());
|
||||
assert jobComplete.apply(job);
|
||||
vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId());
|
||||
// TODO: check if error or not base on isPasswordEnabled
|
||||
|
||||
job = client.getVirtualMachineClient().startVirtualMachine(vm.getId());
|
||||
assert jobComplete.apply(job);
|
||||
vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId());
|
||||
assertEquals(vm.getState(), VirtualMachine.State.RUNNING);
|
||||
|
||||
job = client.getVirtualMachineClient().rebootVirtualMachine(vm.getId());
|
||||
assert jobComplete.apply(job);
|
||||
vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId());
|
||||
assertEquals(vm.getState(), VirtualMachine.State.RUNNING);
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (vm != null) {
|
||||
|
|
Loading…
Reference in New Issue