network: cleanup dhcp/dns entries while remove a nic from vm (#3721)

This commit is contained in:
Wei Zhou 2020-01-03 14:03:09 +01:00 committed by dahn
parent 8844f59247
commit 75ccb53fa3
1 changed files with 10 additions and 10 deletions

View File

@ -2014,15 +2014,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
final List<NicVO> 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));