JCLOUDS-347: Implement a poor-mans rollback if CloudStack static NAT creation fails

This commit is contained in:
Hugo Trippaers 2013-10-15 14:10:10 +02:00 committed by Andrew Phillips
parent 7ab18ffbd3
commit f3303f03c3
1 changed files with 29 additions and 19 deletions

View File

@ -242,6 +242,7 @@ public class CloudStackComputeServiceAdapter implements
credentialsBuilder.password(vm.getPassword()); credentialsBuilder.password(vm.getPassword());
} }
try {
if (templateOptions.shouldSetupStaticNat()) { if (templateOptions.shouldSetupStaticNat()) {
Capabilities capabilities = client.getConfigurationApi().listCapabilities(); Capabilities capabilities = client.getConfigurationApi().listCapabilities();
// TODO: possibly not all network ids, do we want to do this // TODO: possibly not all network ids, do we want to do this
@ -262,6 +263,15 @@ public class CloudStackComputeServiceAdapter implements
} }
} }
} }
} catch (RuntimeException re) {
logger.error("-- exception after node has been created, trying to destroy the created virtualMachine(%s)", vm.getId());
try {
destroyNode(vm.getId());
} catch (RuntimeException re2) {
logger.debug("-- exception in exceptionHandler while executing destroyNode for virtualMachine(%s), ignoring and rethrowing original exception", vm.getId());
}
throw re;
}
return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId() + "", credentialsBuilder.build()); return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId() + "", credentialsBuilder.build());
} }