diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index ff0235f018a..1e8edafe4e2 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -169,6 +169,8 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.SecondaryStorageVmDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; +import com.cloud.vm.snapshot.VMSnapshotVO; +import com.cloud.vm.snapshot.dao.VMSnapshotDao; @Component public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @@ -289,6 +291,8 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @Inject protected ResourceTagDao _resourceTagDao; @Inject + protected VMSnapshotDao _vmSnapshotDao; + @Inject protected List _storagePoolAllocators; @Inject ConfigurationDao _configDao; @@ -1669,6 +1673,13 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } } + // if target VM has associated VM snapshots + List vmSnapshots = _vmSnapshotDao.findByVm(vmId); + if(vmSnapshots.size() > 0){ + throw new InvalidParameterValueException( + "Unable to attach volume, please specify a VM that does not have VM snapshots"); + } + // permission check _accountMgr.checkAccess(caller, null, true, volume, vm); @@ -1826,6 +1837,13 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { "Please specify a VM that is either running or stopped."); } + // Check if the VM has VM snapshots + List vmSnapshots = _vmSnapshotDao.findByVm(vmId); + if(vmSnapshots.size() > 0){ + throw new InvalidParameterValueException( + "Unable to detach volume, the specified volume is attached to a VM that has VM snapshots."); + } + AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor .getCurrentExecutor(); if (asyncExecutor != null) {