Skip to content

Commit 4c3865e

Browse files
author
Daniel Augusto Veronezi Salvador
committed
Merge branch 'template-settings-deny-list-config-4.20' into '4.20.0.0-scclouds'
Port 4.20 - Configuração para desconsiderar _settings_ durante a criação de templates See merge request scclouds/scclouds!993
2 parents ad88803 + d531f7c commit 4c3865e

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

engine/components-api/src/main/java/com/cloud/template/TemplateManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public interface TemplateManager {
5656
+ "will validate if the provided URL is resolvable during the register of templates/ISOs before persisting them in the database.",
5757
true);
5858

59+
ConfigKey<String> TemplateSettingsInheritanceDenyList = new ConfigKey<>(
60+
String.class,
61+
"template.settings.inheritance.deny.list",
62+
"Advanced",
63+
"",
64+
"List of settings to not consider when creating a template. The template settings are inherited from the instance the volume or snapshot belongs to.",
65+
true,
66+
ConfigKey.Scope.Global, null, null, null, null, null,
67+
ConfigKey.Kind.CSV, null);
68+
5969
static final String VMWARE_TOOLS_ISO = "vmware-tools.iso";
6070
static final String XS_TOOLS_ISO = "xs-tools.iso";
6171

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,7 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
19601960
VMTemplateVO template = _tmpltDao.persist(privateTemplate);
19611961
// Increment the number of templates
19621962
if (template != null) {
1963+
List<String> templateSettingsDenyList = List.of(TemplateSettingsInheritanceDenyList.value().split(","));
19631964
Map<String, String> details = new HashMap<String, String>();
19641965

19651966
if (sourceTemplateId != null) {
@@ -1976,9 +1977,10 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
19761977
if (userVm != null) {
19771978
_userVmDao.loadDetails(userVm);
19781979
Map<String, String> vmDetails = userVm.getDetails();
1980+
logger.debug("Removing the {} settings from template because they were defined in the {} global setting.", templateSettingsDenyList, TemplateSettingsInheritanceDenyList.key());
19791981
vmDetails = vmDetails.entrySet()
19801982
.stream()
1981-
.filter(map -> map.getValue() != null)
1983+
.filter(map -> map.getValue() != null && !templateSettingsDenyList.contains(map.getKey()))
19821984
.collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
19831985
details.putAll(vmDetails);
19841986
}
@@ -2364,7 +2366,7 @@ public String getConfigComponentName() {
23642366

23652367
@Override
23662368
public ConfigKey<?>[] getConfigKeys() {
2367-
return new ConfigKey<?>[] {AllowPublicUserTemplates, TemplatePreloaderPoolSize, ValidateUrlIsResolvableBeforeRegisteringTemplate};
2369+
return new ConfigKey<?>[] {AllowPublicUserTemplates, TemplatePreloaderPoolSize, ValidateUrlIsResolvableBeforeRegisteringTemplate, TemplateSettingsInheritanceDenyList};
23682370
}
23692371

23702372
public List<TemplateAdapter> getTemplateAdapters() {

0 commit comments

Comments
 (0)