100
100
for ip_cidr, ip_version in previous.items():
101
101
if ip_cidr not in preserve_ips:
102
102
device.addr.delete(ip_version, ip_cidr)
103
self.delete_conntrack_state(root_helper=self.root_helper,
107
def delete_conntrack_state(self, root_helper, namespace, ip):
108
"""Delete conntrack state associated with an IP address.
110
This terminates any active connections through an IP. Call this soon
111
after removing the IP address from an interface so that new connections
112
cannot be created before the IP address is gone.
114
root_helper: root_helper to gain root access to call conntrack
115
namespace: the name of the namespace where the IP has been configured
116
ip: the IP address for which state should be removed. This can be
117
passed as a string with or without /NN. A netaddr.IPAddress or
118
netaddr.Network representing the IP address can also be passed.
120
ip_str = str(netaddr.IPNetwork(ip).ip)
121
ip_wrapper = ip_lib.IPWrapper(root_helper, namespace=namespace)
123
# Delete conntrack state for ingress traffic
124
# If 0 flow entries have been deleted
125
# conntrack -D will return 1
127
ip_wrapper.netns.execute(["conntrack", "-D", "-d", ip_str],
128
check_exit_code=True,
132
LOG.exception(_("Failed deleting ingress connection state of"
133
" floatingip %s"), ip_str)
135
# Delete conntrack state for egress traffic
137
ip_wrapper.netns.execute(["conntrack", "-D", "-q", ip_str],
138
check_exit_code=True,
141
LOG.exception(_("Failed deleting egress connection state of"
142
" floatingip %s"), ip_str)
104
144
def check_bridge_exists(self, bridge):
105
145
if not ip_lib.device_exists(bridge):