mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
11d5eadc72
commit
8296d41b5b
@ -1423,47 +1423,53 @@ public class EC2Engine extends ManagerBase {
|
||||
|
||||
// now actually deploy the vms
|
||||
for( int i=0; i < createInstances; i++ ) {
|
||||
CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(),
|
||||
request.getTemplateId(), zoneId, null, null, null, null,
|
||||
null, null, null, request.getKeyName(), null, (network != null ? network.getId() : null),
|
||||
null, constructList(request.getGroupSet()), request.getSize().longValue(), request.getUserData());
|
||||
EC2Instance vm = new EC2Instance();
|
||||
vm.setId(resp.getId().toString());
|
||||
vm.setName(resp.getName());
|
||||
vm.setZoneName(resp.getZoneName());
|
||||
vm.setTemplateId(resp.getTemplateId().toString());
|
||||
if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) {
|
||||
List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
|
||||
for (CloudStackSecurityGroup securityGroup : securityGroupList) {
|
||||
EC2SecurityGroup param = new EC2SecurityGroup();
|
||||
param.setId(securityGroup.getId());
|
||||
param.setName(securityGroup.getName());
|
||||
vm.addGroupName(param);
|
||||
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),
|
||||
null, constructList(request.getGroupSet()), request.getSize().longValue(), request.getUserData());
|
||||
EC2Instance vm = new EC2Instance();
|
||||
vm.setId(resp.getId().toString());
|
||||
vm.setName(resp.getName());
|
||||
vm.setZoneName(resp.getZoneName());
|
||||
vm.setTemplateId(resp.getTemplateId().toString());
|
||||
if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) {
|
||||
List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
|
||||
for (CloudStackSecurityGroup securityGroup : securityGroupList) {
|
||||
EC2SecurityGroup param = new EC2SecurityGroup();
|
||||
param.setId(securityGroup.getId());
|
||||
param.setName(securityGroup.getName());
|
||||
vm.addGroupName(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
vm.setState(resp.getState());
|
||||
vm.setCreated(resp.getCreated());
|
||||
List <CloudStackNic> nicList = resp.getNics();
|
||||
for (CloudStackNic nic : nicList) {
|
||||
if (nic.getIsDefault()) {
|
||||
vm.setPrivateIpAddress(nic.getIpaddress());
|
||||
break;
|
||||
vm.setState(resp.getState());
|
||||
vm.setCreated(resp.getCreated());
|
||||
List <CloudStackNic> nicList = resp.getNics();
|
||||
for (CloudStackNic nic : nicList) {
|
||||
if (nic.getIsDefault()) {
|
||||
vm.setPrivateIpAddress(nic.getIpaddress());
|
||||
break;
|
||||
}
|
||||
}
|
||||
vm.setIpAddress(resp.getIpAddress());
|
||||
vm.setAccountName(resp.getAccountName());
|
||||
vm.setDomainId(resp.getDomainId());
|
||||
vm.setHypervisor(resp.getHypervisor());
|
||||
vm.setServiceOffering( svcOffering.getName());
|
||||
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;
|
||||
}
|
||||
vm.setIpAddress(resp.getIpAddress());
|
||||
vm.setAccountName(resp.getAccountName());
|
||||
vm.setDomainId(resp.getDomainId());
|
||||
vm.setHypervisor(resp.getHypervisor());
|
||||
vm.setServiceOffering( svcOffering.getName());
|
||||
vm.setKeyPairName(resp.getKeyPairName());
|
||||
instances.addInstance(vm);
|
||||
countCreated++;
|
||||
}
|
||||
|
||||
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 ) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user