Skip to content

Commit 4a779de

Browse files
authored
server: fix on changeServiceForVirtualMachine when updating read/write rate (#4491)
When changing the service offering of a VM the disk_offering_id is not updated in volumes DB table and VM could not start Fixes #4125
1 parent b84a675 commit 4a779de

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,8 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE
10351035
// Check that the specified service offering ID is valid
10361036
_itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
10371037

1038+
resizeRootVolumeOfVmWithNewOffering(vmInstance, newServiceOffering);
1039+
10381040
_itMgr.upgradeVmDb(vmId, newServiceOffering, currentServiceOffering);
10391041

10401042
// Increment or decrement CPU and Memory count accordingly.
@@ -1139,19 +1141,7 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String
11391141
// Check that the specified service offering ID is valid
11401142
_itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
11411143

1142-
DiskOfferingVO newROOTDiskOffering = _diskOfferingDao.findById(newServiceOffering.getId());
1143-
1144-
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vmInstance.getId());
1145-
1146-
for (final VolumeVO rootVolumeOfVm : vols) {
1147-
rootVolumeOfVm.setDiskOfferingId(newROOTDiskOffering.getId());
1148-
1149-
_volsDao.update(rootVolumeOfVm.getId(), rootVolumeOfVm);
1150-
1151-
ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd(rootVolumeOfVm.getId(), newROOTDiskOffering.getMinIops(), newROOTDiskOffering.getMaxIops());
1152-
1153-
_volumeService.resizeVolume(resizeVolumeCmd);
1154-
}
1144+
resizeRootVolumeOfVmWithNewOffering(vmInstance, newServiceOffering);
11551145

11561146
// Check if the new service offering can be applied to vm instance
11571147
ServiceOffering newSvcOffering = _offeringDao.findById(svcOffId);
@@ -1177,6 +1167,23 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String
11771167

11781168
}
11791169

1170+
private void resizeRootVolumeOfVmWithNewOffering(VMInstanceVO vmInstance, ServiceOfferingVO newServiceOffering)
1171+
throws ResourceAllocationException {
1172+
DiskOfferingVO newROOTDiskOffering = _diskOfferingDao.findById(newServiceOffering.getId());
1173+
1174+
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vmInstance.getId());
1175+
1176+
for (final VolumeVO rootVolumeOfVm : vols) {
1177+
rootVolumeOfVm.setDiskOfferingId(newROOTDiskOffering.getId());
1178+
1179+
ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd(rootVolumeOfVm.getId(), newROOTDiskOffering.getMinIops(), newROOTDiskOffering.getMaxIops());
1180+
1181+
_volumeService.resizeVolume(resizeVolumeCmd);
1182+
1183+
_volsDao.update(rootVolumeOfVm.getId(), rootVolumeOfVm);
1184+
}
1185+
}
1186+
11801187
@Override
11811188
@ActionEvent(eventType = EventTypes.EVENT_NIC_CREATE, eventDescription = "Creating Nic", async = true)
11821189
public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, CloudRuntimeException {

0 commit comments

Comments
 (0)