]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move _add_auto_addrs_on_network_ports
authorPavel Bondar <pbondar@infoblox.com>
Thu, 18 Jun 2015 11:17:58 +0000 (14:17 +0300)
committerPavel Bondar <pbondar@infoblox.com>
Fri, 19 Jun 2015 10:38:42 +0000 (10:38 +0000)
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

neutron/db/db_base_plugin_v2.py
neutron/db/ipam_non_pluggable_backend.py

index fe9be44a5351a56ba1876a8f28b54de25abf47bf..f4a92157461303b968535a04257559a6ae5a3b95 100644 (file)
@@ -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.
 
index c1fb4bc9631c3a83cc88344793fa3a6f199e2d45..7884b7ba45fdbff9984b38a55cce5f3d00006d55 100644 (file)
@@ -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']