Skip to content

Commit e77a2f8

Browse files
authored
Merge pull request #868 from anshul1886/CLOUDSTACK-8894
CLOUDSTACK-8894: Restrict vGPU enabled VMs dynamic scaling if new service offering has different vGPU type
2 parents 8b3cadb + f9f0e50 commit e77a2f8

1 file changed

Lines changed: 42 additions & 29 deletions

File tree

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
16481648
// Check that the specified service offering ID is valid
16491649
_itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
16501650

1651-
ServiceOffering currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
1651+
ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
16521652
int newCpu = newServiceOffering.getCpu();
16531653
int newMemory = newServiceOffering.getRamSize();
16541654
int newSpeed = newServiceOffering.getSpeed();
@@ -1665,6 +1665,19 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
16651665
+ ",memory=," + currentMemory + ")");
16661666
}
16671667

1668+
_offeringDao.loadDetails(currentServiceOffering);
1669+
_offeringDao.loadDetails(newServiceOffering);
1670+
1671+
Map<String, String> currentDetails = currentServiceOffering.getDetails();
1672+
Map<String, String> newDetails = newServiceOffering.getDetails();
1673+
String currentVgpuType = currentDetails.get("vgpuType");
1674+
String newVgpuType = newDetails.get("vgpuType");
1675+
if(currentVgpuType != null) {
1676+
if(newVgpuType == null || !newVgpuType.equalsIgnoreCase(currentVgpuType)) {
1677+
throw new InvalidParameterValueException("Dynamic scaling of vGPU type is not supported. VM has vGPU Type: " + currentVgpuType);
1678+
}
1679+
}
1680+
16681681
// Check resource limits
16691682
if (newCpu > currentCpu) {
16701683
_resourceLimitMgr.checkResourceLimit(caller, ResourceType.cpu, newCpu - currentCpu);
@@ -1870,54 +1883,54 @@ public UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationE
18701883
}
18711884

18721885
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<ResourceAllocationException>() {
1873-
@Override
1874-
public void doInTransactionWithoutResult(TransactionStatus status) throws ResourceAllocationException {
1886+
@Override public void doInTransactionWithoutResult(TransactionStatus status) throws ResourceAllocationException {
18751887

18761888
Account account = _accountDao.lockRow(vm.getAccountId(), true);
18771889

1878-
// if the account is deleted, throw error
1879-
if (account.getRemoved() != null) {
1890+
// if the account is deleted, throw error
1891+
if (account.getRemoved() != null) {
18801892
throw new CloudRuntimeException("Unable to recover VM as the account is deleted");
1881-
}
1893+
}
18821894

1883-
// Get serviceOffering for Virtual Machine
1895+
// Get serviceOffering for Virtual Machine
18841896
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
18851897

1886-
// First check that the maximum number of UserVMs, CPU and Memory limit for the given
1887-
// accountId will not be exceeded
1898+
// First check that the maximum number of UserVMs, CPU and Memory limit for the given
1899+
// accountId will not be exceeded
18881900
resourceLimitCheck(account, vm.isDisplayVm(), new Long(serviceOffering.getCpu()), new Long(serviceOffering.getRamSize()));
18891901

1890-
_haMgr.cancelDestroy(vm, vm.getHostId());
1902+
_haMgr.cancelDestroy(vm, vm.getHostId());
18911903

1892-
try {
1904+
try {
18931905
if (!_itMgr.stateTransitTo(vm, VirtualMachine.Event.RecoveryRequested, null)) {
18941906
s_logger.debug("Unable to recover the vm because it is not in the correct state: " + vmId);
18951907
throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId);
1896-
}
1897-
} catch (NoTransitionException e) {
1908+
}
1909+
} catch (NoTransitionException e) {
18981910
throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId);
1899-
}
1911+
}
19001912

1901-
// Recover the VM's disks
1902-
List<VolumeVO> volumes = _volsDao.findByInstance(vmId);
1903-
for (VolumeVO volume : volumes) {
1904-
if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
1905-
// Create an event
1906-
Long templateId = volume.getTemplateId();
1907-
Long diskOfferingId = volume.getDiskOfferingId();
1908-
Long offeringId = null;
1909-
if (diskOfferingId != null) {
1913+
// Recover the VM's disks
1914+
List<VolumeVO> volumes = _volsDao.findByInstance(vmId);
1915+
for (VolumeVO volume : volumes) {
1916+
if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
1917+
// Create an event
1918+
Long templateId = volume.getTemplateId();
1919+
Long diskOfferingId = volume.getDiskOfferingId();
1920+
Long offeringId = null;
1921+
if (diskOfferingId != null) {
19101922
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
19111923
if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) {
1912-
offeringId = offering.getId();
1924+
offeringId = offering.getId();
1925+
}
1926+
}
1927+
UsageEventUtils
1928+
.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), offeringId,
1929+
templateId, volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());
19131930
}
19141931
}
1915-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
1916-
offeringId, templateId, volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());
1917-
}
1918-
}
19191932

1920-
//Update Resource Count for the given account
1933+
//Update Resource Count for the given account
19211934
resourceCountIncrement(account.getId(), vm.isDisplayVm(), new Long(serviceOffering.getCpu()), new Long(serviceOffering.getRamSize()));
19221935
}
19231936
});

0 commit comments

Comments
 (0)