Skip to content

Commit d5ab297

Browse files
committed
Revert "xen/xcpng: revert java changes in PR apache#4672"
This reverts commit a83b902.
1 parent 4c6b407 commit d5ab297

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.cloud.hypervisor;
1818

1919
import java.util.ArrayList;
20+
import java.util.Comparator;
2021
import java.util.List;
2122
import java.util.Map;
2223

@@ -95,7 +96,14 @@ public VirtualMachineTO implement(VirtualMachineProfile vm) {
9596
if (userVmVO != null) {
9697
HostVO host = hostDao.findById(userVmVO.getHostId());
9798
if (host != null) {
98-
to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId()));
99+
List<HostVO> clusterHosts = hostDao.listByClusterAndHypervisorType(host.getClusterId(), host.getHypervisorType());
100+
HostVO hostWithMinSocket = clusterHosts.stream().min(Comparator.comparing(HostVO::getCpuSockets)).orElse(null);
101+
Integer vCpus = MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId());
102+
if (hostWithMinSocket != null && hostWithMinSocket.getCpuSockets() != null &&
103+
hostWithMinSocket.getCpuSockets() < vCpus) {
104+
vCpus = hostWithMinSocket.getCpuSockets();
105+
}
106+
to.setVcpuMaxLimit(vCpus);
99107
}
100108
}
101109

0 commit comments

Comments
 (0)