diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 1584b7e1208..dd1bc4c9a52 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -16,6 +16,7 @@ import functools import netaddr +from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import subnetpool as subnetpool_def from neutron_lib.api import validators @@ -53,7 +54,6 @@ from neutron.db import models_v2 from neutron.db import rbac_db_mixin as rbac_mixin from neutron.db import rbac_db_models as rbac_db from neutron.db import standardattrdescription_db as stattr_db -from neutron.extensions import ip_allocation as ipa from neutron.extensions import l3 from neutron import ipam from neutron.ipam import exceptions as ipam_exc @@ -1266,13 +1266,15 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, try: self.ipam.allocate_ips_for_port_and_store( context, port, port_id) - db_port['ip_allocation'] = ipa.IP_ALLOCATION_IMMEDIATE + db_port['ip_allocation'] = (ipalloc_apidef. + IP_ALLOCATION_IMMEDIATE) except ipam_exc.DeferIpam: - db_port['ip_allocation'] = ipa.IP_ALLOCATION_DEFERRED + db_port['ip_allocation'] = (ipalloc_apidef. + IP_ALLOCATION_DEFERRED) fixed_ips = p['fixed_ips'] if validators.is_attr_set(fixed_ips) and not fixed_ips: # [] was passed explicitly as fixed_ips. An unaddressed port. - db_port['ip_allocation'] = ipa.IP_ALLOCATION_NONE + db_port['ip_allocation'] = ipalloc_apidef.IP_ALLOCATION_NONE return db_port diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index e7009da7cb3..b172a4446c4 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -18,6 +18,7 @@ import copy import itertools import netaddr +from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef from neutron_lib.api.definitions import portbindings from neutron_lib.api import validators from neutron_lib import constants as const @@ -40,7 +41,6 @@ from neutron.db import db_base_plugin_common from neutron.db.models import segment as segment_model from neutron.db.models import subnet_service_type as sst_model from neutron.db import models_v2 -from neutron.extensions import ip_allocation as ipa from neutron.extensions import segment from neutron.ipam import exceptions as ipam_exceptions from neutron.ipam import utils as ipam_utils @@ -756,7 +756,8 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): fixed_ips_requested = validators.is_attr_set(new_port.get('fixed_ips')) old_ips = old_port.get('fixed_ips') deferred_ip_allocation = ( - old_port.get('ip_allocation') == ipa.IP_ALLOCATION_DEFERRED + old_port.get('ip_allocation') == + ipalloc_apidef.IP_ALLOCATION_DEFERRED and host and not old_host and not old_ips and not fixed_ips_requested) diff --git a/neutron/extensions/ip_allocation.py b/neutron/extensions/ip_allocation.py index 4aac7bdf5d8..7c91eb1425e 100644 --- a/neutron/extensions/ip_allocation.py +++ b/neutron/extensions/ip_allocation.py @@ -12,46 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib.api.definitions import port as port_def +from neutron_lib.api.definitions import ip_allocation as apidef from neutron_lib.api import extensions -IP_ALLOCATION = 'ip_allocation' -IP_ALLOCATION_IMMEDIATE = 'immediate' -IP_ALLOCATION_DEFERRED = 'deferred' -IP_ALLOCATION_NONE = 'none' - -# Attribute Map -RESOURCE_ATTRIBUTE_MAP = { - port_def.COLLECTION_NAME: { - IP_ALLOCATION: {'allow_post': False, - 'allow_put': False, - 'is_visible': True, }, - }, -} - - -class Ip_allocation(extensions.ExtensionDescriptor): +class Ip_allocation(extensions.APIExtensionDescriptor): """Extension indicates when ports use deferred or no IP allocation.""" - @classmethod - def get_name(cls): - return "IP Allocation" - - @classmethod - def get_alias(cls): - return "ip_allocation" - - @classmethod - def get_description(cls): - return "IP allocation extension." - - @classmethod - def get_updated(cls): - return "2016-06-10T23:00:00-00:00" - - def get_extended_resources(self, version): - if version == "2.0": - return RESOURCE_ATTRIBUTE_MAP - else: - return {} + api_definition = apidef diff --git a/neutron/services/segments/plugin.py b/neutron/services/segments/plugin.py index c14af4f1342..68aef08b188 100644 --- a/neutron/services/segments/plugin.py +++ b/neutron/services/segments/plugin.py @@ -16,6 +16,7 @@ from keystoneauth1 import loading as ks_loading import netaddr +from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef from neutron_lib.api.definitions import l2_adjacency as l2adj_apidef from neutron_lib.api.definitions import network as net_def from neutron_lib.api.definitions import port as port_def @@ -36,7 +37,6 @@ from neutron.db import _resource_extend as resource_extend from neutron.db import api as db_api from neutron.db.models import segment as segment_model from neutron.db import models_v2 -from neutron.extensions import ip_allocation from neutron.extensions import segment from neutron.notifiers import batch_notifier from neutron.services.segments import db @@ -86,10 +86,10 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase): if not directory.get_plugin('segments'): return - value = ip_allocation.IP_ALLOCATION_IMMEDIATE + value = ipalloc_apidef.IP_ALLOCATION_IMMEDIATE if port_db.get('ip_allocation'): value = port_db.get('ip_allocation') - port_res[ip_allocation.IP_ALLOCATION] = value + port_res[ipalloc_apidef.IP_ALLOCATION] = value @classmethod def get_instance(cls): diff --git a/neutron/tests/unit/extensions/test_segment.py b/neutron/tests/unit/extensions/test_segment.py index 970496a893c..9c48b63ae08 100644 --- a/neutron/tests/unit/extensions/test_segment.py +++ b/neutron/tests/unit/extensions/test_segment.py @@ -17,6 +17,7 @@ import copy from keystoneauth1 import exceptions as ks_exc import mock import netaddr +from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef from neutron_lib.api.definitions import l2_adjacency as l2adj_apidef from neutron_lib.api.definitions import portbindings from neutron_lib.callbacks import events @@ -39,7 +40,6 @@ from neutron.db import agentschedulers_db from neutron.db import db_base_plugin_v2 from neutron.db import portbindings_db from neutron.db import segments_db -from neutron.extensions import ip_allocation from neutron.extensions import segment as ext_segment from neutron.objects import network from neutron.services.segments import db @@ -1055,8 +1055,8 @@ class TestSegmentAwareIpam(SegmentAwareIpamTestCase): # Create an unbound port requesting no IP addresses response = self._create_port_and_show(network, fixed_ips=[]) self.assertEqual([], response['port']['fixed_ips']) - self.assertEqual(ip_allocation.IP_ALLOCATION_NONE, - response['port'][ip_allocation.IP_ALLOCATION]) + self.assertEqual(ipalloc_apidef.IP_ALLOCATION_NONE, + response['port'][ipalloc_apidef.IP_ALLOCATION]) def test_port_create_with_no_fixed_ips_no_ipam(self): """Ports without addresses on non-routed networks are not deferred""" @@ -1068,8 +1068,8 @@ class TestSegmentAwareIpam(SegmentAwareIpamTestCase): response = self._create_port_and_show(network, fixed_ips=[]) self.assertEqual([], response['port']['fixed_ips']) - self.assertEqual(ip_allocation.IP_ALLOCATION_NONE, - response['port'][ip_allocation.IP_ALLOCATION]) + self.assertEqual(ipalloc_apidef.IP_ALLOCATION_NONE, + response['port'][ipalloc_apidef.IP_ALLOCATION]) def test_port_without_ip_not_deferred(self): """Ports without addresses on non-routed networks are not deferred""" @@ -1087,8 +1087,8 @@ class TestSegmentAwareIpam(SegmentAwareIpamTestCase): response = self.deserialize(self.fmt, request.get_response(self.api)) self.assertEqual([], response['port']['fixed_ips']) - self.assertEqual(ip_allocation.IP_ALLOCATION_IMMEDIATE, - response['port'][ip_allocation.IP_ALLOCATION]) + self.assertEqual(ipalloc_apidef.IP_ALLOCATION_IMMEDIATE, + response['port'][ipalloc_apidef.IP_ALLOCATION]) def test_port_without_ip_not_deferred_no_binding(self): """Ports without addresses on non-routed networks are not deferred""" @@ -1098,8 +1098,8 @@ class TestSegmentAwareIpam(SegmentAwareIpamTestCase): # Create a unbound port with no IP address (since there is no subnet) response = self._create_port_and_show(network) self.assertEqual([], response['port']['fixed_ips']) - self.assertEqual(ip_allocation.IP_ALLOCATION_IMMEDIATE, - response['port'][ip_allocation.IP_ALLOCATION]) + self.assertEqual(ipalloc_apidef.IP_ALLOCATION_IMMEDIATE, + response['port'][ipalloc_apidef.IP_ALLOCATION]) def test_port_update_is_host_aware(self): """Binding information is provided, subnets on segments""" @@ -1140,8 +1140,8 @@ class TestSegmentAwareIpam(SegmentAwareIpamTestCase): request = self.new_show_request('ports', port_id) response = self.deserialize(self.fmt, request.get_response(self.api)) - self.assertEqual(ip_allocation.IP_ALLOCATION_DEFERRED, - response['port'][ip_allocation.IP_ALLOCATION]) + self.assertEqual(ipalloc_apidef.IP_ALLOCATION_DEFERRED, + response['port'][ipalloc_apidef.IP_ALLOCATION]) ips = response['port']['fixed_ips'] self.assertEqual(0, len(ips)) @@ -1149,8 +1149,8 @@ class TestSegmentAwareIpam(SegmentAwareIpamTestCase): request = self.new_show_request('ports', port_id) response = self.deserialize(self.fmt, request.get_response(self.api)) - self.assertEqual(ip_allocation.IP_ALLOCATION_IMMEDIATE, - response['port'][ip_allocation.IP_ALLOCATION]) + self.assertEqual(ipalloc_apidef.IP_ALLOCATION_IMMEDIATE, + response['port'][ipalloc_apidef.IP_ALLOCATION]) ips = response['port']['fixed_ips'] self.assertNotEqual(0, len(ips))