Repository: cloudstack Updated Branches: refs/heads/master f4133a7f7 -> 4821bfffe
CLOUDSTACK-8091: Stale entry exists for a VM NIC even after an exception while adding a new nic to vm Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4821bfff Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4821bfff Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4821bfff Branch: refs/heads/master Commit: 4821bfffe2813ffb43761246e75cc7cf73291d27 Parents: f4133a7 Author: Saksham Srivastava <[email protected]> Authored: Thu Dec 18 17:45:10 2014 +0530 Committer: Saksham Srivastava <[email protected]> Committed: Thu Dec 18 17:45:34 2014 +0530 ---------------------------------------------------------------------- server/src/com/cloud/vm/UserVmManagerImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4821bfff/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 6de86a6..674a4c1 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1051,16 +1051,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); }
