groupNames = constructList(sgNameList);
// 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, null, groupIds, groupNames, 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.setIpAddress(resp.getIpAddress());
vm.setAccountName(resp.getAccountName());
vm.setDomainId(resp.getDomainId());
vm.setHypervisor(mapToAmazonHypervisorType(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;