mirror of https://github.com/apache/cloudstack.git
changes for restore with template; refactor
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
a6c7e55570
commit
1f72a2284c
|
|
@ -77,6 +77,7 @@ public class ApiConstants {
|
|||
public static final String BOOTABLE = "bootable";
|
||||
public static final String BIND_DN = "binddn";
|
||||
public static final String BIND_PASSWORD = "bindpass";
|
||||
public static final String BLANK_INSTANCE = "blankinstance";
|
||||
public static final String BUS_ADDRESS = "busaddress";
|
||||
public static final String BYTES_READ_RATE = "bytesreadrate";
|
||||
public static final String BYTES_READ_RATE_MAX = "bytesreadratemax";
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ import com.cloud.network.Network;
|
|||
import com.cloud.network.Network.IpAddresses;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.utils.net.Dhcp;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.VmDetailConstants;
|
||||
import com.cloud.vm.VmDiskInfo;
|
||||
import com.cloud.utils.net.Dhcp;
|
||||
|
||||
public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd {
|
||||
|
||||
|
|
@ -75,13 +75,13 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "availability zone for the virtual machine")
|
||||
private Long zoneId;
|
||||
protected Long zoneId;
|
||||
|
||||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "host name for the virtual machine", validations = {ApiArgValidator.RFCComplianceDomainName})
|
||||
private String name;
|
||||
protected String name;
|
||||
|
||||
@Parameter(name = ApiConstants.DISPLAY_NAME, type = CommandType.STRING, description = "an optional user generated name for the virtual machine")
|
||||
private String displayName;
|
||||
protected String displayName;
|
||||
|
||||
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="The password of the virtual machine. If null, a random password will be generated for the VM.",
|
||||
since="4.19.0.0")
|
||||
|
|
@ -89,21 +89,21 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
|
||||
//Owner information
|
||||
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional account for the virtual machine. Must be used with domainId.")
|
||||
private String accountName;
|
||||
protected String accountName;
|
||||
|
||||
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "an optional domainId for the virtual machine. If the account parameter is used, domainId must also be used. If account is NOT provided then virtual machine will be assigned to the caller account and domain.")
|
||||
private Long domainId;
|
||||
protected Long domainId;
|
||||
|
||||
//Network information
|
||||
//@ACL(accessType = AccessType.UseEntry)
|
||||
@Parameter(name = ApiConstants.NETWORK_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = NetworkResponse.class, description = "list of network ids used by virtual machine. Can't be specified with ipToNetworkList parameter")
|
||||
private List<Long> networkIds;
|
||||
protected List<Long> networkIds;
|
||||
|
||||
@Parameter(name = ApiConstants.BOOT_TYPE, type = CommandType.STRING, required = false, description = "Guest VM Boot option either custom[UEFI] or default boot [BIOS]. Not applicable with VMware if the template is marked as deploy-as-is, as we honour what is defined in the template.", since = "4.14.0.0")
|
||||
private String bootType;
|
||||
protected String bootType;
|
||||
|
||||
@Parameter(name = ApiConstants.BOOT_MODE, type = CommandType.STRING, required = false, description = "Boot Mode [Legacy] or [Secure] Applicable when Boot Type Selected is UEFI, otherwise Legacy only for BIOS. Not applicable with VMware if the template is marked as deploy-as-is, as we honour what is defined in the template.", since = "4.14.0.0")
|
||||
private String bootMode;
|
||||
protected String bootMode;
|
||||
|
||||
@Parameter(name = ApiConstants.BOOT_INTO_SETUP, type = CommandType.BOOLEAN, required = false, description = "Boot into hardware setup or not (ignored if startVm = false, only valid for vmware)", since = "4.15.0.0")
|
||||
private Boolean bootIntoSetup;
|
||||
|
|
@ -138,7 +138,7 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, description = "the hypervisor on which to deploy the virtual machine. "
|
||||
+ "The parameter is required and respected only when hypervisor info is not set on the ISO/Template passed to the call")
|
||||
private String hypervisor;
|
||||
protected 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. " +
|
||||
|
|
@ -147,7 +147,7 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
|
||||
"You also need to change vm.userdata.max.length value",
|
||||
length = 1048576)
|
||||
private String userData;
|
||||
protected String userData;
|
||||
|
||||
@Parameter(name = ApiConstants.USER_DATA_ID, type = CommandType.UUID, entityType = UserDataResponse.class, description = "the ID of the Userdata", since = "4.18")
|
||||
private Long userdataId;
|
||||
|
|
@ -189,10 +189,10 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
private String macAddress;
|
||||
|
||||
@Parameter(name = ApiConstants.KEYBOARD, type = CommandType.STRING, description = "an optional keyboard device type for the virtual machine. valid value can be one of de,de-ch,es,es-latam,fi,fr,fr-be,fr-ch,is,it,jp,nl-be,no,pt,uk,us")
|
||||
private String keyboard;
|
||||
protected String keyboard;
|
||||
|
||||
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Deploy vm for the project")
|
||||
private Long projectId;
|
||||
protected Long projectId;
|
||||
|
||||
@Parameter(name = ApiConstants.START_VM, type = CommandType.BOOLEAN, description = "true if start vm after creating; defaulted to true if not specified")
|
||||
private Boolean startVm;
|
||||
|
|
@ -208,10 +208,10 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
private List<String> affinityGroupNameList;
|
||||
|
||||
@Parameter(name = ApiConstants.DISPLAY_VM, type = CommandType.BOOLEAN, since = "4.2", description = "an optional field, whether to the display the vm to the end user or not.", authorized = {RoleType.Admin})
|
||||
private Boolean displayVm;
|
||||
protected Boolean displayVm;
|
||||
|
||||
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, since = "4.3", description = "used to specify the custom parameters. 'extraconfig' is not allowed to be passed in details")
|
||||
private Map details;
|
||||
protected Map details;
|
||||
|
||||
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "Deployment planner to use for vm allocation. Available to ROOT admin only", since = "4.4", authorized = { RoleType.Admin })
|
||||
private String deploymentPlanner;
|
||||
|
|
@ -225,7 +225,7 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
private Map dataDiskTemplateToDiskOfferingList;
|
||||
|
||||
@Parameter(name = ApiConstants.EXTRA_CONFIG, type = CommandType.STRING, since = "4.12", description = "an optional URL encoded string that can be passed to the virtual machine upon successful deployment", length = 5120)
|
||||
private String extraConfig;
|
||||
protected String extraConfig;
|
||||
|
||||
@Parameter(name = ApiConstants.COPY_IMAGE_TAGS, type = CommandType.BOOLEAN, since = "4.13", description = "if true the image tags (if any) will be copied to the VM, default value is false")
|
||||
private Boolean copyImageTags;
|
||||
|
|
@ -799,217 +799,6 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
return null;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
////////////////// Setters //////////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
public void setZoneId(Long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
public void setNetworkIds(List<Long> networkIds) {
|
||||
this.networkIds = networkIds;
|
||||
}
|
||||
|
||||
public void setBootType(String bootType) {
|
||||
this.bootType = bootType;
|
||||
}
|
||||
|
||||
public void setBootMode(String bootMode) {
|
||||
this.bootMode = bootMode;
|
||||
}
|
||||
|
||||
public void setBootIntoSetup(Boolean bootIntoSetup) {
|
||||
this.bootIntoSetup = bootIntoSetup;
|
||||
}
|
||||
|
||||
public void setDiskOfferingId(Long diskOfferingId) {
|
||||
this.diskOfferingId = diskOfferingId;
|
||||
}
|
||||
|
||||
public void setSize(Long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void setRootdisksize(Long rootdisksize) {
|
||||
this.rootdisksize = rootdisksize;
|
||||
}
|
||||
|
||||
public void setDataDisksDetails(Map dataDisksDetails) {
|
||||
this.dataDisksDetails = dataDisksDetails;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public void setHypervisor(String hypervisor) {
|
||||
this.hypervisor = hypervisor;
|
||||
}
|
||||
|
||||
public void setUserData(String userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
public void setUserdataId(Long userdataId) {
|
||||
this.userdataId = userdataId;
|
||||
}
|
||||
|
||||
public void setUserdataDetails(Map userdataDetails) {
|
||||
this.userdataDetails = userdataDetails;
|
||||
}
|
||||
|
||||
public void setSshKeyPairName(String sshKeyPairName) {
|
||||
this.sshKeyPairName = sshKeyPairName;
|
||||
}
|
||||
|
||||
public void setSshKeyPairNames(List<String> sshKeyPairNames) {
|
||||
this.sshKeyPairNames = sshKeyPairNames;
|
||||
}
|
||||
|
||||
public void setHostId(Long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public void setSecurityGroupIdList(List<Long> securityGroupIdList) {
|
||||
this.securityGroupIdList = securityGroupIdList;
|
||||
}
|
||||
|
||||
public void setSecurityGroupNameList(List<String> securityGroupNameList) {
|
||||
this.securityGroupNameList = securityGroupNameList;
|
||||
}
|
||||
|
||||
public void setIpToNetworkList(Map ipToNetworkList) {
|
||||
this.ipToNetworkList = ipToNetworkList;
|
||||
}
|
||||
|
||||
public void setIpAddress(String ipAddress) {
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
public void setIp6Address(String ip6Address) {
|
||||
this.ip6Address = ip6Address;
|
||||
}
|
||||
|
||||
public void setMacAddress(String macAddress) {
|
||||
this.macAddress = macAddress;
|
||||
}
|
||||
|
||||
public void setKeyboard(String keyboard) {
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
public void setProjectId(Long projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public void setStartVm(Boolean startVm) {
|
||||
this.startVm = startVm;
|
||||
}
|
||||
|
||||
public void setAffinityGroupIdList(List<Long> affinityGroupIdList) {
|
||||
this.affinityGroupIdList = affinityGroupIdList;
|
||||
}
|
||||
|
||||
public void setAffinityGroupNameList(List<String> affinityGroupNameList) {
|
||||
this.affinityGroupNameList = affinityGroupNameList;
|
||||
}
|
||||
|
||||
public void setDisplayVm(Boolean displayVm) {
|
||||
this.displayVm = displayVm;
|
||||
}
|
||||
|
||||
public void setDetails(Map details) {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public void setDeploymentPlanner(String deploymentPlanner) {
|
||||
this.deploymentPlanner = deploymentPlanner;
|
||||
}
|
||||
|
||||
public void setDhcpOptionsNetworkList(Map dhcpOptionsNetworkList) {
|
||||
this.dhcpOptionsNetworkList = dhcpOptionsNetworkList;
|
||||
}
|
||||
|
||||
public void setDataDiskTemplateToDiskOfferingList(Map dataDiskTemplateToDiskOfferingList) {
|
||||
this.dataDiskTemplateToDiskOfferingList = dataDiskTemplateToDiskOfferingList;
|
||||
}
|
||||
|
||||
public void setExtraConfig(String extraConfig) {
|
||||
this.extraConfig = extraConfig;
|
||||
}
|
||||
|
||||
public void setCopyImageTags(Boolean copyImageTags) {
|
||||
this.copyImageTags = copyImageTags;
|
||||
}
|
||||
|
||||
public void setvAppProperties(Map vAppProperties) {
|
||||
this.vAppProperties = vAppProperties;
|
||||
}
|
||||
|
||||
public void setvAppNetworks(Map vAppNetworks) {
|
||||
this.vAppNetworks = vAppNetworks;
|
||||
}
|
||||
|
||||
public void setDynamicScalingEnabled(Boolean dynamicScalingEnabled) {
|
||||
this.dynamicScalingEnabled = dynamicScalingEnabled;
|
||||
}
|
||||
|
||||
public void setOverrideDiskOfferingId(Long overrideDiskOfferingId) {
|
||||
this.overrideDiskOfferingId = overrideDiskOfferingId;
|
||||
}
|
||||
|
||||
public void setIothreadsEnabled(Boolean iothreadsEnabled) {
|
||||
this.iothreadsEnabled = iothreadsEnabled;
|
||||
}
|
||||
|
||||
public void setIoDriverPolicy(String ioDriverPolicy) {
|
||||
this.ioDriverPolicy = ioDriverPolicy;
|
||||
}
|
||||
|
||||
public void setNicMultiqueueNumber(Integer nicMultiqueueNumber) {
|
||||
this.nicMultiqueueNumber = nicMultiqueueNumber;
|
||||
}
|
||||
|
||||
public void setNicPackedVirtQueues(Boolean nicPackedVirtQueues) {
|
||||
this.nicPackedVirtQueues = nicPackedVirtQueues;
|
||||
}
|
||||
|
||||
public void setLeaseDuration(Integer leaseDuration) {
|
||||
this.leaseDuration = leaseDuration;
|
||||
}
|
||||
|
||||
public void setLeaseExpiryAction(String leaseExpiryAction) {
|
||||
this.leaseExpiryAction = leaseExpiryAction;
|
||||
}
|
||||
|
||||
public void setExternalDetails(Map externalDetails) {
|
||||
this.externalDetails = externalDetails;
|
||||
}
|
||||
|
||||
public void setDataDiskInfoList(List<VmDiskInfo> dataDiskInfoList) {
|
||||
this.dataDiskInfoList = dataDiskInfoList;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vm;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.api.ACL;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
|
|
@ -40,6 +41,7 @@ import com.cloud.exception.InsufficientServerCapacityException;
|
|||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
@APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts an Instance based on a service offering, disk offering, and Template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
|
||||
|
|
@ -96,9 +98,74 @@ public class DeployVMCmd extends BaseDeployVMCmd {
|
|||
return Boolean.TRUE.equals(blankInstance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
////////////////// Setters //////////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
public void setZoneId(Long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
public void setNetworkIds(List<Long> networkIds) {
|
||||
this.networkIds = networkIds;
|
||||
}
|
||||
|
||||
public void setBootType(String bootType) {
|
||||
this.bootType = bootType;
|
||||
}
|
||||
|
||||
public void setBootMode(String bootMode) {
|
||||
this.bootMode = bootMode;
|
||||
}
|
||||
|
||||
public void setHypervisor(String hypervisor) {
|
||||
this.hypervisor = hypervisor;
|
||||
}
|
||||
|
||||
public void setUserData(String userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
public void setKeyboard(String keyboard) {
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
public void setProjectId(Long projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public void setDisplayVm(Boolean displayVm) {
|
||||
this.displayVm = displayVm;
|
||||
}
|
||||
|
||||
public void setDetails(Map details) {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public void setExtraConfig(String extraConfig) {
|
||||
this.extraConfig = extraConfig;
|
||||
}
|
||||
|
||||
public void setDynamicScalingEnabled(Boolean dynamicScalingEnabled) {
|
||||
this.dynamicScalingEnabled = dynamicScalingEnabled;
|
||||
}
|
||||
|
||||
public void setServiceOfferingId(Long serviceOfferingId) {
|
||||
this.serviceOfferingId = serviceOfferingId;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ import javax.inject.Inject;
|
|||
import javax.naming.ConfigurationException;
|
||||
import javax.persistence.EntityExistsException;
|
||||
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.annotation.AnnotationService;
|
||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||
|
|
@ -303,8 +302,8 @@ import com.cloud.vm.VirtualMachine.PowerState;
|
|||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDetailsDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.vm.dao.VMInstanceDetailsDao;
|
||||
import com.cloud.vm.snapshot.VMSnapshotManager;
|
||||
import com.cloud.vm.snapshot.VMSnapshotVO;
|
||||
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
|
||||
|
|
@ -577,7 +576,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
|
||||
logger.debug("Allocating disks for {}", persistedVm);
|
||||
|
||||
if (_userVmMgr.isBlankInstanceTemplate(template)) {
|
||||
if (_userVmMgr.isBlankInstance(template)) {
|
||||
logger.debug("Template is a dummy template for hypervisor {}, skipping volume allocation", hyperType);
|
||||
return;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -152,9 +152,11 @@ import com.cloud.projects.Project;
|
|||
import com.cloud.projects.ProjectService;
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeApiService;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.dao.VolumeDetailsDao;
|
||||
import com.cloud.tags.ResourceTagVO;
|
||||
|
|
@ -264,6 +266,9 @@ public class ServerAdapter extends ManagerBase {
|
|||
@Inject
|
||||
ServiceOfferingDao serviceOfferingDao;
|
||||
|
||||
@Inject
|
||||
VMTemplateDao templateDao;
|
||||
|
||||
@Inject
|
||||
UserVmService userVmService;
|
||||
|
||||
|
|
@ -611,11 +616,15 @@ public class ServerAdapter extends ManagerBase {
|
|||
if (request.getCpuProfile() != null && StringUtils.isNotEmpty(request.getCpuProfile().getId())) {
|
||||
serviceOfferingUuid = request.getCpuProfile().getId();
|
||||
}
|
||||
String templateUuid = null;
|
||||
if (request.getTemplate() != null && StringUtils.isNotEmpty(request.getTemplate().getId())) {
|
||||
templateUuid = request.getTemplate().getId();
|
||||
}
|
||||
Pair<User, Account> serviceUserAccount = getServiceAccount();
|
||||
CallContext ctx = CallContext.register(serviceUserAccount.first(), serviceUserAccount.second());
|
||||
try {
|
||||
return createInstance(zoneId, clusterId, owner.first(), owner.second(), owner.third(), name, displayName,
|
||||
serviceOfferingUuid, cpu, memory, userdata, bootType, bootMode);
|
||||
serviceOfferingUuid, cpu, memory, templateUuid, userdata, bootType, bootMode);
|
||||
} finally {
|
||||
CallContext.unregister();
|
||||
}
|
||||
|
|
@ -643,9 +652,21 @@ public class ServerAdapter extends ManagerBase {
|
|||
return serviceOfferingDao.findByUuid(uuid);
|
||||
}
|
||||
|
||||
protected VMTemplateVO getTemplateForVmCreation(String templateUuid) {
|
||||
if (StringUtils.isBlank(templateUuid)) {
|
||||
return null;
|
||||
}
|
||||
VMTemplateVO template = templateDao.findByUuid(templateUuid);
|
||||
if (template == null) {
|
||||
logger.warn("Template with ID {} not found, VM will be created with default template", templateUuid);
|
||||
return null;
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
protected Vm createInstance(Long zoneId, Long clusterId, Long domainId, String accountName, Long projectId,
|
||||
String name, String displayName, String serviceOfferingUuid, int cpu, long memory, String userdata,
|
||||
ApiConstants.BootType bootType, ApiConstants.BootMode bootMode) {
|
||||
String name, String displayName, String serviceOfferingUuid, int cpu, long memory, String templateUuid,
|
||||
String userdata, ApiConstants.BootType bootType, ApiConstants.BootMode bootMode) {
|
||||
ServiceOffering serviceOffering = getServiceOfferingIdForVmCreation(serviceOfferingUuid, zoneId, cpu, memory);
|
||||
if (serviceOffering == null) {
|
||||
throw new CloudRuntimeException("No service offering found for VM creation with specified CPU and memory");
|
||||
|
|
@ -676,6 +697,10 @@ public class ServerAdapter extends ManagerBase {
|
|||
if (bootMode != null) {
|
||||
cmd.setBootMode(bootMode.toString());
|
||||
}
|
||||
VMTemplateVO template = getTemplateForVmCreation(templateUuid);
|
||||
if (template != null) {
|
||||
cmd.setTemplateId(template.getId());
|
||||
}
|
||||
// ToDo: handle any other field?
|
||||
// Handle custom offerings
|
||||
cmd.setHypervisor(Hypervisor.HypervisorType.KVM.name());
|
||||
|
|
|
|||
|
|
@ -204,5 +204,5 @@ public interface UserVmManager extends UserVmService {
|
|||
*/
|
||||
boolean isVMPartOfAnyCKSCluster(VMInstanceVO vm);
|
||||
|
||||
boolean isBlankInstanceTemplate(VirtualMachineTemplate template);
|
||||
boolean isBlankInstance(VirtualMachineTemplate template);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3933,8 +3933,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
_accountMgr.checkAccess(owner, _diskOfferingDao.findById(diskOfferingId), zone);
|
||||
|
||||
// If no network is specified, find system security group enabled network
|
||||
if (isBlankInstanceTemplate(template)) {
|
||||
logger.debug("Template is a dummy template for hypervisor {}, skipping network allocation in an advanced security group enabled zone", hypervisor);
|
||||
if (isBlankInstance(template)) {
|
||||
logger.debug("Blank instance for {} hypervisor, skipping network allocation in an advanced security group enabled zone", hypervisor);
|
||||
} else if (networkIdList == null || networkIdList.isEmpty()) {
|
||||
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(owner, zone.getId());
|
||||
if (networkWithSecurityGroup == null) {
|
||||
|
|
@ -4048,7 +4048,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
_accountMgr.checkAccess(owner, diskOffering, zone);
|
||||
|
||||
List<HypervisorType> vpcSupportedHTypes = _vpcMgr.getSupportedVpcHypervisors();
|
||||
if (isBlankInstanceTemplate(template)) {
|
||||
if (isBlankInstance(template)) {
|
||||
logger.debug("Template is a dummy template for hypervisor {}, skipping network allocation in an advanced zone", hypervisor);
|
||||
} else if (networkIdList == null || networkIdList.isEmpty()) {
|
||||
NetworkVO defaultNetwork = getDefaultNetwork(zone, owner, false);
|
||||
|
|
@ -4485,7 +4485,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
}
|
||||
|
||||
if (TemplateType.SYSTEM.equals(template.getTemplateType()) && !CKS_NODE.equals(vmType) && !SHAREDFSVM.equals(vmType) && !isBlankInstanceTemplate(template)) {
|
||||
if (TemplateType.SYSTEM.equals(template.getTemplateType()) && !CKS_NODE.equals(vmType) &&
|
||||
!SHAREDFSVM.equals(vmType) && !isBlankInstanceDefaultTemplate(template)) {
|
||||
throw new InvalidParameterValueException(String.format("Unable to use system template %s to deploy a user vm", template));
|
||||
}
|
||||
|
||||
|
|
@ -4498,7 +4499,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
if (CollectionUtils.isEmpty(snapshotsOnZone)) {
|
||||
throw new InvalidParameterValueException("The snapshot does not exist on zone " + zone.getId());
|
||||
}
|
||||
} else if (!isBlankInstanceTemplate(template)) {
|
||||
} else if (!isBlankInstanceDefaultTemplate(template)) {
|
||||
List<VMTemplateZoneVO> listZoneTemplate = _templateZoneDao.listByZoneTemplate(zone.getId(), template.getId());
|
||||
if (listZoneTemplate == null || listZoneTemplate.isEmpty()) {
|
||||
throw new InvalidParameterValueException("The template " + template.getId() + " is not available for use");
|
||||
|
|
@ -4613,7 +4614,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
// by Agent Manager in order to configure default
|
||||
// gateway for the vm
|
||||
if (defaultNetworkNumber == 0) {
|
||||
if (isBlankInstanceTemplate(template)) {
|
||||
if (isBlankInstance(template)) {
|
||||
logger.debug("Template is a dummy template for hypervisor {}, vm can be created without a default network", hypervisorType);
|
||||
} else {
|
||||
throw new InvalidParameterValueException("At least 1 default network has to be specified for the vm");
|
||||
|
|
@ -6483,7 +6484,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
(!(HypervisorType.KVM.equals(template.getHypervisorType()) || HypervisorType.KVM.equals(cmd.getHypervisor())))) {
|
||||
throw new InvalidParameterValueException("Deploying a virtual machine with existing volume/snapshot is supported only from KVM hypervisors");
|
||||
}
|
||||
if (template == null && HypervisorType.KVM.equals(cmd.getHypervisor()) && cmd.isBlankInstance()) {
|
||||
boolean blankInstance = cmd.isBlankInstance();
|
||||
if (blankInstance) {
|
||||
CallContext.current().putContextParameter(ApiConstants.BLANK_INSTANCE, true);
|
||||
}
|
||||
if (template == null && HypervisorType.KVM.equals(cmd.getHypervisor()) && blankInstance) {
|
||||
template = getBlankInstanceTemplate();
|
||||
logger.info("Creating launch permission for Dummy template");
|
||||
LaunchPermissionVO launchPermission = new LaunchPermissionVO(template.getId(), owner.getId());
|
||||
|
|
@ -6648,7 +6653,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
applyLeaseOnCreateInstance(vm, cmd.getLeaseDuration(), cmd.getLeaseExpiryAction(), svcOffering);
|
||||
}
|
||||
|
||||
if (isBlankInstanceTemplate(template) && cmd instanceof DeployVMCmd && ((DeployVMCmd) cmd).isBlankInstance()) {
|
||||
if (isBlankInstance(template) && cmd instanceof DeployVMCmd && ((DeployVMCmd) cmd).isBlankInstance()) {
|
||||
logger.info("Revoking launch permission for Dummy template");
|
||||
launchPermissionDao.removePermissions(template.getId(), Collections.singletonList(owner.getId()));
|
||||
}
|
||||
|
|
@ -10091,11 +10096,19 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlankInstanceTemplate(VirtualMachineTemplate template) {
|
||||
protected boolean isBlankInstanceDefaultTemplate(VirtualMachineTemplate template) {
|
||||
return KVM_VM_DUMMY_TEMPLATE_NAME.equals(template.getUniqueName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlankInstance(VirtualMachineTemplate template) {
|
||||
if (isBlankInstanceDefaultTemplate(template)) {
|
||||
return true;
|
||||
}
|
||||
return MapUtils.getBoolean(CallContext.current().getContextParameters(),
|
||||
ApiConstants.BLANK_INSTANCE);
|
||||
}
|
||||
|
||||
VMTemplateVO getBlankInstanceTemplate() {
|
||||
VMTemplateVO template = _templateDao.findByName(KVM_VM_DUMMY_TEMPLATE_NAME);
|
||||
if (template != null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue