From 84e1532fd566fd0461b1ec5812d258cf83e9227f Mon Sep 17 00:00:00 2001 From: Kailun Qin Date: Fri, 21 Dec 2018 00:24:47 +0800 Subject: [PATCH] Add network-segment-range extension API definition This patch adds the network-segment-range extension's API definition into neutron-lib. Co-authored-by: Allain Legacy Needed-by: https://review.openstack.org/624708 Partially-implements: blueprint network-segment-range-management Change-Id: Ieb799c42e995f0612c3ba3eb8a7960be77178e07 --- neutron_lib/api/definitions/__init__.py | 2 + neutron_lib/api/definitions/base.py | 1 + .../api/definitions/network_segment_range.py | 146 ++++++++++++++++++ .../exceptions/network_segment_range.py | 35 +++++ .../definitions/test_network_segment_range.py | 26 ++++ ...rk-segment-range-ext-2b93b7fa42310c25.yaml | 4 + 6 files changed, 214 insertions(+) create mode 100644 neutron_lib/api/definitions/network_segment_range.py create mode 100644 neutron_lib/exceptions/network_segment_range.py create mode 100644 neutron_lib/tests/unit/api/definitions/test_network_segment_range.py create mode 100644 releasenotes/notes/network-segment-range-ext-2b93b7fa42310c25.yaml diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index bf2c2525b..98fcc6e06 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -61,6 +61,7 @@ from neutron_lib.api.definitions import network_availability_zone from neutron_lib.api.definitions import network_ip_availability from neutron_lib.api.definitions import network_mtu from neutron_lib.api.definitions import network_mtu_writable +from neutron_lib.api.definitions import network_segment_range from neutron_lib.api.definitions import pagination from neutron_lib.api.definitions import port from neutron_lib.api.definitions import port_mac_address_regenerate @@ -156,6 +157,7 @@ _ALL_API_DEFINITIONS = { network_ip_availability, network_mtu, network_mtu_writable, + network_segment_range, pagination, port, port_mac_address_regenerate, diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index ad9c170af..3fd73a159 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -108,6 +108,7 @@ KNOWN_EXTENSIONS = ( 'multi-provider', 'net-mtu', 'network-ip-availability', + 'network-segment-range', 'network_availability_zone', 'pagination', 'port-resource-request', diff --git a/neutron_lib/api/definitions/network_segment_range.py b/neutron_lib/api/definitions/network_segment_range.py new file mode 100644 index 000000000..cb52cc48e --- /dev/null +++ b/neutron_lib/api/definitions/network_segment_range.py @@ -0,0 +1,146 @@ +# Copyright (c) 2018 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api import converters +from neutron_lib.api.definitions import provider_net as providernet +from neutron_lib import constants +from neutron_lib.db import constants as db_const +from oslo_log import log as logging + +LOG = logging.getLogger(__name__) + +# The name of the extension. +NAME = 'Neutron Network Segment Range' +# The alias of the extension. +ALIAS = 'network-segment-range' +# The description of the extension. +DESCRIPTION = "Provides support for the network segment range management" + +# A timestamp of when the extension was introduced. +UPDATED_TIMESTAMP = "2018-11-29T00:00:00-00:00" + +# The name of the resource. +RESOURCE_NAME = 'network_segment_range' +# The plural for the resource. +COLLECTION_NAME = 'network_segment_ranges' + +NETWORK_SEGMENT_RANGE_TYPE_LIST = [constants.TYPE_VLAN, + constants.TYPE_VXLAN, + constants.TYPE_GRE, + constants.TYPE_GENEVE] + +# Min ID for VLAN, VXLAN, GRE and GENEVE all equal to 1; Max ID for them are +# 4094, 2 ** 24 - 1, 2 ** 32 - 1 and 2 ** 24 - 1 respectively. +# Take the largest range: [MIN_GRE_ID, MAX_GRE_ID] as the limit for validation. +NETWORK_SEGMENT_RANGE_LIMIT = [constants.MIN_GRE_ID, constants.MAX_GRE_ID] + +RESOURCE_ATTRIBUTE_MAP = { + COLLECTION_NAME: { + 'id': {'allow_post': False, + 'allow_put': False, + 'validate': {'type:uuid': None}, + 'is_filter': True, + 'is_sort_key': True, + 'primary_key': True, + 'is_visible': True}, + 'name': {'allow_post': True, + 'allow_put': True, + 'validate': {'type:string': db_const.NAME_FIELD_SIZE}, + 'default': '', + 'is_filter': True, + 'is_sort_key': True, + 'is_visible': True}, + 'default': {'allow_post': False, + 'allow_put': False, + 'convert_to': converters.convert_to_boolean, + 'default': False, + 'is_visible': True}, + constants.SHARED: {'allow_post': True, + 'allow_put': False, + 'convert_to': converters.convert_to_boolean, + 'default': True, + 'is_visible': True}, + 'project_id': {'allow_post': True, + 'allow_put': False, + 'validate': { + 'type:string': db_const.PROJECT_ID_FIELD_SIZE}, + 'required_by_policy': True, + 'is_filter': True, + 'is_sort_key': True, + 'is_visible': True}, + 'network_type': {'allow_post': True, + 'allow_put': False, + 'validate': { + 'type:values': NETWORK_SEGMENT_RANGE_TYPE_LIST}, + 'default': constants.ATTR_NOT_SPECIFIED, + 'is_filter': True, + 'is_visible': True}, + 'physical_network': {'allow_post': True, + 'allow_put': False, + 'validate': { + 'type:string': + providernet.PHYSICAL_NETWORK_MAX_LEN}, + 'default': constants.ATTR_NOT_SPECIFIED, + 'is_filter': True, + 'is_visible': True}, + 'minimum': {'allow_post': True, + 'allow_put': True, + 'convert_to': converters.convert_to_int, + 'validate': {'type:range': NETWORK_SEGMENT_RANGE_LIMIT}, + 'is_visible': True}, + 'maximum': {'allow_post': True, + 'allow_put': True, + 'convert_to': converters.convert_to_int, + 'validate': {'type:range': NETWORK_SEGMENT_RANGE_LIMIT}, + 'is_visible': True}, + 'used': {'allow_post': False, + 'allow_put': False, + 'is_visible': True}, + 'available': {'allow_post': False, + 'allow_put': False, + 'convert_to': converters.convert_none_to_empty_list, + 'is_visible': True} + } +} + +# Whether or not this extension is simply signaling behavior to the user +# or it actively modifies the attribute map. +IS_SHIM_EXTENSION = False + +# Whether the extension is marking the adoption of standardattr model for +# legacy resources, or introducing new standardattr attributes. False or +# None if the standardattr model is adopted since the introduction of +# resource extension. +# If this is True, the alias for the extension should be prefixed with +# 'standard-attr-'. +IS_STANDARD_ATTR_EXTENSION = False + +# The subresource attribute map for the extension. It adds child resources +# to main extension's resource. The subresource map must have a parent and +# a parameters entry. If an extension does not need such a map, None can +# be specified (mandatory). +SUB_RESOURCE_ATTRIBUTE_MAP = {} + +# The action map: it associates verbs with methods to be performed on +# the API resource. +ACTION_MAP = {} + +# The list of required extensions. +REQUIRED_EXTENSIONS = [providernet.ALIAS] + +# The list of optional extensions. +OPTIONAL_EXTENSIONS = [] + +# The action status. +ACTION_STATUS = {} diff --git a/neutron_lib/exceptions/network_segment_range.py b/neutron_lib/exceptions/network_segment_range.py new file mode 100644 index 000000000..d722739d9 --- /dev/null +++ b/neutron_lib/exceptions/network_segment_range.py @@ -0,0 +1,35 @@ +# Copyright (c) 2018 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib._i18n import _ +from neutron_lib import exceptions + + +class NetworkSegmentRangeNetTypeNotSupported(exceptions.NeutronException): + message = _("Network type %(type)s does not support " + "network segment ranges.") + + +class NetworkSegmentRangeNotFound(exceptions.NotFound): + message = _("Network Segment Range %(range_id)s could not be found.") + + +class NetworkSegmentRangeReferencedByProject(exceptions.NeutronException): + message = _("Network Segment Range %(range_id)s is referenced by " + "one or more tenant networks.") + + +class NetworkSegmentRangeDefaultReadOnly(exceptions.NeutronException): + message = _("Network Segment Range %(range_id)s is a " + "default segment range which could not be updated or deleted.") diff --git a/neutron_lib/tests/unit/api/definitions/test_network_segment_range.py b/neutron_lib/tests/unit/api/definitions/test_network_segment_range.py new file mode 100644 index 000000000..f9bf40f83 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_network_segment_range.py @@ -0,0 +1,26 @@ +# Copyright (c) 2018 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import network_segment_range +from neutron_lib import constants +from neutron_lib.tests.unit.api.definitions import base + + +class NetworkSegmentRangeDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = network_segment_range + extension_resources = (network_segment_range.COLLECTION_NAME,) + extension_attributes = ('name', 'default', constants.SHARED, + 'project_id', 'network_type', + 'physical_network', 'minimum', 'maximum', + 'used', 'available',) diff --git a/releasenotes/notes/network-segment-range-ext-2b93b7fa42310c25.yaml b/releasenotes/notes/network-segment-range-ext-2b93b7fa42310c25.yaml new file mode 100644 index 000000000..1bcd3f368 --- /dev/null +++ b/releasenotes/notes/network-segment-range-ext-2b93b7fa42310c25.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add API definition for the new ``network-segment-range`` extension.