From 6a1f8388d3f0ebd791aa1c466f5310efec5e83cc Mon Sep 17 00:00:00 2001 From: Pavel Bondar Date: Tue, 23 Jun 2015 14:01:29 +0300 Subject: [PATCH] Decompose _save_subnet Moved allocation pool generation and validation into separate method. Partially-Implements: blueprint neutron-ipam Change-Id: Ibe241c7b6389e444145b0600f8fcee28e478bc62 --- neutron/db/ipam_backend_mixin.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index af0833014..cd35300c0 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -308,6 +308,16 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): pool_2=r_range, subnet_cidr=subnet_cidr) + def _prepare_allocation_pools(self, context, allocation_pools, subnet): + if not attributes.is_attr_set(allocation_pools): + return self._allocate_pools_for_subnet(context, subnet) + + self._validate_allocation_pools(allocation_pools, subnet['cidr']) + if subnet['gateway_ip']: + self._validate_gw_out_of_pools(subnet['gateway_ip'], + allocation_pools) + return allocation_pools + def _validate_gw_out_of_pools(self, gateway_ip, pools): for allocation_pool in pools: pool_range = netaddr.IPRange( @@ -364,17 +374,9 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): dns_nameservers, host_routes, allocation_pools): - - if not attributes.is_attr_set(allocation_pools): - allocation_pools = self._allocate_pools_for_subnet(context, - subnet_args) - else: - self._validate_allocation_pools(allocation_pools, - subnet_args['cidr']) - if subnet_args['gateway_ip']: - self._validate_gw_out_of_pools(subnet_args['gateway_ip'], - allocation_pools) - + allocation_pools = self._prepare_allocation_pools(context, + allocation_pools, + subnet_args) self._validate_subnet_cidr(context, network, subnet_args['cidr']) self._validate_network_subnetpools(network, subnet_args['subnetpool_id'], -- 2.45.2