CLOUDSTACK-8091: Stale entry exists for a VM NIC even after an exception while adding a new nic to vm

(cherry picked from commit 4821bfffe2813ffb43761246e75cc7cf73291d27)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Saksham Srivastava 2014-12-18 17:45:10 +05:30 committed by Rohit Yadav
parent 7d1ced7400
commit 54d08a8e29

View File

@ -1045,16 +1045,27 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
NicProfile guestNic = null;
boolean cleanUp = true;
try {
guestNic = _itMgr.addVmToNetwork(vmInstance, network, profile);
cleanUp = false;
} catch (ResourceUnavailableException e) {
throw new CloudRuntimeException("Unable to add NIC to " + vmInstance + ": " + e);
} catch (InsufficientCapacityException e) {
throw new CloudRuntimeException("Insufficient capacity when adding NIC to " + vmInstance + ": " + e);
} catch (ConcurrentOperationException e) {
throw new CloudRuntimeException("Concurrent operations on adding NIC to " + vmInstance + ": " + e);
} finally {
if(cleanUp) {
try {
_itMgr.removeVmFromNetwork(vmInstance, network, null);
} catch (ResourceUnavailableException e) {
throw new CloudRuntimeException("Error while cleaning up NIC " + e);
}
}
}
if (guestNic == null) {
throw new CloudRuntimeException("Unable to add NIC to " + vmInstance);
}