From: rossella Date: Wed, 20 Aug 2014 10:44:01 +0000 (+0200) Subject: Add _store_ip_allocation method X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0846f76da7b87e20c713403b793586e021a1b5d1;p=openstack-build%2Fneutron-build.git Add _store_ip_allocation method This refactor supports patch [1] The code to store the IPAllocation is moved to a specific method _store_ip_allocation [1] https://review.openstack.org/#/c/100963 Change-Id: I9492dcb9479d6e6dadb79b137a273052d948412b --- diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 910e3e7f9..36851ca05 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -182,6 +182,23 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, return (subnet['ipv6_address_mode'] == constants.IPV6_SLAAC or subnet['ipv6_address_mode'] == constants.DHCPV6_STATELESS) + @staticmethod + def _store_ip_allocation(context, ip_address, network_id, subnet_id, + port_id): + LOG.debug("Allocated IP %(ip_address)s " + "(%(network_id)s/%(subnet_id)s/%(port_id)s)", + {'ip_address': ip_address, + 'network_id': network_id, + 'subnet_id': subnet_id, + 'port_id': port_id}) + allocated = models_v2.IPAllocation( + network_id=network_id, + port_id=port_id, + ip_address=ip_address, + subnet_id=subnet_id + ) + context.session.add(allocated) + @staticmethod def _generate_ip(context, subnets): try: @@ -1289,19 +1306,8 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, for ip in ips: ip_address = ip['ip_address'] subnet_id = ip['subnet_id'] - LOG.debug(_("Allocated IP %(ip_address)s " - "(%(network_id)s/%(subnet_id)s/%(port_id)s)"), - {'ip_address': ip_address, - 'network_id': network_id, - 'subnet_id': subnet_id, - 'port_id': port_id}) - allocated = models_v2.IPAllocation( - network_id=network_id, - port_id=port_id, - ip_address=ip_address, - subnet_id=subnet_id, - ) - context.session.add(allocated) + NeutronDbPluginV2._store_ip_allocation( + context, ip_address, network_id, subnet_id, port_id) return self._make_port_dict(port, process_extensions=False) @@ -1339,10 +1345,9 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, # Update ips if necessary for ip in added_ips: - allocated = models_v2.IPAllocation( - network_id=port['network_id'], port_id=port.id, - ip_address=ip['ip_address'], subnet_id=ip['subnet_id']) - context.session.add(allocated) + NeutronDbPluginV2._store_ip_allocation( + context, ip['ip_address'], port['network_id'], + ip['subnet_id'], port.id) # Remove all attributes in p which are not in the port DB model # and then update the port port.update(self._filter_non_model_columns(p, models_v2.Port))