From 75ccb53fa301a89cb5fb83e59584298f3a6bb5de Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 3 Jan 2020 14:03:09 +0100 Subject: [PATCH] network: cleanup dhcp/dns entries while remove a nic from vm (#3721) --- .../orchestration/NetworkOrchestrator.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 9e49148f402..fc9d96fb522 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -2014,15 +2014,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final List nics = _nicDao.listByVmId(vm.getId()); for (final NicVO nic : nics) { - final NetworkVO network = _networksDao.findById(nic.getNetworkId()); - if (network != null && network.getTrafficType() == TrafficType.Guest) { - final String nicIp = Strings.isNullOrEmpty(nic.getIPv4Address()) ? nic.getIPv6Address() : nic.getIPv4Address(); - if (!Strings.isNullOrEmpty(nicIp)) { - NicProfile nicProfile = new NicProfile(nic.getIPv4Address(), nic.getIPv6Address(), nic.getMacAddress()); - nicProfile.setId(nic.getId()); - cleanupNicDhcpDnsEntry(network, vm, nicProfile); - } - } removeNic(vm, nic); } } @@ -2044,9 +2035,18 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } + final NetworkVO network = _networksDao.findById(nic.getNetworkId()); + if (network != null && network.getTrafficType() == TrafficType.Guest) { + final String nicIp = Strings.isNullOrEmpty(nic.getIPv4Address()) ? nic.getIPv6Address() : nic.getIPv4Address(); + if (!Strings.isNullOrEmpty(nicIp)) { + NicProfile nicProfile = new NicProfile(nic.getIPv4Address(), nic.getIPv6Address(), nic.getMacAddress()); + nicProfile.setId(nic.getId()); + cleanupNicDhcpDnsEntry(network, vm, nicProfile); + } + } + nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); - final NetworkVO network = _networksDao.findById(nic.getNetworkId()); final NicProfile profile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( vm.getHypervisorType(), network));