openstack-nova: Wiring AdminActions extension into compute service to implement suspend and resume

This commit is contained in:
Adam Lowe 2012-05-04 16:44:32 +01:00
parent 7678c6e776
commit 33b4a2d253
2 changed files with 22 additions and 4 deletions

View File

@ -219,12 +219,20 @@ public class NovaComputeServiceAdapter implements
@Override @Override
public void resumeNode(String id) { public void resumeNode(String id) {
throw new UnsupportedOperationException("suspend not supported"); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaClient.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaClient.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().resumeServer(zoneAndId.getId());
}
throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension");
} }
@Override @Override
public void suspendNode(String id) { public void suspendNode(String id) {
throw new UnsupportedOperationException("suspend not supported"); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaClient.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaClient.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().suspendServer(zoneAndId.getId());
}
throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension");
} }
} }

View File

@ -1,10 +1,13 @@
package org.jclouds.openstack.nova.v1_1.compute; package org.jclouds.openstack.nova.v1_1.compute;
import static java.util.logging.Logger.getAnonymousLogger;
import java.util.Properties; import java.util.Properties;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.nova.v1_1.config.NovaProperties; import org.jclouds.openstack.nova.v1_1.config.NovaProperties;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -31,9 +34,16 @@ public class NovaComputeServiceLiveTest extends BaseComputeServiceLiveTest {
// start call is blocking anyway. // start call is blocking anyway.
} }
@Test(enabled = true, dependsOnMethods = "testReboot", expectedExceptions = UnsupportedOperationException.class) @Test(enabled = true, dependsOnMethods = "testReboot")
public void testSuspendResume() throws Exception { public void testSuspendResume() throws Exception {
super.testSuspendResume(); try {
// may fail because of lack of AdminActions extension or non-admin user, so log and continue
super.testSuspendResume();
} catch (AuthorizationException e) {
getAnonymousLogger().info("testSuspendResume() threw, probably due to lack of privileges: " + e.getMessage());
} catch (UnsupportedOperationException e) {
getAnonymousLogger().info("testSuspendResume() threw, probably due to unavailable AdminActions extension: " + e.getMessage());
}
} }
@Test(enabled = true, dependsOnMethods = "testSuspendResume") @Test(enabled = true, dependsOnMethods = "testSuspendResume")