fix CLOUDSTACK-1698

This commit is contained in:
Mice Xia 2013-04-02 16:19:24 +08:00
parent 8d34b5809d
commit dedec164e8

View File

@ -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<StoragePoolAllocator> _storagePoolAllocators;
@Inject
ConfigurationDao _configDao;
@ -1669,6 +1673,13 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
}
}
// if target VM has associated VM snapshots
List<VMSnapshotVO> 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<VMSnapshotVO> 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) {