From: Pavel Bondar Date: Thu, 18 Jun 2015 11:17:58 +0000 (+0300) Subject: Move _add_auto_addrs_on_network_ports X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5aaae68e5148f01e78a5e6013dce797dd42c1917;p=openstack-build%2Fneutron-build.git Move _add_auto_addrs_on_network_ports Moved to ipam_non_pluggable_backend.py since implementation is specific for non pluggable ipam backend. Pluggable implementation will additionally include rollback on failure actions. This commit is a preparation step for using pluggable ipam. More changes in this methods are expected to be done by following patches. Partially-Implements: blueprint neutron-ipam Change-Id: I1876846526e370a7fcfa05b9a23fd9065973f111 --- diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index fe9be44a5..f4a921574 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -728,34 +728,6 @@ class NeutronDbPluginV2(ipam_non_pluggable_backend.IpamNonPluggableBackend, return created_subnet - def _add_auto_addrs_on_network_ports(self, context, subnet): - """For an auto-address subnet, add addrs for ports on the net.""" - with context.session.begin(subtransactions=True): - network_id = subnet['network_id'] - port_qry = context.session.query(models_v2.Port) - for port in port_qry.filter( - and_(models_v2.Port.network_id == network_id, - models_v2.Port.device_owner != - constants.DEVICE_OWNER_ROUTER_SNAT, - ~models_v2.Port.device_owner.in_( - constants.ROUTER_INTERFACE_OWNERS))): - ip_address = self._calculate_ipv6_eui64_addr( - context, subnet, port['mac_address']) - allocated = models_v2.IPAllocation(network_id=network_id, - port_id=port['id'], - ip_address=ip_address, - subnet_id=subnet['id']) - try: - # Do the insertion of each IP allocation entry within - # the context of a nested transaction, so that the entry - # is rolled back independently of other entries whenever - # the corresponding port has been deleted. - with context.session.begin_nested(): - context.session.add(allocated) - except db_exc.DBReferenceError: - LOG.debug("Port %s was deleted while updating it with an " - "IPv6 auto-address. Ignoring.", port['id']) - def update_subnet(self, context, id, subnet): """Update the subnet with new info. diff --git a/neutron/db/ipam_non_pluggable_backend.py b/neutron/db/ipam_non_pluggable_backend.py index c1fb4bc96..7884b7ba4 100644 --- a/neutron/db/ipam_non_pluggable_backend.py +++ b/neutron/db/ipam_non_pluggable_backend.py @@ -15,7 +15,9 @@ import netaddr from oslo_config import cfg +from oslo_db import exception as db_exc from oslo_log import log as logging +from sqlalchemy import and_ from sqlalchemy import orm from sqlalchemy.orm import exc @@ -403,6 +405,34 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin): return ips + def _add_auto_addrs_on_network_ports(self, context, subnet): + """For an auto-address subnet, add addrs for ports on the net.""" + with context.session.begin(subtransactions=True): + network_id = subnet['network_id'] + port_qry = context.session.query(models_v2.Port) + for port in port_qry.filter( + and_(models_v2.Port.network_id == network_id, + models_v2.Port.device_owner != + constants.DEVICE_OWNER_ROUTER_SNAT, + ~models_v2.Port.device_owner.in_( + constants.ROUTER_INTERFACE_OWNERS))): + ip_address = self._calculate_ipv6_eui64_addr( + context, subnet, port['mac_address']) + allocated = models_v2.IPAllocation(network_id=network_id, + port_id=port['id'], + ip_address=ip_address, + subnet_id=subnet['id']) + try: + # Do the insertion of each IP allocation entry within + # the context of a nested transaction, so that the entry + # is rolled back independently of other entries whenever + # the corresponding port has been deleted. + with context.session.begin_nested(): + context.session.add(allocated) + except db_exc.DBReferenceError: + LOG.debug("Port %s was deleted while updating it with an " + "IPv6 auto-address. Ignoring.", port['id']) + def _calculate_ipv6_eui64_addr(self, context, subnet, mac_addr): prefix = subnet['cidr'] network_id = subnet['network_id']