Skip to content

Commit 7188f28

Browse files
committed
server: fix available hypervisors listing for a zone
In the absence of a SYSTEM type template for a zone, listing of templates can break. Behaviour was change in apache#9840 but it would be better to find available hypervisors using existing hosts.
1 parent a09354d commit 7188f28

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,12 +3266,16 @@ public List<HostVO> listAllHostsInAllZonesByType(final Type type) {
32663266

32673267
@Override
32683268
public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
3269-
List<VMTemplateVO> systemVMTemplates = _templateDao.listAllReadySystemVMTemplates(zoneId);
3270-
final Set<HypervisorType> hypervisors = new HashSet<>();
3271-
for (final VMTemplateVO systemVMTemplate : systemVMTemplates) {
3272-
hypervisors.add(systemVMTemplate.getHypervisorType());
3269+
final SearchCriteria<String> sc = _hypervisorsInDC.create();
3270+
if (zoneId != null) {
3271+
sc.setParameters("dataCenter", zoneId);
32733272
}
3274-
return new ArrayList<>(hypervisors);
3273+
sc.setParameters("type", Host.Type.Routing);
3274+
3275+
return _hostDao.customSearch(sc, null).stream()
3276+
// The search is not able to return list of enums, so getting
3277+
// list of hypervisors as strings and then converting them to enum
3278+
.map(HypervisorType::getType).collect(Collectors.toList());
32753279
}
32763280

32773281
@Override

0 commit comments

Comments
 (0)