This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 37d2264  simulator: Add support to scale a VM (#5515)
37d2264 is described below

commit 37d22646b2fae74c83d362e383b54b35309f6848
Author: Pearl Dsilva <[email protected]>
AuthorDate: Wed Sep 29 09:47:58 2021 +0530

    simulator: Add support to scale a VM (#5515)
    
    * simulator: Add support to scale VM
    
    * make list a constant
---
 server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java | 7 +++----
 server/src/main/java/com/cloud/vm/UserVmManagerImpl.java         | 8 ++++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index c900197..e0852da 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -294,6 +294,8 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
 
     protected Gson _gson;
 
+    private static final List<HypervisorType> SupportedHypervisorsForVolResize 
= Arrays.asList(HypervisorType.KVM, HypervisorType.XenServer,
+            HypervisorType.VMware, HypervisorType.Any, HypervisorType.None);
     private List<StoragePoolAllocator> _storagePoolAllocators;
 
     private List<HypervisorType> supportingDefaultHV;
@@ -965,10 +967,7 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
         /* Only works for KVM/XenServer/VMware (or "Any") for now, and volumes 
with 'None' since they're just allocated in DB */
 
         HypervisorType hypervisorType = 
_volsDao.getHypervisorType(volume.getId());
-
-        if (hypervisorType != HypervisorType.KVM && hypervisorType != 
HypervisorType.XenServer
-                && hypervisorType != HypervisorType.VMware && hypervisorType 
!= HypervisorType.Any
-                && hypervisorType != HypervisorType.None) {
+        if (!SupportedHypervisorsForVolResize.contains(hypervisorType)) {
             throw new InvalidParameterValueException("Hypervisor " + 
hypervisorType + " does not support volume resize");
         }
 
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index 6a5054f..44bb79e 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -1282,8 +1282,12 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 rootVolumeOfVm.setDiskOfferingId(newRootDiskOffering.getId());
                 _volsDao.update(rootVolumeOfVm.getId(), rootVolumeOfVm);
             }
-
-            _volumeService.resizeVolume(resizeVolumeCmd);
+            HypervisorType hypervisorType = 
_volsDao.getHypervisorType(rootVolumeOfVm.getId());
+            if (HypervisorType.Simulator != hypervisorType) {
+                _volumeService.resizeVolume(resizeVolumeCmd);
+            } else if (newRootDiskOffering.getDiskSize() > 0 && 
currentRootDiskOffering.getDiskSize() != newRootDiskOffering.getDiskSize()) {
+                throw new InvalidParameterValueException("Hypervisor " + 
hypervisorType + " does not support volume resize");
+            }
         }
 
         _itMgr.upgradeVmDb(vmId, newServiceOffering, currentServiceOffering);

Reply via email to