Merge "Optimize subnet retrieval during CIDR validation"

This commit is contained in:
Zuul 2020-05-05 06:08:26 +00:00 committed by Gerrit Code Review
commit 2a6ab2e9c0
2 changed files with 13 additions and 7 deletions

View File

@ -236,14 +236,14 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
if cidr.prefixlen == 0:
err_msg = _("0 is not allowed as CIDR prefix length")
raise exc.InvalidInput(error_message=err_msg)
if cfg.CONF.allow_overlapping_ips:
subnet_list = network.subnets
subnet_list = [{'id': s.id, 'cidr': s.cidr}
for s in network.subnets]
else:
subnet_list = self._get_subnets(context)
subnet_list = subnet_obj.Subnet.get_subnet_cidrs(context)
for subnet in subnet_list:
if ((netaddr.IPSet([subnet.cidr]) & new_subnet_ipset) and
str(subnet.cidr) != const.PROVISIONAL_IPV6_PD_PREFIX):
if ((netaddr.IPSet([subnet['cidr']]) & new_subnet_ipset) and
str(subnet['cidr']) != const.PROVISIONAL_IPV6_PD_PREFIX):
# don't give out details of the overlapping subnet
err_msg = ("Requested subnet with cidr: %(cidr)s for "
"network: %(network_id)s overlaps with another "
@ -254,8 +254,8 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
"overlaps with subnet %(subnet_id)s "
"(CIDR: %(cidr)s)",
{'new_cidr': new_subnet_cidr,
'subnet_id': subnet.id,
'cidr': subnet.cidr})
'subnet_id': subnet['id'],
'cidr': subnet['cidr']})
raise exc.InvalidInput(error_message=err_msg)
def _validate_network_subnetpools(self, network, subnet_ip_version,

View File

@ -476,6 +476,12 @@ class Subnet(base.NeutronDbObject):
raise ipam_exceptions.DeferIpam()
return False
@classmethod
def get_subnet_cidrs(cls, context):
return [
{'id': subnet[0], 'cidr': subnet[1]} for subnet in
context.session.query(cls.db_model.id, cls.db_model.cidr).all()]
def obj_make_compatible(self, primitive, target_version):
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 1): # version 1.1 adds "dns_publish_fixed_ip"