mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
vmware: Make deploy-as-is optional (#4901)
* [Vmware] Make deploy-as-is optional * Do not use deployasis on create volume test * Update api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java Co-authored-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * Update api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java Co-authored-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * Review comments * Refactor condition to select suitable template Co-authored-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
de30f3b7ee
commit
9349d20dd3
@ -72,7 +72,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
|
||||
private String format;
|
||||
|
||||
@Parameter(name = ApiConstants.HYPERVISOR, type = CommandType.STRING, required = true, description = "the target hypervisor for the template")
|
||||
private String hypervisor;
|
||||
protected String hypervisor;
|
||||
|
||||
@Parameter(name = ApiConstants.IS_FEATURED, type = CommandType.BOOLEAN, description = "true if this template is a featured template, false otherwise")
|
||||
private Boolean featured;
|
||||
@ -162,6 +162,11 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
|
||||
description = "true if template should bypass Secondary Storage and be downloaded to Primary Storage on deployment")
|
||||
private Boolean directDownload;
|
||||
|
||||
@Parameter(name=ApiConstants.DEPLOY_AS_IS,
|
||||
type = CommandType.BOOLEAN,
|
||||
description = "(VMware only) true if VM deployments should preserve all the configurations defined for this template", since = "4.15.1")
|
||||
protected Boolean deployAsIs;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -274,8 +279,9 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
|
||||
return directDownload == null ? false : directDownload;
|
||||
}
|
||||
|
||||
public Boolean isDeployAsIs() {
|
||||
return hypervisor != null && hypervisor.equalsIgnoreCase(Hypervisor.HypervisorType.VMware.toString());
|
||||
public boolean isDeployAsIs() {
|
||||
return Hypervisor.HypervisorType.VMware.toString().equalsIgnoreCase(hypervisor) &&
|
||||
Boolean.TRUE.equals(deployAsIs);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -341,7 +347,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
|
||||
"Parameter directdownload is only allowed for KVM templates");
|
||||
}
|
||||
|
||||
if (!getHypervisor().equalsIgnoreCase(Hypervisor.HypervisorType.VMware.toString()) && osTypeId == null) {
|
||||
if (!isDeployAsIs() && osTypeId == null) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please provide a guest OS type");
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
package org.apache.cloudstack.api.command.user.template;
|
||||
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.template.TemplateApiService;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
@ -108,4 +109,34 @@ public class RegisterTemplateCmdTest{
|
||||
registerTemplateCmd.zoneId = 1L;
|
||||
Assert.assertEquals((Long)1L,registerTemplateCmd.getZoneIds().get(0));
|
||||
}
|
||||
|
||||
private void testIsDeployAsIsBase(Hypervisor.HypervisorType hypervisorType, Boolean deployAsIsParameter, boolean expectedResult) {
|
||||
registerTemplateCmd = new RegisterTemplateCmd();
|
||||
registerTemplateCmd.hypervisor = hypervisorType.name();
|
||||
registerTemplateCmd.deployAsIs = deployAsIsParameter;
|
||||
boolean isDeployAsIs = registerTemplateCmd.isDeployAsIs();
|
||||
Assert.assertEquals(expectedResult, isDeployAsIs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDeployAsIsVmwareNullAsIs() {
|
||||
testIsDeployAsIsBase(Hypervisor.HypervisorType.VMware, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDeployAsIsVmwareNotAsIs() {
|
||||
testIsDeployAsIsBase(Hypervisor.HypervisorType.VMware, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDeployAsIsVmwareAsIs() {
|
||||
testIsDeployAsIsBase(Hypervisor.HypervisorType.VMware, true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDeployAsIsNonVmware() {
|
||||
testIsDeployAsIsBase(Hypervisor.HypervisorType.KVM, true, false);
|
||||
testIsDeployAsIsBase(Hypervisor.HypervisorType.XenServer, true, false);
|
||||
testIsDeployAsIsBase(Hypervisor.HypervisorType.Any, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,7 +291,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
|
||||
}
|
||||
|
||||
Map details = cmd.getDetails();
|
||||
if (hypervisorType == HypervisorType.VMware) {
|
||||
if (cmd.isDeployAsIs()) {
|
||||
if (MapUtils.isNotEmpty(details)) {
|
||||
if (details.containsKey(VmDetailConstants.ROOT_DISK_CONTROLLER)) {
|
||||
s_logger.info("Ignoring the rootDiskController detail provided, as we honour what is defined in the template");
|
||||
|
||||
@ -260,8 +260,8 @@ class TestKubernetesCluster(cloudstackTestCase):
|
||||
|
||||
if validateList(templates)[0] != PASS:
|
||||
details = None
|
||||
if hypervisor in ["vmware"]:
|
||||
details = [{"keyboard": "us"}]
|
||||
if hypervisor in ["vmware"] and "details" in cks_template:
|
||||
details = cks_template["details"]
|
||||
template = Template.register(cls.apiclient, cks_template, zoneid=cls.zone.id, hypervisor=hypervisor.lower(), randomize_name=False, details=details)
|
||||
template.download(cls.apiclient)
|
||||
return template, False
|
||||
|
||||
@ -59,6 +59,7 @@ class TestVMWareStoragePolicies(cloudstackTestCase):
|
||||
cls.apiclient,
|
||||
cls.zone.id,
|
||||
cls.hypervisor,
|
||||
deploy_as_is=cls.hypervisor.lower() == "vmware"
|
||||
)
|
||||
cls._cleanup.append(cls.network_offering)
|
||||
return
|
||||
|
||||
@ -84,6 +84,7 @@ class TestCreateTemplateWithChecksum(cloudstackTestCase):
|
||||
self.test_template.displaytext = 'test sha-1'
|
||||
self.test_template.url = "http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-vmware.ova"
|
||||
self.test_template.format = "OVA"
|
||||
self.test_template.ostypeid = self.getOsType("Other Linux (64-bit)")
|
||||
self.md5 = "27f3c56a8c7ec7b2f3ff2199f7078006"
|
||||
self.sha256 = "a7b04c1eb507f3f5de844bda352df1ea5e20335b465409493ca6ae07dfd0a158"
|
||||
|
||||
|
||||
@ -308,7 +308,8 @@ class TestVolumes(cloudstackTestCase):
|
||||
cls.apiclient,
|
||||
cls.zone.id,
|
||||
cls.services["ostype"],
|
||||
cls.hypervisor
|
||||
cls.hypervisor,
|
||||
deploy_as_is=cls.hypervisor.lower() == "vmware"
|
||||
)
|
||||
if cls.template == FAILED:
|
||||
assert False, "get_suitable_test_template() failed to return template with description %s" % cls.services["ostype"]
|
||||
|
||||
@ -1403,8 +1403,6 @@ class Template:
|
||||
elif "hypervisor" in services:
|
||||
cmd.hypervisor = services["hypervisor"]
|
||||
|
||||
if cmd.hypervisor.lower() not in ["vmware"]:
|
||||
# Since version 4.15 VMware templates honour the guest OS defined in the template
|
||||
if "ostypeid" in services:
|
||||
cmd.ostypeid = services["ostypeid"]
|
||||
elif "ostype" in services:
|
||||
@ -1438,6 +1436,7 @@ class Template:
|
||||
cmd.isdynamicallyscalable = services["isdynamicallyscalable"] if "isdynamicallyscalable" in services else False
|
||||
cmd.passwordenabled = services[
|
||||
"passwordenabled"] if "passwordenabled" in services else False
|
||||
cmd.deployasis = services["deployasis"] if "deployasis" in services else False
|
||||
|
||||
if account:
|
||||
cmd.account = account
|
||||
|
||||
@ -348,7 +348,7 @@ def get_template(
|
||||
return list_templatesout[0]
|
||||
|
||||
|
||||
def get_test_template(apiclient, zone_id=None, hypervisor=None, test_templates=None):
|
||||
def get_test_template(apiclient, zone_id=None, hypervisor=None, test_templates=None, deploy_as_is=False):
|
||||
"""
|
||||
@Name : get_test_template
|
||||
@Desc : Retrieves the test template used to running tests. When the template
|
||||
@ -373,6 +373,8 @@ def get_test_template(apiclient, zone_id=None, hypervisor=None, test_templates=N
|
||||
return FAILED
|
||||
|
||||
test_template = test_templates[hypervisor]
|
||||
if deploy_as_is:
|
||||
test_template['deployasis'] = True
|
||||
|
||||
cmd = listTemplates.listTemplatesCmd()
|
||||
cmd.name = test_template['name']
|
||||
@ -513,7 +515,7 @@ def get_windows_template(
|
||||
|
||||
return FAILED
|
||||
|
||||
def get_suitable_test_template(apiclient, zoneid, ostypeid, hypervisor):
|
||||
def get_suitable_test_template(apiclient, zoneid, ostypeid, hypervisor, deploy_as_is=False):
|
||||
'''
|
||||
@Name : get_suitable_test_template
|
||||
@Desc : Retrieves the test template information based upon inputs provided
|
||||
@ -525,11 +527,12 @@ def get_suitable_test_template(apiclient, zoneid, ostypeid, hypervisor):
|
||||
template Information matching the inputs
|
||||
'''
|
||||
template = FAILED
|
||||
if hypervisor.lower() in ["xenserver"]:
|
||||
if hypervisor.lower() in ["xenserver"] or (hypervisor.lower() in ["vmware"] and deploy_as_is):
|
||||
template = get_test_template(
|
||||
apiclient,
|
||||
zoneid,
|
||||
hypervisor)
|
||||
hypervisor,
|
||||
deploy_as_is=deploy_as_is)
|
||||
if template == FAILED:
|
||||
template = get_template(
|
||||
apiclient,
|
||||
|
||||
@ -715,7 +715,7 @@
|
||||
"label.demote.project.owner": "Demote account to Regular role",
|
||||
"label.demote.project.owner.user": "Demote user to Regular role",
|
||||
"label.deny": "Deny",
|
||||
"label.deployasis":"Deploy As-Is",
|
||||
"label.deployasis":"Read VM settings from OVA",
|
||||
"label.deploymentplanner": "Deployment planner",
|
||||
"label.description": "Description",
|
||||
"label.destcidr": "Destination CIDR",
|
||||
|
||||
@ -208,8 +208,18 @@
|
||||
:default-checked="xenServerProvider" />
|
||||
</a-form-item>
|
||||
</a-row>
|
||||
|
||||
<a-form-item :label="$t('label.deployasis')" v-if="hyperVMWShow">
|
||||
<a-switch
|
||||
v-decorator="['deployasis', {
|
||||
initialValue: false,
|
||||
}]"
|
||||
:checked="deployasis"
|
||||
@change="val => deployasis = val"/>
|
||||
</a-form-item>
|
||||
|
||||
<a-row :gutter="12" v-if="hyperKVMShow || hyperVMWShow">
|
||||
<a-col :md="24" :lg="24" v-if="hyperKVMShow">
|
||||
<a-col :md="24" :lg="24" v-if="hyperKVMShow || (hyperVMWShow && !deployasis)">
|
||||
<a-form-item :label="$t('label.rootdiskcontrollertype')">
|
||||
<a-select
|
||||
v-decorator="['rootDiskControllerType', {
|
||||
@ -230,7 +240,7 @@
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :md="24" :lg="24">
|
||||
<a-form-item v-if="hyperVMWShow" :label="$t('label.keyboardtype')">
|
||||
<a-form-item v-if="hyperVMWShow && !deployasis" :label="$t('label.keyboardtype')">
|
||||
<a-select
|
||||
v-decorator="['keyboardType', {
|
||||
rules: [
|
||||
@ -248,7 +258,7 @@
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row :gutter="12" v-if="!hyperVMWShow">
|
||||
<a-row :gutter="12" v-if="!hyperVMWShow || (hyperVMWShow && !deployasis)">
|
||||
<a-col :md="24" :lg="24">
|
||||
<a-form-item :label="$t('label.ostypeid')">
|
||||
<a-select
|
||||
@ -378,6 +388,7 @@ export default {
|
||||
hyperKVMShow: false,
|
||||
hyperXenServerShow: false,
|
||||
hyperVMWShow: false,
|
||||
deployasis: false,
|
||||
zoneError: '',
|
||||
zoneErrorMessage: '',
|
||||
loading: false,
|
||||
@ -763,6 +774,7 @@ export default {
|
||||
this.hyperXenServerShow = false
|
||||
this.hyperVMWShow = false
|
||||
this.hyperKVMShow = false
|
||||
this.deployasis = false
|
||||
this.allowDirectDownload = false
|
||||
|
||||
this.resetSelect()
|
||||
@ -794,10 +806,6 @@ export default {
|
||||
continue
|
||||
}
|
||||
params[key] = input.join()
|
||||
} else if (key === 'zoneid') {
|
||||
params[key] = input
|
||||
} else if (key === 'ostypeid') {
|
||||
params[key] = input
|
||||
} else if (key === 'hypervisor') {
|
||||
params[key] = this.hyperVisor.opts[input].name
|
||||
} else if (key === 'groupenabled') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user