Skip to content

Commit 37d2264

Browse files
authored
simulator: Add support to scale a VM (apache#5515)
* simulator: Add support to scale VM * make list a constant
1 parent 75c15fd commit 37d2264

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
294294

295295
protected Gson _gson;
296296

297+
private static final List<HypervisorType> SupportedHypervisorsForVolResize = Arrays.asList(HypervisorType.KVM, HypervisorType.XenServer,
298+
HypervisorType.VMware, HypervisorType.Any, HypervisorType.None);
297299
private List<StoragePoolAllocator> _storagePoolAllocators;
298300

299301
private List<HypervisorType> supportingDefaultHV;
@@ -965,10 +967,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
965967
/* Only works for KVM/XenServer/VMware (or "Any") for now, and volumes with 'None' since they're just allocated in DB */
966968

967969
HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId());
968-
969-
if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.XenServer
970-
&& hypervisorType != HypervisorType.VMware && hypervisorType != HypervisorType.Any
971-
&& hypervisorType != HypervisorType.None) {
970+
if (!SupportedHypervisorsForVolResize.contains(hypervisorType)) {
972971
throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support volume resize");
973972
}
974973

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,12 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String
12821282
rootVolumeOfVm.setDiskOfferingId(newRootDiskOffering.getId());
12831283
_volsDao.update(rootVolumeOfVm.getId(), rootVolumeOfVm);
12841284
}
1285-
1286-
_volumeService.resizeVolume(resizeVolumeCmd);
1285+
HypervisorType hypervisorType = _volsDao.getHypervisorType(rootVolumeOfVm.getId());
1286+
if (HypervisorType.Simulator != hypervisorType) {
1287+
_volumeService.resizeVolume(resizeVolumeCmd);
1288+
} else if (newRootDiskOffering.getDiskSize() > 0 && currentRootDiskOffering.getDiskSize() != newRootDiskOffering.getDiskSize()) {
1289+
throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support volume resize");
1290+
}
12871291
}
12881292

12891293
_itMgr.upgradeVmDb(vmId, newServiceOffering, currentServiceOffering);

0 commit comments

Comments
 (0)