Skip to content

Commit 8ca1843

Browse files
authored
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>
1 parent 01c721f commit 8ca1843

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.lang3.BooleanUtils;
2020

21+
import org.apache.cloudstack.acl.RoleType;
2122
import org.apache.cloudstack.api.APICommand;
2223
import org.apache.cloudstack.api.ApiCommandResourceType;
2324
import org.apache.cloudstack.api.ApiConstants;
@@ -53,6 +54,9 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
5354
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force delete a template.", since = "4.9+")
5455
private Boolean forced;
5556

57+
@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})
58+
private Boolean isSystem;
59+
5660
/////////////////////////////////////////////////////
5761
/////////////////// Accessors ///////////////////////
5862
/////////////////////////////////////////////////////
@@ -69,6 +73,10 @@ public boolean isForced() {
6973
return BooleanUtils.toBooleanDefaultIfNull(forced, false);
7074
}
7175

76+
public boolean getIsSystem() {
77+
return BooleanUtils.toBooleanDefaultIfNull(isSystem, false);
78+
}
79+
7280
/////////////////////////////////////////////////////
7381
/////////////// API Implementation///////////////////
7482
/////////////////////////////////////////////////////

server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ void checkAndRemoveTemplateDetails(VMTemplateVO template) {
752752
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
753753
TemplateProfile profile = super.prepareDelete(cmd);
754754
VMTemplateVO template = profile.getTemplate();
755-
if (template.getTemplateType() == TemplateType.SYSTEM) {
756-
throw new InvalidParameterValueException("The DomR template cannot be deleted.");
755+
if (template.getTemplateType() == TemplateType.SYSTEM && !cmd.getIsSystem()) {
756+
throw new InvalidParameterValueException("Could not delete template as it is a SYSTEM template and isSystem is set to false.");
757757
}
758758
checkZoneImageStores(profile.getTemplate(), profile.getZoneIdList());
759759
return profile;

0 commit comments

Comments
 (0)