From 54d08a8e293e3747903250e872ec74614ff63ccf Mon Sep 17 00:00:00 2001 From: Saksham Srivastava Date: Thu, 18 Dec 2014 17:45:10 +0530 Subject: [PATCH] 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 --- server/src/com/cloud/vm/UserVmManagerImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 466d0ea53c0..5a3b885d08d 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -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); }