Fix detach volume on stopped Vms

This commit is contained in:
nvazquez 2020-10-25 00:33:46 -03:00
parent d119a5d19f
commit a831ad1252

View File

@ -2054,31 +2054,35 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
if (!sendCommand || (answer != null && answer.getResult())) {
// Mark the volume as detached
_volsDao.detachVolume(volume.getId());
String datastoreName = answer.getContextParam("datastoreName");
if (datastoreName != null) {
StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
if (storagePoolVO != null) {
if (answer != null) {
String datastoreName = answer.getContextParam("datastoreName");
if (datastoreName != null) {
StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
if (storagePoolVO != null) {
VolumeVO volumeVO = _volsDao.findById(volumeId);
volumeVO.setPoolId(storagePoolVO.getId());
_volsDao.update(volumeVO.getId(), volumeVO);
} else {
s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreName, volumeId));
}
}
String volumePath = answer.getContextParam("volumePath");
if (volumePath != null) {
VolumeVO volumeVO = _volsDao.findById(volumeId);
volumeVO.setPoolId(storagePoolVO.getId());
volumeVO.setPath(volumePath);
_volsDao.update(volumeVO.getId(), volumeVO);
}
String chainInfo = answer.getContextParam("chainInfo");
if (chainInfo != null) {
VolumeVO volumeVO = _volsDao.findById(volumeId);
volumeVO.setChainInfo(chainInfo);
_volsDao.update(volumeVO.getId(), volumeVO);
} else {
s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreName, volumeId));
}
}
String volumePath = answer.getContextParam("volumePath");
if (volumePath != null) {
VolumeVO volumeVO = _volsDao.findById(volumeId);
volumeVO.setPath(volumePath);
_volsDao.update(volumeVO.getId(), volumeVO);
}
String chainInfo = answer.getContextParam("chainInfo");
if (chainInfo != null) {
VolumeVO volumeVO = _volsDao.findById(volumeId);
volumeVO.setChainInfo(chainInfo);
_volsDao.update(volumeVO.getId(), volumeVO);
}
// volume.getPoolId() should be null if the VM we are detaching the disk from has never been started before
if (volume.getPoolId() != null) {
DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);