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
This commit is contained in:
parent
ac687a3171
commit
7e0222409d
|
@ -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.
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue