Skip to content

Commit c81d9b0

Browse files
committed
address comments
1 parent 4dff9c1 commit c81d9b0

3 files changed

Lines changed: 34 additions & 21 deletions

File tree

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,7 @@ public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceL
221221
response.setMemoryAvailable(memoryAvail);
222222

223223
//get resource limits for gpus
224-
long gpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getGpuLimit(), account.getId(), ResourceType.gpu);
225-
String gpuLimitDisplay = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit);
226-
long gpuTotal = (account.getGpuTotal() == null) ? 0 : account.getGpuTotal();
227-
String gpuAvail = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit - gpuTotal);
228-
response.setGpuLimit(gpuLimitDisplay);
229-
response.setGpuTotal(gpuTotal);
230-
response.setGpuAvailable(gpuAvail);
224+
setGpuResourceLimits(account, fullView,response);
231225

232226
//get resource limits for primary storage space and convert it from Bytes to GiB
233227
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getPrimaryStorageLimit(), account.getId(), ResourceType.primary_storage);
@@ -287,6 +281,16 @@ public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceL
287281
response.setObjectStorageAvailable(objectStorageAvail);
288282
}
289283

284+
private void setGpuResourceLimits(AccountJoinVO account, boolean fullView, ResourceLimitAndCountResponse response) {
285+
long gpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getGpuLimit(), account.getId(), ResourceType.gpu);
286+
String gpuLimitDisplay = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit);
287+
long gpuTotal = (account.getGpuTotal() == null) ? 0 : account.getGpuTotal();
288+
String gpuAvail = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit - gpuTotal);
289+
response.setGpuLimit(gpuLimitDisplay);
290+
response.setGpuTotal(gpuTotal);
291+
response.setGpuAvailable(gpuAvail);
292+
}
293+
290294
@Override
291295
public List<AccountJoinVO> searchByIds(Long... accountIds) {
292296
// set detail batch query size

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,7 @@ public void setResourceLimits(DomainJoinVO domain, boolean fullView, ResourceLim
196196
response.setMemoryAvailable(memoryAvail);
197197

198198
//get resource limits for gpus
199-
long gpuLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getGpuLimit(), ResourceType.gpu, domain.getId());
200-
String gpuLimitDisplay = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit);
201-
long gpuTotal = (domain.getGpuTotal() == null) ? 0 : domain.getGpuTotal();
202-
String gpuAvail = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit - gpuTotal);
203-
response.setGpuLimit(gpuLimitDisplay);
204-
response.setGpuTotal(gpuTotal);
205-
response.setGpuAvailable(gpuAvail);
199+
setGpuResourceLimits(domain, fullView, response);
206200

207201
//get resource limits for primary storage space and convert it from Bytes to GiB
208202
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getPrimaryStorageLimit(), ResourceType.primary_storage, domain.getId());
@@ -259,6 +253,16 @@ public void setResourceLimits(DomainJoinVO domain, boolean fullView, ResourceLim
259253
response.setObjectStorageAvailable(objectStorageAvail);
260254
}
261255

256+
private void setGpuResourceLimits(DomainJoinVO domain, boolean fullView, ResourceLimitAndCountResponse response) {
257+
long gpuLimit = ApiDBUtils.findCorrectResourceLimitForDomain(domain.getGpuLimit(), ResourceType.gpu, domain.getId());
258+
String gpuLimitDisplay = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit);
259+
long gpuTotal = (domain.getGpuTotal() == null) ? 0 : domain.getGpuTotal();
260+
String gpuAvail = (fullView || gpuLimit == -1) ? Resource.UNLIMITED : String.valueOf(gpuLimit - gpuTotal);
261+
response.setGpuLimit(gpuLimitDisplay);
262+
response.setGpuTotal(gpuTotal);
263+
response.setGpuAvailable(gpuAvail);
264+
}
265+
262266
@Override
263267
public List<DomainJoinVO> searchByIds(Long... domainIds) {
264268
// set detail batch query size

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,13 +1549,7 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
15491549
throw new InvalidParameterValueException("Unsupported operation, VM uses Local storage, cannot migrate");
15501550
}
15511551

1552-
ServiceOffering serviceOffering = vmProfile.getServiceOffering();
1553-
if (serviceOffering.getVgpuProfileId() != null) {
1554-
VgpuProfileVO vgpuProfile = vgpuProfileDao.findById(serviceOffering.getVgpuProfileId());
1555-
if (vgpuProfile == null || "passthrough".equals(vgpuProfile.getName())) {
1556-
throw new InvalidParameterValueException("Unsupported operation, VM uses host passthrough, cannot migrate");
1557-
}
1558-
}
1552+
validateVgpuProfileForVmMigration(vmProfile);
15591553

15601554
final Type hostType = srcHost.getType();
15611555
Pair<List<HostVO>, Integer> allHostsPair = null;
@@ -1683,6 +1677,17 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
16831677
return new Ternary<>(otherHosts, suitableHosts, requiresStorageMotion);
16841678
}
16851679

1680+
private void validateVgpuProfileForVmMigration(final VirtualMachineProfile vmProfile) {
1681+
// Validate if the VM is using a vGPU profile that supports migration.
1682+
ServiceOffering serviceOffering = vmProfile.getServiceOffering();
1683+
if (serviceOffering.getVgpuProfileId() != null) {
1684+
VgpuProfileVO vgpuProfile = vgpuProfileDao.findById(serviceOffering.getVgpuProfileId());
1685+
if (vgpuProfile == null || "passthrough".equals(vgpuProfile.getName())) {
1686+
throw new InvalidParameterValueException("Unsupported operation, VM uses host passthrough, cannot migrate");
1687+
}
1688+
}
1689+
}
1690+
16861691
/**
16871692
* Add non DPDK enabled hosts to the avoid list
16881693
*/

0 commit comments

Comments
 (0)