mirror of https://github.com/apache/cloudstack.git
Allow deletion of system VM templates (#8556)
* allow delete system VM templates * Add isSystem parameter * add authorized --------- Co-authored-by: Gabriel <gabriel.fernandes@scclouds.com.br>
This commit is contained in:
parent
01c721fcda
commit
8ca1843efa
|
|
@ -18,6 +18,7 @@ package org.apache.cloudstack.api.command.user.template;
|
|||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
|
|
@ -53,6 +54,9 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
|
|||
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force delete a template.", since = "4.9+")
|
||||
private Boolean forced;
|
||||
|
||||
@Parameter(name = ApiConstants.IS_SYSTEM, type = CommandType.BOOLEAN, required = false, description = "Necessary if the template's type is system.", since = "4.20.0", authorized = {RoleType.Admin})
|
||||
private Boolean isSystem;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -69,6 +73,10 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
|
|||
return BooleanUtils.toBooleanDefaultIfNull(forced, false);
|
||||
}
|
||||
|
||||
public boolean getIsSystem() {
|
||||
return BooleanUtils.toBooleanDefaultIfNull(isSystem, false);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -752,8 +752,8 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
|
||||
TemplateProfile profile = super.prepareDelete(cmd);
|
||||
VMTemplateVO template = profile.getTemplate();
|
||||
if (template.getTemplateType() == TemplateType.SYSTEM) {
|
||||
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
|
||||
if (template.getTemplateType() == TemplateType.SYSTEM && !cmd.getIsSystem()) {
|
||||
throw new InvalidParameterValueException("Could not delete template as it is a SYSTEM template and isSystem is set to false.");
|
||||
}
|
||||
checkZoneImageStores(profile.getTemplate(), profile.getZoneIdList());
|
||||
return profile;
|
||||
|
|
|
|||
Loading…
Reference in New Issue