From: Pavel Bondar Date: Thu, 11 Jun 2015 14:23:41 +0000 (+0300) Subject: Refactor _update_subnet_allocation_pools X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7e0222409dab6223579efea34ba0d3ccf93e11d3;p=openstack-build%2Fneutron-build.git Refactor _update_subnet_allocation_pools 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 --- diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 9147fd889..8dcd27554 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -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. diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index e38b49549..74853bd61 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -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.