]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Decompose create_port and save_subnet
authorPavel Bondar <pbondar@infoblox.com>
Thu, 18 Jun 2015 11:52:24 +0000 (14:52 +0300)
committerPavel Bondar <pbondar@infoblox.com>
Mon, 22 Jun 2015 08:06:03 +0000 (08:06 +0000)
This commit is a preparation step for enabling pluggable ipam.
Some actions in create_port and save_subnet are specific for
non pluggable ipam implementation.

- create_port
Moved allocation ips for port and storing results into separate method
_allocate_ips_for_port_and_store.
Moved to ipam_non_pluggable_backend, since pluggable implementation will
be different due to rollback on failure logic included.

- save_subnet
Moved saving allocation pools into new method _save_allocation_pools.
Moved to ipam_non_pluggable_backend, since pluggable ipam implementation
does not need to save IPAvailabilityRange (availability ranges are
maintained by ipam driver for pluggable case)

Partially-Implements: blueprint neutron-ipam

Change-Id: I4a3e5d7f3aa54630279d9589225a509c96ed2186

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

index f4a92157461303b968535a04257559a6ae5a3b95..ed7126ac0056888e3ecc20039ff202fa1a6bbbb0 100644 (file)
@@ -552,16 +552,7 @@ class NeutronDbPluginV2(ipam_non_pluggable_backend.IpamNonPluggableBackend,
                     nexthop=rt['nexthop'])
                 context.session.add(route)
 
-        for pool in allocation_pools:
-            ip_pool = models_v2.IPAllocationPool(subnet=subnet,
-                                                 first_ip=pool['start'],
-                                                 last_ip=pool['end'])
-            context.session.add(ip_pool)
-            ip_range = models_v2.IPAvailabilityRange(
-                ipallocationpool=ip_pool,
-                first_ip=pool['start'],
-                last_ip=pool['end'])
-            context.session.add(ip_range)
+        self._save_allocation_pools(context, subnet, allocation_pools)
 
         return subnet
 
@@ -1031,14 +1022,7 @@ class NeutronDbPluginV2(ipam_non_pluggable_backend.IpamNonPluggableBackend,
                 db_port = self._create_port_with_mac(
                     context, network_id, port_data, p['mac_address'])
 
-            # Update the IP's for the port
-            ips = self._allocate_ips_for_port(context, port)
-            if ips:
-                for ip in ips:
-                    ip_address = ip['ip_address']
-                    subnet_id = ip['subnet_id']
-                    NeutronDbPluginV2._store_ip_allocation(
-                        context, ip_address, network_id, subnet_id, port_id)
+            self._allocate_ips_for_port_and_store(context, port, port_id)
 
         return self._make_port_dict(db_port, process_extensions=False)
 
index 7884b7ba45fdbff9984b38a55cce5f3d00006d55..4941776f0c0abeb4fbd16faf51b8f3c2ba8e26a7 100644 (file)
@@ -184,6 +184,28 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
             return True
         return False
 
+    def _save_allocation_pools(self, context, subnet, allocation_pools):
+        for pool in allocation_pools:
+            ip_pool = models_v2.IPAllocationPool(subnet=subnet,
+                                                 first_ip=pool['start'],
+                                                 last_ip=pool['end'])
+            context.session.add(ip_pool)
+            ip_range = models_v2.IPAvailabilityRange(
+                ipallocationpool=ip_pool,
+                first_ip=pool['start'],
+                last_ip=pool['end'])
+            context.session.add(ip_range)
+
+    def _allocate_ips_for_port_and_store(self, context, port, port_id):
+        network_id = port['port']['network_id']
+        ips = self._allocate_ips_for_port(context, port)
+        if ips:
+            for ip in ips:
+                ip_address = ip['ip_address']
+                subnet_id = ip['subnet_id']
+                self._store_ip_allocation(context, ip_address, network_id,
+                                          subnet_id, port_id)
+
     def _update_port_with_ips(self, context, db_port, new_port, new_mac):
         changes = self.Changes(add=[], original=[], remove=[])
         # Check if the IPs need to be updated