diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 0e6243967aa..f3a448b5da9 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.network; -import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -387,17 +386,6 @@ public interface NetworkManager extends NetworkService { InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - /** - * @param vmProfile - * @param network - * @return TODO - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ - NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) - throws ConcurrentOperationException, ResourceUnavailableException; - - /** * @param vm * @param network @@ -446,13 +434,11 @@ public interface NetworkManager extends NetworkService { /** * @param vmProfile - * @param network - * @param broadcastUri - * @return + * @param nic TODO * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) + void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException; diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c3109190a4c..76b3465aa57 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2264,37 +2264,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ConcurrentOperationException, ResourceUnavailableException { List nics = _nicDao.listByVmId(vmProfile.getId()); for (NicVO nic : nics) { - NetworkVO network = _networksDao.findById(nic.getNetworkId()); - releaseNic(vmProfile, nic, network); + releaseNic(vmProfile, nic); } } - @Override - public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { - NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vmProfile.getId()); - releaseNic(vmProfile, nic, network); - - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, - isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); - return profile; - } - - - @Override - public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) - throws ConcurrentOperationException, ResourceUnavailableException { - NicVO nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vmProfile.getId(), broadcastUri.toString()); - releaseNic(vmProfile, nic, network); - - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, - isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); - return profile; + NicVO nicVO = _nicDao.findById(nic.getId()); + releaseNic(vmProfile, nicVO); } - protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic, NetworkVO network) + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nic) throws ConcurrentOperationException, ResourceUnavailableException { + NetworkVO network = _networksDao.findById(nic.getNetworkId()); if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) { Nic.State originalState = nic.getState(); if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index da2790d85c5..2e75e720132 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2493,7 +2493,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene @Override public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException { VMInstanceVO vmVO = _vmDao.findById(vm.getId()); - NetworkVO networkVO = _networkDao.findById(network.getId()); ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); @@ -2503,20 +2502,20 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene DataCenter dc = _configMgr.getZone(network.getDataCenterId()); Host host = _hostDao.findById(vm.getHostId()); DeployDestination dest = new DeployDestination(dc, null, null, host); - - //1) Release the nic - NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO, broadcastUri); - - //2) Convert vmProfile to vmTO VirtualMachineGuru vmGuru = getVmGuru(vmVO); HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); + Nic nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId()); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + _networkMgr.getNetworkRate(network.getId(), vm.getId()), + _networkMgr.isSecurityGroupSupportedInNetwork(network), + _networkMgr.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + //1) Unplug the nic + NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType()); s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network); boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest); - //4) Unplug the nic if (result) { s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network ); } else { @@ -2524,7 +2523,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene return false; } - //6) Remove the nic + //2) Release the nic + _networkMgr.releaseNic(vmProfile, nic); + s_logger.debug("Successfully released nic " + nic + "for vm " + vm); + + //3) Remove the nic _networkMgr.removeNic(vmProfile, network); return result; } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index e245a9af3ec..f8a657cf73c 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.network; -import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -804,15 +803,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO) - */ - @Override - public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkManager#removeNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network) */ @@ -962,8 +952,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS * @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String) */ @Override - public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException { + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub } @@ -1066,15 +1055,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS return false; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO, java.net.URI) - */ - @Override - public NicProfile releaseNic(VirtualMachineProfile vmProfile, NetworkVO network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkManager#getPhysicalNtwksSupportingTrafficType(long, com.cloud.network.Networks.TrafficType) */ @@ -1139,4 +1119,14 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS // TODO Auto-generated method stub return null; } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String) + */ + @Override + public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException, + InsufficientAddressCapacityException { + // TODO Auto-generated method stub + + } }