Skip to content

Commit a38c383

Browse files
committed
refactor: enhance host ID retrieval logic for VMs based on hypervisor type
1 parent 80e87df commit a38c383

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,14 @@ int advertisedCdromCap(Long hostId) {
15991599
}
16001600

16011601
Long hostIdForVm(VirtualMachine vm) {
1602-
return vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
1602+
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
1603+
if (hostId == null && vm.getHypervisorType() != null) {
1604+
List<HostVO> candidates = _hostDao.listByDataCenterIdAndHypervisorType(vm.getDataCenterId(), vm.getHypervisorType());
1605+
if (!candidates.isEmpty()) {
1606+
hostId = candidates.get(0).getId();
1607+
}
1608+
}
1609+
return hostId;
16031610
}
16041611

16051612
@Override

0 commit comments

Comments
 (0)