From c0ef7a8f4546cd3c081a61c742dd9ed70ec2c147 Mon Sep 17 00:00:00 2001 From: Pavel Bondar Date: Thu, 18 Jun 2015 14:52:24 +0300 Subject: [PATCH] Decompose create_port and save_subnet 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 | 20 ++------------------ neutron/db/ipam_non_pluggable_backend.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index f4a921574..ed7126ac0 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -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) diff --git a/neutron/db/ipam_non_pluggable_backend.py b/neutron/db/ipam_non_pluggable_backend.py index 7884b7ba4..4941776f0 100644 --- a/neutron/db/ipam_non_pluggable_backend.py +++ b/neutron/db/ipam_non_pluggable_backend.py @@ -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 -- 2.45.2