diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 14b703c0c2e..8ceccb9d2d6 100755 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -128,7 +128,8 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd { @Parameter(name = ApiConstants.GROUP, type = CommandType.STRING, description = "an optional group for the virtual machine") private String group; - @Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, description = "the hypervisor on which to deploy the virtual machine") + @Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, description = "the hypervisor on which to deploy the virtual machine. " + + "The parameter is respected only when hypervisor info is not set on the ISO/Template passed to the call") private String hypervisor; @Parameter(name = ApiConstants.USER_DATA, type = CommandType.STRING, description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. This binary data must be base64 encoded before adding it to the request. Using HTTP GET (via querystring), you can send up to 2KB of data after base64 encoding. Using HTTP POST(via POST body), you can send up to 32K of data after base64 encoding.", length = 32768) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 0fa5085c0e7..a9f8efdbf63 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2716,7 +2716,17 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } - if (template.getHypervisorType() != null && template.getHypervisorType() != HypervisorType.BareMetal) { + HypervisorType hypervisorType = null; + if (template.getHypervisorType() == null || template.getHypervisorType() == HypervisorType.None) { + hypervisorType = hypervisor; + } else { + if (hypervisor != null && hypervisor != HypervisorType.None && hypervisor != template.getHypervisorType()) { + throw new InvalidParameterValueException("Hypervisor passed to the deployVm call, is different from the hypervisor type of the template"); + } + hypervisorType = template.getHypervisorType(); + } + + if (hypervisorType != HypervisorType.BareMetal) { // check if we have available pools for vm deployment long availablePools = _storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up); if (availablePools < 1) { @@ -2892,15 +2902,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir checkIfHostNameUniqueInNtwkDomain(hostName, networkList); - HypervisorType hypervisorType = null; - if (template.getHypervisorType() == null || template.getHypervisorType() == HypervisorType.None) { - hypervisorType = hypervisor; - } else { - hypervisorType = template.getHypervisorType(); - } - - UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, hypervisor, caller, isDisplayVm, keyboard, accountId, - offering, isIso, sshPublicKey, networkNicMap, id, instanceName, uuidName, hypervisorType, customParameters); + UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, accountId, offering, + isIso, sshPublicKey, networkNicMap, id, instanceName, uuidName, hypervisorType, customParameters); // Assign instance to the group try { @@ -2957,10 +2960,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } private UserVmVO commitUserVm(final DataCenter zone, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner, - final Long diskOfferingId, final Long diskSize, final String userData, final HypervisorType hypervisor, final Account caller, final Boolean isDisplayVm, - final String keyboard, final long accountId, final ServiceOfferingVO offering, final boolean isIso, final String sshPublicKey, - final LinkedHashMap networkNicMap, final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, - final Map customParameters) throws InsufficientCapacityException { + final Long diskOfferingId, final Long diskSize, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard, + final long accountId, final ServiceOfferingVO offering, final boolean isIso, final String sshPublicKey, final LinkedHashMap networkNicMap, + final long id, final String instanceName, final String uuidName, final HypervisorType hypervisorType, final Map customParameters) throws InsufficientCapacityException { return Transaction.execute(new TransactionCallbackWithException() { @Override public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCapacityException { @@ -2993,8 +2995,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir rootDiskSize = Long.parseLong(customParameters.get("rootdisksize")); // only KVM supports rootdisksize override - if (hypervisor != HypervisorType.KVM) { - throw new InvalidParameterValueException("Hypervisor " + hypervisor + " does not support rootdisksize override"); + if (hypervisorType != HypervisorType.KVM) { + throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support rootdisksize override"); } // rotdisksize must be larger than template @@ -3064,10 +3066,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir if (isIso) { _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), Long.toString(owner.getAccountId()), vm.getIsoId().toString(), hostName, displayName, - hypervisor.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, + hypervisorType.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan); } else { - _orchSrvc.createVirtualMachine(vm.getUuid(), Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, displayName, hypervisor.name(), + _orchSrvc.createVirtualMachine(vm.getUuid(), Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, displayName, hypervisorType.name(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan, rootDiskSize); }