Skip to content

Commit 85b44e9

Browse files
GaOrtigaGabriel
authored andcommitted
Refactor configuration SystemVMDefaultHypervisor (apache#8934)
* refactor configuration SystemVMDefaultHypervisor * change variable name --------- Co-authored-by: Gabriel <gabriel.fernandes@scclouds.com.br>
1 parent 55d50ba commit 85b44e9

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

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
@@ -79,6 +79,11 @@ public interface ResourceManager extends ResourceService, Configurable {
7979
ConfigKey.Kind.Select,
8080
"," + CPU.CPUArch.getTypesAsCSV());
8181

82+
ConfigKey<String> SystemVMDefaultHypervisor = new ConfigKey<String>(String.class,
83+
"system.vm.default.hypervisor", "Advanced", "Any", "Hypervisor type used to create System VMs. Valid values are: XenServer, KVM, VMware, Hyperv, VirtualBox, " +
84+
"Parralels, BareMetal, Ovm, LXC, Any", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.Select, "XenServer, KVM, VMware, Hyperv, " +
85+
"VirtualBox, Parralels, BareMetal, Ovm, LXC, Any");
86+
8287
/**
8388
* Register a listener for different types of resource life cycle events.
8489
* 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
@@ -542,13 +542,6 @@ public enum Config {
542542
"true",
543543
"Indicates whether or not to automatically reserver system VM standby capacity.",
544544
null),
545-
SystemVMDefaultHypervisor("Advanced",
546-
ManagementServer.class,
547-
String.class,
548-
"system.vm.default.hypervisor",
549-
null,
550-
"Hypervisor type used to create system vm, valid values are: XenServer, KVM, VMware, Hyperv, VirtualBox, Parralels, BareMetal, Ovm, LXC, Any",
551-
null),
552545
SystemVMRandomPassword(
553546
"Advanced",
554547
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
@@ -352,7 +352,6 @@ public void setDiscoverers(final List<? extends Discoverer> discoverers) {
352352
private final HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<>();
353353

354354
private final HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<>();
355-
private HypervisorType _defaultSystemVMHypervisor;
356355

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

@@ -2935,7 +2934,6 @@ public DataCenter getZone(Long zoneId) {
29352934

29362935
@Override
29372936
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
2938-
_defaultSystemVMHypervisor = HypervisorType.getType(_configDao.getValue(Config.SystemVMDefaultHypervisor.toString()));
29392937
_gson = GsonHelper.getGson();
29402938

29412939
_hypervisorsInDC = _hostDao.createSearchBuilder(String.class);
@@ -2981,10 +2979,7 @@ public List<HypervisorType> getSupportedHypervisorTypes(final long zoneId, final
29812979

29822980
@Override
29832981
public HypervisorType getDefaultHypervisor(final long zoneId) {
2984-
HypervisorType defaultHyper = HypervisorType.None;
2985-
if (_defaultSystemVMHypervisor != HypervisorType.None) {
2986-
defaultHyper = _defaultSystemVMHypervisor;
2987-
}
2982+
HypervisorType systemVMDefaultHypervisor = HypervisorType.getType(ResourceManager.SystemVMDefaultHypervisor.value());
29882983

29892984
final DataCenterVO dc = _dcDao.findById(zoneId);
29902985
if (dc == null) {
@@ -2993,27 +2988,27 @@ public HypervisorType getDefaultHypervisor(final long zoneId) {
29932988
_dcDao.loadDetails(dc);
29942989
final String defaultHypervisorInZone = dc.getDetail("defaultSystemVMHypervisorType");
29952990
if (defaultHypervisorInZone != null) {
2996-
defaultHyper = HypervisorType.getType(defaultHypervisorInZone);
2991+
systemVMDefaultHypervisor = HypervisorType.getType(defaultHypervisorInZone);
29972992
}
29982993

29992994
final List<VMTemplateVO> systemTemplates = _templateDao.listAllSystemVMTemplates();
30002995
boolean isValid = false;
30012996
for (final VMTemplateVO template : systemTemplates) {
3002-
if (template.getHypervisorType() == defaultHyper) {
2997+
if (template.getHypervisorType() == systemVMDefaultHypervisor) {
30032998
isValid = true;
30042999
break;
30053000
}
30063001
}
30073002

30083003
if (isValid) {
3009-
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
3004+
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, systemVMDefaultHypervisor.toString());
30103005
if (clusters.isEmpty()) {
30113006
isValid = false;
30123007
}
30133008
}
30143009

30153010
if (isValid) {
3016-
return defaultHyper;
3011+
return systemVMDefaultHypervisor;
30173012
} else {
30183013
return HypervisorType.None;
30193014
}
@@ -4578,7 +4573,8 @@ public ConfigKey<?>[] getConfigKeys() {
45784573
return new ConfigKey<?>[] {
45794574
KvmSshToAgentEnabled,
45804575
HOST_MAINTENANCE_LOCAL_STRATEGY,
4581-
SystemVmPreferredArchitecture
4576+
SystemVmPreferredArchitecture,
4577+
SystemVMDefaultHypervisor
45824578
};
45834579
}
45844580
}

0 commit comments

Comments
 (0)