Skip to content

Commit fdc33d4

Browse files
committed
refactor: enhance effective CD-ROM max count logic to handle missing host IDs and improve cluster ID retrieval
1 parent aca4d84 commit fdc33d4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import com.cloud.host.ControlState;
6565
import com.cloud.host.DetailVO;
6666
import com.cloud.host.Host;
67+
import com.cloud.host.HostVO;
68+
import com.cloud.host.dao.HostDao;
6769
import com.cloud.host.dao.HostDetailsDao;
6870
import com.cloud.network.IpAddress;
6971
import com.cloud.network.vpc.VpcVO;
@@ -139,6 +141,8 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
139141
@Inject
140142
HostDetailsDao hostDetailsDao;
141143
@Inject
144+
HostDao hostDao;
145+
@Inject
142146
ExtensionHelper extensionHelper;
143147

144148
private final SearchBuilder<UserVmJoinVO> VmDetailSearch;
@@ -564,8 +568,17 @@ private long computeLeaseDurationFromExpiryDate(Date created, Date leaseExpiryDa
564568
}
565569

566570
int effectiveCdromMaxCount(UserVmJoinVO userVm) {
567-
int configuredCap = TemplateManager.VmIsoMaxCount.valueIn(userVm.getClusterId());
568-
int hypervisorCap = advertisedCdromCap(userVm.getHostId() != null ? userVm.getHostId() : userVm.getLastHostId());
571+
Long hostId = userVm.getHostId() != null && userVm.getHostId() > 0
572+
? userVm.getHostId() : userVm.getLastHostId();
573+
Long clusterId = userVm.getClusterId();
574+
if (clusterId == null && hostId != null) {
575+
HostVO host = hostDao.findById(hostId);
576+
if (host != null) {
577+
clusterId = host.getClusterId();
578+
}
579+
}
580+
int configuredCap = TemplateManager.VmIsoMaxCount.valueIn(clusterId);
581+
int hypervisorCap = advertisedCdromCap(hostId);
569582
// List endpoint clamps for display robustness; the action paths in TemplateManagerImpl
570583
// throw on misconfiguration so operators still see the loud error when they try to attach.
571584
return Math.min(configuredCap, hypervisorCap);

0 commit comments

Comments
 (0)