]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Refactor _update_subnet_allocation_pools
authorPavel Bondar <pbondar@infoblox.com>
Thu, 11 Jun 2015 14:23:41 +0000 (17:23 +0300)
committerJohn Belamaric <jbelamaric@infoblox.com>
Fri, 12 Jun 2015 02:37:11 +0000 (22:37 -0400)
Moved _update_subnet_allocation_pools to ipam_backend_mixin.py.
Call _rebuild_availability_ranges with self to make it overridable
on upper level (from non-pluggable backend).

Partially-Implements: blueprint neutron-ipam

Change-Id: If7b1e720f88a2f0177b6772a015ae216f19ee22d

neutron/db/db_base_plugin_v2.py
neutron/db/ipam_backend_mixin.py

index 9147fd88996bff2bab1de0a4b1f1192624a8a8ad..8dcd27554a4fa3bcf620f8b5a1acea2fb0a859a9 100644 (file)
@@ -781,21 +781,6 @@ class NeutronDbPluginV2(ipam_non_pluggable_backend.IpamNonPluggableBackend,
                     LOG.debug("Port %s was deleted while updating it with an "
                               "IPv6 auto-address. Ignoring.", port['id'])
 
-    def _update_subnet_allocation_pools(self, context, id, s):
-        context.session.query(models_v2.IPAllocationPool).filter_by(
-            subnet_id=id).delete()
-        new_pools = [models_v2.IPAllocationPool(
-            first_ip=p['start'], last_ip=p['end'],
-            subnet_id=id) for p in s['allocation_pools']]
-        context.session.add_all(new_pools)
-        NeutronDbPluginV2._rebuild_availability_ranges(context, [s])
-        #Gather new pools for result:
-        result_pools = [{'start': pool['start'],
-                         'end': pool['end']}
-                        for pool in s['allocation_pools']]
-        del s['allocation_pools']
-        return result_pools
-
     def update_subnet(self, context, id, subnet):
         """Update the subnet with new info.
 
index e38b49549be512c4015ccda381773c10163e4830..74853bd619edd765b0590b16b316bde914e63b45 100644 (file)
@@ -37,6 +37,12 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
     # Tracks changes in ip allocation for port using namedtuple
     Changes = collections.namedtuple('Changes', 'add original remove')
 
+    @staticmethod
+    def _rebuild_availability_ranges(context, subnets):
+        """Should be redefined for non-ipam backend only
+        """
+        pass
+
     def _update_db_port(self, context, db_port, new_port, network_id, new_mac):
         # Remove all attributes in new_port which are not in the port DB model
         # and then update the port
@@ -99,6 +105,24 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
         del s["dns_nameservers"]
         return new_dns
 
+    def _update_subnet_allocation_pools(self, context, id, s):
+        context.session.query(models_v2.IPAllocationPool).filter_by(
+            subnet_id=id).delete()
+        new_pools = [models_v2.IPAllocationPool(first_ip=p['start'],
+                                                last_ip=p['end'],
+                                                subnet_id=id)
+                     for p in s['allocation_pools']]
+        context.session.add_all(new_pools)
+        # Call static method with self to redefine in child
+        # (non-pluggable backend)
+        self._rebuild_availability_ranges(context, [s])
+        # Gather new pools for result:
+        result_pools = [{'start': pool['start'],
+                         'end': pool['end']}
+                        for pool in s['allocation_pools']]
+        del s['allocation_pools']
+        return result_pools
+
     def _validate_allocation_pools(self, ip_pools, subnet_cidr):
         """Validate IP allocation pools.