Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface VmDetailConstants {
String ROOT_DISK_SIZE = "rootdisksize";
String BOOT_MODE = "boot.mode";
String NAME_ON_HYPERVISOR= "nameonhypervisor";
String CLUSTER_ID = "clusterid";

// VMware specific
String NIC_ADAPTER = "nicAdapter";
Expand Down
30 changes: 26 additions & 4 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import javax.xml.parsers.ParserConfigurationException;

import com.cloud.agent.api.StartCommand;
import com.cloud.dc.ClusterVO;
import com.cloud.network.NetworkService;
import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao;
import org.apache.cloudstack.acl.ControlledEntity;
Expand Down Expand Up @@ -3641,7 +3642,13 @@ public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, Con
additonalParams.put(VirtualMachineProfile.Param.ConsiderLastHost, cmd.getConsiderLastHost().toString());
}

return startVirtualMachine(cmd.getId(), cmd.getPodId(), cmd.getClusterId(), cmd.getHostId(), additonalParams, cmd.getDeploymentPlanner(), false).first();
Long clusterId = cmd.getClusterId();
if (clusterId != null) {
VMInstanceDetailVO clusterDetail = vmInstanceDetailsDao.findDetail(cmd.getId(), VmDetailConstants.CLUSTER_ID);
clusterId = clusterDetail != null ? Long.parseLong(clusterDetail.getValue()) : null;
}

return startVirtualMachine(cmd.getId(), cmd.getPodId(), clusterId, cmd.getHostId(), additonalParams, cmd.getDeploymentPlanner(), false).first();
}

@Override
Expand Down Expand Up @@ -6905,29 +6912,44 @@ private UserVm createVirtualMachine(BaseDeployVMCmd cmd, DataCenter zone, Accoun
Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap = cmd.getDataDiskTemplateToDiskOfferingMap();
Map<String, String> userVmOVFProperties = cmd.getVmProperties();
final String instanceType = cmd.getInstanceType();

Map<String, String> vmDetails = cmd.getDetails();
if (cmd instanceof DeployVMCmdByAdmin && ((DeployVMCmdByAdmin) cmd).getClusterId() != null) {
Long clusterId = ((DeployVMCmdByAdmin) cmd).getClusterId();
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null) {
throw new InvalidParameterValueException("Unable to find cluster by id=" + clusterId);
}
if (cluster.getHypervisorType() != hypervisor) {
throw new InvalidParameterValueException("Hypervisor type of cluster " + cluster.getName() + " is " + cluster.getHypervisorType() +
" but hypervisor type of the VM is " + hypervisor);
}
vmDetails.put(VmDetailConstants.CLUSTER_ID, clusterId.toString());
}

if (zone.getNetworkType() == NetworkType.Basic) {
if (networkIds != null) {
throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
} else {
vm = createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(cmd, zone, template, owner), owner, name, displayName, diskOfferingId,
size , dataDiskInfoList, group , hypervisor, cmd.getHttpMethod(), userData, userDataId, userDataDetails, sshKeyPairNames, ipToNetworkMap, addrs, displayVm , keyboard , cmd.getAffinityGroupIdList(),
cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(),
vmDetails, cmd.getCustomId(), cmd.getDhcpOptionsMap(),
dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled, overrideDiskOfferingId, cmd.getRootDiskKmsKeyId(), volume, snapshot);
}
} else {
if (_networkModel.checkSecurityGroupSupportForNetwork(owner, zone, networkIds,
cmd.getSecurityGroupIdList())) {
vm = createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, networkIds, getSecurityGroupIdList(cmd, zone, template, owner), owner, name,
displayName, diskOfferingId, size, dataDiskInfoList, group, hypervisor, cmd.getHttpMethod(), userData, userDataId, userDataDetails, sshKeyPairNames, ipToNetworkMap, addrs, displayVm, keyboard,
cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(),
cmd.getAffinityGroupIdList(), vmDetails, cmd.getCustomId(), cmd.getDhcpOptionsMap(),
dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled, overrideDiskOfferingId, cmd.getRootDiskKmsKeyId(), instanceType, volume, snapshot);

} else {
if (cmd.getSecurityGroupIdList() != null && !cmd.getSecurityGroupIdList().isEmpty()) {
throw new InvalidParameterValueException("Can't create VM with security groups; security group feature is not enabled per zone");
}
vm = createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner, name, displayName, diskOfferingId, size, dataDiskInfoList, group,
hypervisor, cmd.getHttpMethod(), userData, userDataId, userDataDetails, sshKeyPairNames, ipToNetworkMap, addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(),
hypervisor, cmd.getHttpMethod(), userData, userDataId, userDataDetails, sshKeyPairNames, ipToNetworkMap, addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), vmDetails,
cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled, instanceType, overrideDiskOfferingId, cmd.getRootDiskKmsKeyId(), volume, snapshot);
if (cmd instanceof DeployVnfApplianceCmd) {
vnfTemplateManager.createIsolatedNetworkRulesForVnfAppliance(zone, template, owner, vm, (DeployVnfApplianceCmd) cmd);
Expand Down
Loading