server: allow destroy/recover volumes which are attached to removed vms (#5364)

* server: allow destroy volumes which attach to a expunged vm

* server: recover volume which is attached to a removed vm
This commit is contained in:
Wei Zhou 2021-08-28 14:10:31 +02:00 committed by GitHub
parent 4acedc8308
commit 41f6f0e568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -1364,7 +1364,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
if (!_snapshotMgr.canOperateOnVolume(volume)) {
throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it");
}
if (volume.getInstanceId() != null && volume.getState() != Volume.State.Expunged) {
if (volume.getInstanceId() != null && _vmInstanceDao.findById(volume.getInstanceId()) != null && volume.getState() != Volume.State.Expunged) {
throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM.");
}
if (volume.getState() == Volume.State.UploadOp) {
@ -1520,6 +1520,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
}
try {
_volsDao.detachVolume(volume.getId());
stateTransitTo(volume, Volume.Event.RecoverRequested);
} catch (NoTransitionException e) {
s_logger.debug("Failed to recover volume" + volume.getId(), e);