components/openstack/neutron/files/agent/evs_l3_agent.py
branchs11u3-sru
changeset 6444 bf62eba2612a
parent 6035 c9748fcc32de
--- a/components/openstack/neutron/files/agent/evs_l3_agent.py	Thu Jul 14 13:57:27 2016 -0700
+++ b/components/openstack/neutron/files/agent/evs_l3_agent.py	Thu Jul 21 09:32:01 2016 -0700
@@ -319,7 +319,6 @@
             fixed_cidr = str(fip['fixed_ip_address']) + '/32'
             nat_rule = 'bimap %s %s -> %s' % (interface_name, fixed_cidr,
                                               fip_cidr)
-
             if fip_cidr not in existing_cidrs:
                 try:
                     ipintf.create_address(fip_cidr)
@@ -335,6 +334,33 @@
                     LOG.warn(_("Unable to configure IP address for "
                                "floating IP: %s: %s") % (fip['id'], err))
                     continue
+            else:
+                # check if existing fip has been reassigned
+                fip_reassigned = False
+                for rule in existing_nat_rules:
+                    if not rule.startswith('bimap'):
+                        continue
+                    if fip_ip not in rule:
+                        continue
+                    if fixed_cidr not in rule:
+                        fip_reassigned = True
+                        break
+
+                if fip_reassigned:
+                    LOG.debug("Floating ip '%s' reassigned to '%s'",
+                              fip_ip, fip['fixed_ip_address'])
+                    # remove the old nat rule and
+                    # add a new one for the new fixed_ip
+                    try:
+                        self.ipfilters_manager.remove_nat_rules([rule])
+                        existing_nat_rules.remove(rule)
+                        self.ipfilters_manager.add_nat_rules([nat_rule])
+                    except Exception as err:
+                        fip_statuses[fip['id']] = (
+                            l3_constants.FLOATINGIP_STATUS_ERROR)
+                        LOG.warn(_("Unable to configure IP address for "
+                                   "floating IP: %s: %s") % (fip['id'], err))
+                        continue
             fip_statuses[fip['id']] = (
                 l3_constants.FLOATINGIP_STATUS_ACTIVE)
             LOG.debug("Floating ip %(id)s added, status %(status)s",