CLOUDSTACK-1330: ec2-run-instances - When -n option is used to deploy multiple Vms API returns error even though few of the Vms have been deployed successfully.

Changes:
- Instead of throwing out error, return the response containing the info about the instances that were launched.
This commit is contained in:
Prachi Damle 2013-02-19 15:12:06 -08:00
parent 11d5eadc72
commit 8296d41b5b

View File

@ -1423,6 +1423,7 @@ public class EC2Engine extends ManagerBase {
// now actually deploy the vms
for( int i=0; i < createInstances; i++ ) {
try{
CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(),
request.getTemplateId(), zoneId, null, null, null, null,
null, null, null, request.getKeyName(), null, (network != null ? network.getId() : null),
@ -1458,12 +1459,17 @@ public class EC2Engine extends ManagerBase {
vm.setKeyPairName(resp.getKeyPairName());
instances.addInstance(vm);
countCreated++;
}catch(Exception e){
logger.error("Failed to deploy VM number: "+ (i+1) +" due to error: "+e.getMessage());
break;
}
}
if (0 == countCreated) {
// TODO, we actually need to destroy left-over VMs when the exception is thrown
throw new EC2ServiceException(ServerError.InsufficientInstanceCapacity, "Insufficient Instance Capacity" );
throw new EC2ServiceException(ServerError.InternalError, "Failed to deploy instances" );
}
logger.debug("Could deploy "+ countCreated + " VM's successfully");
return instances;
} catch( Exception e ) {