cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajeshbatt...@apache.org
Subject [1/4] git commit: updated refs/heads/4.5 to bcc2038
Date Tue, 18 Nov 2014 08:42:33 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.5 635abaf2e -> bcc203806


CLOUDSTACK-7688, CLOUDSTACK-7747: restricted various operations for VM with VM snapshots which
breaks VM snapshots.
 Now they are informed that they cannot perform the operation.
 To perform operation they have to remove VM snapshots of VM.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f43ffb9a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f43ffb9a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f43ffb9a

Branch: refs/heads/4.5
Commit: f43ffb9a0f71f380f896e1e5c581725e9c08faab
Parents: 635abaf
Author: Anshul Gangwar <anshul.gangwar@citrix.com>
Authored: Thu Oct 9 10:37:21 2014 +0530
Committer: Rajesh Battala <rajesh.battala@citrix.com>
Committed: Tue Nov 18 14:12:02 2014 +0530

----------------------------------------------------------------------
 .../com/cloud/storage/VolumeApiServiceImpl.java | 22 +++++-
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 75 ++++++++++++--------
 .../vm/snapshot/VMSnapshotManagerImpl.java      | 12 ++++
 3 files changed, 78 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43ffb9a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index 3184dca..1ed5e27 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -707,6 +707,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
         /* Does the caller have authority to act on this volume? */
         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
 
