Merge pull request #1613 from nvazquez/vmnetworkmapissue

CLOUDSTACK-9436: vm_network_map table cleanup, release network resources on expunge commandJIRA TICKET: https://issues.apache.org/jira/browse/CLOUDSTACK-9436

This PR replaces #1594

Due to error on `test/integration/smoke/test_vpc_redundant.py` it was found out that `vm_network_map` table should be less aggresive on vm stop

* pr/1613:
  CLOUDSTACK-9436: Release network resources on expunge command

Signed-off-by: Will Stevens <williamstevens@gmail.com>
This commit is contained in:
Will Stevens 2016-07-25 16:37:18 -04:00
commit 0a0839ea2d
1 changed files with 20 additions and 0 deletions

View File

@ -2046,6 +2046,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
return false;
}
try {
releaseNetworkResourcesOnExpunge(vm.getId());
List<VolumeVO> rootVol = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
// expunge the vm
_itMgr.advanceExpunge(vm.getUuid());
@ -2086,6 +2089,23 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
}
/**
* Release network resources, it was done on vm stop previously.
* @param id vm id
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
private void releaseNetworkResourcesOnExpunge(long id) throws ConcurrentOperationException, ResourceUnavailableException {
final VMInstanceVO vmInstance = _vmDao.findById(id);
if (vmInstance != null){
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vmInstance);
_networkMgr.release(profile, false);
}
else {
s_logger.error("Couldn't find vm with id = " + id + ", unable to release network resources");
}
}
private boolean cleanupVmResources(long vmId) {
boolean success = true;
// Remove vm from security groups