Skip to content

Commit 4093b72

Browse files
GaOrtigadhslove
authored andcommitted
Refactor configuration SystemVMDefaultHypervisor (apache#8934)
* refactor configuration SystemVMDefaultHypervisor * change variable name --------- Co-authored-by: Gabriel <gabriel.fernandes@scclouds.com.br>
1 parent 72e2b8a commit 4093b72

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

engine/components-api/src/main/java/com/cloud/resource/ResourceManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public interface ResourceManager extends ResourceService, Configurable {
8484
ConfigKey.Kind.Select,
8585
"," + CPU.CPUArch.getTypesAsCSV());
8686

87+
ConfigKey<String> SystemVMDefaultHypervisor = new ConfigKey<String>(String.class,
88+
"system.vm.default.hypervisor", "Advanced", "Any", "Hypervisor type used to create System VMs. Valid values are: XenServer, KVM, VMware, Hyperv, VirtualBox, " +
89+
"Parralels, BareMetal, Ovm, LXC, Any", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.Select, "XenServer, KVM, VMware, Hyperv, " +
90+
"VirtualBox, Parralels, BareMetal, Ovm, LXC, Any");
91+
8792
/**
8893
* Register a listener for different types of resource life cycle events.
8994
* There can only be one type of listener per type of host.

server/src/main/java/com/cloud/configuration/Config.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,6 @@ public enum Config {
658658
"true",
659659
"Indicates whether or not to automatically reserver system VM standby capacity.",
660660
null),
661-
SystemVMDefaultHypervisor("Advanced",
662-
ManagementServer.class,
663-
String.class,
664-
"system.vm.default.hypervisor",
665-
null,
666-
"Hypervisor type used to create system vm, valid values are: XenServer, KVM, VMware, Hyperv, VirtualBox, Parralels, BareMetal, Ovm, LXC, Any",
667-
null),
668661
SystemVMRandomPassword(
669662
"Advanced",
670663
ManagementServer.class,

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ public void setDiscoverers(final List<? extends Discoverer> discoverers) {
353353
private final HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<>();
354354

355355
private final HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<>();
356-
private HypervisorType _defaultSystemVMHypervisor;
357356

358357
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 30; // seconds
359358

@@ -2956,7 +2955,6 @@ public DataCenter getZone(Long zoneId) {
29562955

29572956
@Override
29582957
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
2959-
_defaultSystemVMHypervisor = HypervisorType.getType(_configDao.getValue(Config.SystemVMDefaultHypervisor.toString()));
29602958
_gson = GsonHelper.getGson();
29612959

29622960
_hypervisorsInDC = _hostDao.createSearchBuilder(String.class);
@@ -3002,10 +3000,7 @@ public List<HypervisorType> getSupportedHypervisorTypes(final long zoneId, final
30023000

30033001
@Override
30043002
public HypervisorType getDefaultHypervisor(final long zoneId) {
3005-
HypervisorType defaultHyper = HypervisorType.None;
3006-
if (_defaultSystemVMHypervisor != HypervisorType.None) {
3007-
defaultHyper = _defaultSystemVMHypervisor;
3008-
}
3003+
HypervisorType systemVMDefaultHypervisor = HypervisorType.getType(ResourceManager.SystemVMDefaultHypervisor.value());
30093004

30103005
final DataCenterVO dc = _dcDao.findById(zoneId);
30113006
if (dc == null) {
@@ -3014,27 +3009,27 @@ public HypervisorType getDefaultHypervisor(final long zoneId) {
30143009
_dcDao.loadDetails(dc);
30153010
final String defaultHypervisorInZone = dc.getDetail("defaultSystemVMHypervisorType");
30163011
if (defaultHypervisorInZone != null) {
3017-
defaultHyper = HypervisorType.getType(defaultHypervisorInZone);
3012+
systemVMDefaultHypervisor = HypervisorType.getType(defaultHypervisorInZone);
30183013
}
30193014

30203015
final List<VMTemplateVO> systemTemplates = _templateDao.listAllSystemVMTemplates();
30213016
boolean isValid = false;
30223017
for (final VMTemplateVO template : systemTemplates) {
3023-
if (template.getHypervisorType() == defaultHyper) {
3018+
if (template.getHypervisorType() == systemVMDefaultHypervisor) {
30243019
isValid = true;
30253020
break;
30263021
}
30273022
}
30283023

30293024
if (isValid) {
3030-
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
3025+
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, systemVMDefaultHypervisor.toString());
30313026
if (clusters.isEmpty()) {
30323027
isValid = false;
30333028
}
30343029
}
30353030

30363031
if (isValid) {
3037-
return defaultHyper;
3032+
return systemVMDefaultHypervisor;
30383033
} else {
30393034
return HypervisorType.None;
30403035
}
@@ -4630,7 +4625,8 @@ public ConfigKey<?>[] getConfigKeys() {
46304625
KvmSshToAgentEnabled,
46314626
KvmSshPort,
46324627
HOST_MAINTENANCE_LOCAL_STRATEGY,
4633-
SystemVmPreferredArchitecture
4628+
SystemVmPreferredArchitecture,
4629+
SystemVMDefaultHypervisor
46344630
};
46354631
}
46364632
}

0 commit comments

Comments
 (0)