# Path: neutron/objects/network.py
# class NetworkRBAC(rbac.RBACBaseObject):
# class NetworkDhcpAgentBinding(base.NeutronDbObject):
# class NetworkSegment(base.NeutronDbObject):
# class NetworkPortSecurity(base_ps._PortSecurity):
# class ExternalNetwork(base.NeutronDbObject):
# class Network(rbac_db.NeutronRbacObject):
# class SegmentHostMapping(base.NeutronDbObject):
# class NetworkDNSDomain(base.NeutronDbObject):
#     VERSION = '1.3'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = "1.0"
#     VERSION = '1.0'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = '1.0'
#     def obj_make_compatible(self, primitive, target_version):
#     def get_down_bindings(cls, context, cutoff):
#     def create(self):
#     def update(self):
#     def _attach_hosts(self, hosts):
#     def obj_load_attr(self, attrname):
#     def _load_hosts(self, db_obj=None):
#     def from_db_object(self, db_obj):
#     def get_objects(cls, context, _pager=None, **kwargs):
#     def create(self):
#     def update(self):
#     def _attach_qos_policy(self, qos_policy_id):
#     def _set_dns_domain(self, dns_domain):
#     def modify_fields_from_db(cls, db_obj):
#     def modify_fields_to_db(cls, fields):
#     def from_db_object(self, *objs):
#     def get_bound_project_ids(cls, context, policy_id):
#     def obj_make_compatible(self, primitive, target_version):
#     def get_net_dns_from_port(cls, context, port_id):


import collections
import copy
import itertools
import netaddr
from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef
from neutron_lib.api.definitions import portbindings
from neutron_lib.api.definitions import segment
from neutron_lib.api import validators
from neutron_lib import constants as const
from neutron_lib.db import api as db_api
from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as exc
from neutron_lib.exceptions import address_scope as addr_scope_exc
from neutron_lib.utils import net as net_utils
from oslo_config import cfg
from oslo_log import log as logging
from sqlalchemy.orm import exc as orm_exc
from neutron._i18n import _
from neutron.common import ipv6_utils
from neutron.db import db_base_plugin_common
from neutron.db import models_v2
from neutron.ipam import exceptions as ipam_exceptions
from neutron.ipam import utils as ipam_utils
from neutron.objects import address_scope as addr_scope_obj
from neutron.objects import network as network_obj
from neutron.objects import subnet as subnet_obj
from neutron.services.segments import exceptions as segment_exc
            context.session.delete(query.first())
        except orm_exc.UnmappedInstanceError:
            LOG.debug("Port %s was not found and therefore no delete "
                      "operation was performed", port_id)

    def _save_subnet(self, context,
                     network,
                     subnet_args,
                     dns_nameservers,
                     host_routes,
                     subnet_request):
        network_scope = addr_scope_obj.AddressScope.get_network_address_scope(
            context, network.id, subnet_args['ip_version'])
        # 'subnetpool' is not necessarily an object
        subnetpool = subnet_args.get('subnetpool_id')
        if subnetpool and subnetpool != const.IPV6_PD_POOL_ID:
            subnetpool = self._get_subnetpool(context, subnetpool)

        self._validate_subnet_cidr(context, network, subnet_args['cidr'])
        self._validate_network_subnetpools(network,
                                           subnet_args['ip_version'],
                                           subnetpool,
                                           network_scope)

        service_types = subnet_args.pop('service_types', [])

        segment_id = subnet_args.get('segment_id')
        if segment_id:
            # TODO(slaweq): integrate check if segment exists in
            # self._validate_segment() method

# Path: neutron/objects/network.py
# class NetworkRBAC(rbac.RBACBaseObject):
# class NetworkDhcpAgentBinding(base.NeutronDbObject):
# class NetworkSegment(base.NeutronDbObject):
# class NetworkPortSecurity(base_ps._PortSecurity):
# class ExternalNetwork(base.NeutronDbObject):
# class Network(rbac_db.NeutronRbacObject):
# class SegmentHostMapping(base.NeutronDbObject):
# class NetworkDNSDomain(base.NeutronDbObject):
#     VERSION = '1.3'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = "1.0"
#     VERSION = '1.0'
#     VERSION = '1.1'
#     VERSION = '1.0'
#     VERSION = '1.0'
#     def obj_make_compatible(self, primitive, target_version):
#     def get_down_bindings(cls, context, cutoff):
#     def create(self):
#     def update(self):
#     def _attach_hosts(self, hosts):
#     def obj_load_attr(self, attrname):
#     def _load_hosts(self, db_obj=None):
#     def from_db_object(self, db_obj):
#     def get_objects(cls, context, _pager=None, **kwargs):
#     def create(self):
#     def update(self):
#     def _attach_qos_policy(self, qos_policy_id):
#     def _set_dns_domain(self, dns_domain):
#     def modify_fields_from_db(cls, db_obj):
#     def modify_fields_to_db(cls, fields):
#     def from_db_object(self, *objs):
#     def get_bound_project_ids(cls, context, policy_id):
#     def obj_make_compatible(self, primitive, target_version):
#     def get_net_dns_from_port(cls, context, port_id):


# Path: neutron/db/ipam_backend_mixin.py
import collections
import copy
import itertools
import netaddr
from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef
from neutron_lib.api.definitions import portbindings
from neutron_lib.api.definitions import segment
from neutron_lib.api import validators
from neutron_lib import constants as const
from neutron_lib.db import api as db_api
from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as exc
from neutron_lib.exceptions import address_scope as addr_scope_exc
from neutron_lib.utils import net as net_utils
from oslo_config import cfg
from oslo_log import log as logging
from sqlalchemy.orm import exc as orm_exc
from neutron._i18n import _
from neutron.common import ipv6_utils
from neutron.db import db_base_plugin_common
from neutron.db import models_v2
from neutron.ipam import exceptions as ipam_exceptions
from neutron.ipam import utils as ipam_utils
from neutron.objects import address_scope as addr_scope_obj
from neutron.objects import network as network_obj
from neutron.objects import subnet as subnet_obj
from neutron.services.segments import exceptions as segment_exc

            context.session.delete(query.first())
        except orm_exc.UnmappedInstanceError:
            LOG.debug("Port %s was not found and therefore no delete "
                      "operation was performed", port_id)

    def _save_subnet(self, context,
                     network,
                     subnet_args,
                     dns_nameservers,
                     host_routes,
                     subnet_request):
        network_scope = addr_scope_obj.AddressScope.get_network_address_scope(
            context, network.id, subnet_args['ip_version'])
        # 'subnetpool' is not necessarily an object
        subnetpool = subnet_args.get('subnetpool_id')
        if subnetpool and subnetpool != const.IPV6_PD_POOL_ID:
            subnetpool = self._get_subnetpool(context, subnetpool)

        self._validate_subnet_cidr(context, network, subnet_args['cidr'])
        self._validate_network_subnetpools(network,
                                           subnet_args['ip_version'],
                                           subnetpool,
                                           network_scope)

        service_types = subnet_args.pop('service_types', [])

        segment_id = subnet_args.get('segment_id')
        if segment_id:
            # TODO(slaweq): integrate check if segment exists in
            # self._validate_segment() method

            if not network_obj.NetworkSegment.get_object(context,