+        if(volume.getInstanceId() != null) {
+            // Check that Vm to which this volume is attached does not have VM Snapshots
+            if (_vmSnapshotDao.findByVm(volume.getInstanceId()).size() > 0) {
+                throw new InvalidParameterValueException("Volume cannot be resized which
is attached to VM with VM Snapshots");
+            }
+        }
+
         DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
         DiskOfferingVO newDiskOffering = null;
 
@@ -977,7 +984,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
 
             if (storagePool.isManaged() && storagePool.getHypervisor() == HypervisorType.Any
&& hosts != null && hosts.length > 0) {
-                HostVO host = this._hostDao.findById(hosts[0]);
+                HostVO host = _hostDao.findById(hosts[0]);
 
                 if (currentSize != newSize && host.getHypervisorType() == HypervisorType.XenServer
&& !userVm.getState().equals(State.Stopped)) {
                     throw new InvalidParameterValueException(errorMsg);
@@ -1504,7 +1511,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
         // Permissions check
         _accountMgr.checkAccess(caller, null, true, volume);
 
-
         // Check that the volume is currently attached to a VM
         if (vmId == null) {
             throw new InvalidParameterValueException("The specified volume is not attached
to a VM.");
@@ -1695,6 +1701,11 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             vm = _vmInstanceDao.findById(instanceId);
         }
 
+        // Check that Vm to which this volume is attached does not have VM Snapshots
+        if (vm != null && _vmSnapshotDao.findByVm(vm.getId()).size() > 0) {
+            throw new InvalidParameterValueException("Volume cannot be migrated, please remove
all VM snapshots for VM to which this volume is attached");
+        }
+
         if (vm != null && vm.getState() == State.Running) {
             // Check if the VM is GPU enabled.
             if(_serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.pciDevice.toString())
!= null) {
@@ -1928,6 +1939,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             throw new InvalidParameterValueException("Can't find zone by id " + volume.getDataCenterId());
         }
 
+        if (volume.getInstanceId() != null) {
+            // Check that Vm to which this volume is attached does not have VM Snapshots
+            if (_vmSnapshotDao.findByVm(volume.getInstanceId()).size() > 0) {
+                throw new InvalidParameterValueException("Volume snapshot is not allowed,
please detach it from VM with VM Snapshots");
+            }
+        }
+
         if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId()))
{
             throw new PermissionDeniedException("Cannot perform this operation, Zone is currently
disabled: " + zone.getName());
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43ffb9a/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 77ace7a..1cf0ae6 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -86,6 +86,8 @@ import org.apache.cloudstack.storage.command.DeleteCommand;
 import org.apache.cloudstack.storage.command.DettachCommand;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -273,7 +275,6 @@ import com.cloud.vm.dao.UserVmCloneSettingDao;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
-import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.snapshot.VMSnapshotManager;
 import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
@@ -817,6 +818,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
                     + "; make sure the virtual machine is stopped");
         }
 
+        // If target VM has associated VM snapshots then don't allow upgrading of VM
+        List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
+        if (vmSnapshots.size() > 0) {
+            throw new InvalidParameterValueException("Unable to change service offering for
VM, please remove VM snapshots before changing service offering of VM");
+        }
+
         _accountMgr.checkAccess(caller, null, true, vmInstance);
 
         // Check resource limits for CPU and Memory.
@@ -844,19 +851,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         // Check that the specified service offering ID is valid
         _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
 
-        // remove diskAndMemory VM snapshots
-        List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
-        for (VMSnapshotVO vmSnapshotVO : vmSnapshots) {
-            if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) {
-                if (!_vmSnapshotMgr.deleteAllVMSnapshots(vmId, VMSnapshot.Type.DiskAndMemory))
{
-                    String errMsg = "Failed to remove VM snapshot during upgrading, snapshot
id " + vmSnapshotVO.getId();
-                    s_logger.debug(errMsg);
-                    throw new CloudRuntimeException(errMsg);
-                }
-
-            }
-        }
-
         _itMgr.upgradeVmDb(vmId, svcOffId);
         if (newServiceOffering.isDynamic()) {
             //save the custom values to the database.
@@ -957,19 +951,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         // Check that the specified service offering ID is valid
         _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
 
-        // remove diskAndMemory VM snapshots
-        List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
-        for (VMSnapshotVO vmSnapshotVO : vmSnapshots) {
-            if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) {
-                if (!_vmSnapshotMgr.deleteAllVMSnapshots(vmId, VMSnapshot.Type.DiskAndMemory))
{
-                    String errMsg = "Failed to remove VM snapshot during upgrading, snapshot
id " + vmSnapshotVO.getId();
-                    s_logger.debug(errMsg);
-                    throw new CloudRuntimeException(errMsg);
-                }
-
-            }
-        }
-
         _itMgr.upgradeVmDb(vmId, svcOffId);
         if (newServiceOffering.isDynamic()) {
             //save the custom values to the database.
@@ -1007,6 +988,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         if (vmInstance == null) {
             throw new InvalidParameterValueException("unable to find a virtual machine with
id " + vmId);
         }
+
+        // Check that Vm does not have VM Snapshots
+        if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
+            throw new InvalidParameterValueException("NIC cannot be added to VM with VM Snapshots");
+        }
+
         NetworkVO network = _networkDao.findById(networkId);
         if (network == null) {
             throw new InvalidParameterValueException("unable to find a network with id "
+ networkId);
@@ -1091,6 +1078,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         if (vmInstance == null) {
             throw new InvalidParameterValueException("Unable to find a virtual machine with
id " + vmId);
         }
+
+        // Check that Vm does not have VM Snapshots
+        if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
+            throw new InvalidParameterValueException("NIC cannot be removed from VM with
VM Snapshots");
+        }
+
         NicVO nic = _nicDao.findById(nicId);
         if (nic == null) {
             throw new InvalidParameterValueException("Unable to find a nic with id " + nicId);
@@ -1157,6 +1150,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         if (vmInstance == null) {
             throw new InvalidParameterValueException("unable to find a virtual machine with
id " + vmId);
         }
+
+        // Check that Vm does not have VM Snapshots
+        if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
+            throw new InvalidParameterValueException("NIC cannot be updated for VM with VM
Snapshots");
+        }
+
         NicVO nic = _nicDao.findById(nicId);
         if (nic == null) {
             throw new InvalidParameterValueException("unable to find a nic with id " + nicId);
@@ -1329,6 +1328,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         // Verify input parameters
         VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
 
+        if (vmInstance != null) {
+            // If target VM has associated VM snapshots then don't allow upgrading of VM
+            List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
+            if (vmSnapshots.size() > 0) {
+                throw new InvalidParameterValueException("Unable to scale VM, please remove
VM snapshots before scaling VM");
+            }
+        }
+
         if (vmInstance.getState().equals(State.Stopped)) {
             upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters);
             return true;
@@ -3830,6 +3837,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             throw new InvalidParameterValueException("Data disks attached to the vm, can
not migrate. Need to dettach data disks at first");
         }
 
+        // Check that Vm does not have VM Snapshots
+        if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
+            throw new InvalidParameterValueException("VM's disk cannot be migrated, please
remove all the VM Snapshots for this VM");
+        }
+
         HypervisorType destHypervisorType = destPool.getHypervisor();
         if (destHypervisorType == null) {
             destHypervisorType = _clusterDao.findById(
@@ -4248,6 +4260,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
                     + destinationHost.getResourceState());
         }
 
+        // Check that Vm does not have VM Snapshots
+        if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
+            throw new InvalidParameterValueException("VM with VM Snapshots cannot be migrated
with storage, please remove all VM snapshots");
+        }
+
         List<VolumeVO> vmVolumes = _volsDao.findUsableVolumesForInstance(vm.getId());
         Map<Long, Long> volToPoolObjectMap = new HashMap<Long, Long>();
         if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId()))
{
@@ -4714,8 +4731,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
 
             // If target VM has associated VM snapshots then don't allow restore of VM
             List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId);
-            if (vmSnapshots.size() > 0 && vm.getHypervisorType() == HypervisorType.VMware)
{
-                throw new InvalidParameterValueException("Unable to restore VM, please specify
a VM that does not have VM snapshots");
+            if (vmSnapshots.size() > 0) {
+                throw new InvalidParameterValueException("Unable to restore VM, please remove
VM snapshots before restoring VM");
             }
 
             VMTemplateVO template = null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43ffb9a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
index 7c20080..6590a74 100644
--- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
+++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
@@ -258,6 +258,11 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana
             throw new InvalidParameterValueException("Creating VM snapshot failed due to
VM:" + vmId + " is a system VM or does not exist");
         }
 
+        if (_snapshotDao.listByInstanceId(vmId, Snapshot.State.BackedUp).size() > 0) {
+            throw new InvalidParameterValueException(
+                    "VM snapshot for this VM is not allowed. This VM has volumes attached
which has snapshots, please remove all snapshots before taking VM snapshot");
+        }
+
         // VM snapshot with memory is not supported for VGPU Vms
         if (snapshotMemory && _serviceOfferingDetailsDao.findDetail(userVmVo.getServiceOfferingId(),
GPU.Keys.vgpuType.toString()) != null) {
             throw new InvalidParameterValueException("VM snapshot with MEMORY is not supported
for vGPU enabled VMs.");
@@ -568,6 +573,13 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana
                     "VM Snapshot reverting failed due to vm is not in the state of Running
or Stopped.");
         }
 
+        if (userVm.getState() == VirtualMachine.State.Running && vmSnapshotVo.getType()
== VMSnapshot.Type.Disk || userVm.getState() == VirtualMachine.State.Stopped
+                && vmSnapshotVo.getType() == VMSnapshot.Type.DiskAndMemory) {
+            throw new InvalidParameterValueException(
+                    "VM Snapshot revert not allowed. This will result in VM state change.
You can revert running VM to disk and memory type snapshot and stopped VM to disk type"
+                            + " snapshot");
+        }
+
         // if snapshot is not created, error out
         if (vmSnapshotVo.getState() != VMSnapshot.State.Ready) {
             throw new InvalidParameterValueException(


Mime
View raw message