Skip to content

Commit 642ad06

Browse files
GaOrtigadhslove
authored andcommitted
Allow deletion of system VM templates (apache#8556)
* allow delete system VM templates * Add isSystem parameter * add authorized --------- Co-authored-by: Gabriel <gabriel.fernandes@scclouds.com.br>
1 parent 490ffbc commit 642ad06

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;
@@ -56,6 +57,9 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
5657
@Parameter(name=ApiConstants.DESKTOP_CHECK, type = CommandType.BOOLEAN, required=false, description="Verify that it is a desktop template.")
5758
protected Boolean isDesktop;
5859

60+
@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})
61+
private Boolean isSystem;
62+
5963
/////////////////////////////////////////////////////
6064
/////////////////// Accessors ///////////////////////
6165
/////////////////////////////////////////////////////
@@ -83,6 +87,10 @@ public Boolean isDesktop() {
8387
public void setIsDesktop(Boolean isDesktop) {
8488
this.isDesktop = isDesktop;
8589
}
90+
91+
public boolean getIsSystem() {
92+
return BooleanUtils.toBooleanDefaultIfNull(isSystem, false);
93+
}
8694

8795
/////////////////////////////////////////////////////
8896
/////////////// API Implementation///////////////////

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)