diff --git a/api-ref/source/v2/index.rst b/api-ref/source/v2/index.rst index aab51d695..918a21498 100644 --- a/api-ref/source/v2/index.rst +++ b/api-ref/source/v2/index.rst @@ -31,6 +31,7 @@ Layer 3 Networking .. include:: fip-port-forwarding.inc .. include:: routers.inc .. include:: subnetpools.inc +.. include:: subnetpool_prefix_ops.inc .. include:: subnets.inc ######## Security diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index 7abc672f2..6e4c96722 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -4673,6 +4673,22 @@ prefixes: in: body required: true type: array +prefixes-response: + description: | + A list of the subnet prefixes currently assigned to the subnet + pool. Adjacent prefixes are merged and treated as a single prefix. + in: body + required: true + type: array +prefixes_remove: + description: | + A list of subnet prefixes to remove from the subnet pool. + The API splits larger prefixes when a subset prefix is removed, + and merges any resulting adjacent prefixes to treat them as a single + prefix. + in: body + required: true + type: array project_id: description: | The ID of the project. diff --git a/api-ref/source/v2/samples/subnets/subnetpool-add-prefixes-request.json b/api-ref/source/v2/samples/subnets/subnetpool-add-prefixes-request.json new file mode 100644 index 000000000..a379f9872 --- /dev/null +++ b/api-ref/source/v2/samples/subnets/subnetpool-add-prefixes-request.json @@ -0,0 +1,3 @@ +{ + "prefixes": ["192.168.0.0/24", "192.168.1.0/24", "172.16.0.0/21"] +} diff --git a/api-ref/source/v2/samples/subnets/subnetpool-add-prefixes-response.json b/api-ref/source/v2/samples/subnets/subnetpool-add-prefixes-response.json new file mode 100644 index 000000000..ac3fa700d --- /dev/null +++ b/api-ref/source/v2/samples/subnets/subnetpool-add-prefixes-response.json @@ -0,0 +1,3 @@ +{ + "prefixes": ["192.168.0.0/23", "172.16.0.0/21"] +} diff --git a/api-ref/source/v2/samples/subnets/subnetpool-remove-prefixes-request.json b/api-ref/source/v2/samples/subnets/subnetpool-remove-prefixes-request.json new file mode 100644 index 000000000..bf7cbfe5b --- /dev/null +++ b/api-ref/source/v2/samples/subnets/subnetpool-remove-prefixes-request.json @@ -0,0 +1,3 @@ +{ + "prefixes": ["192.168.0.0/24"] +} diff --git a/api-ref/source/v2/samples/subnets/subnetpool-remove-prefixes-response.json b/api-ref/source/v2/samples/subnets/subnetpool-remove-prefixes-response.json new file mode 100644 index 000000000..18099fefb --- /dev/null +++ b/api-ref/source/v2/samples/subnets/subnetpool-remove-prefixes-response.json @@ -0,0 +1,3 @@ +{ + "prefixes": ["192.168.1.0/24", "172.16.0.0/21"] +} diff --git a/api-ref/source/v2/subnetpool_prefix_ops.inc b/api-ref/source/v2/subnetpool_prefix_ops.inc new file mode 100644 index 000000000..17c8145a3 --- /dev/null +++ b/api-ref/source/v2/subnetpool_prefix_ops.inc @@ -0,0 +1,83 @@ +.. -*- rst -*- + +===================================================== +Subnet pool prefix operations (subnetpool-prefix-ops) +===================================================== + +Add and remove prefixes from a subnet pool prefix list. + +Add prefixes +============ + +.. rest_method:: PUT /v2.0/subnetpools/{subnetpool_id}/add_prefixes + +Adds prefixes to a subnet pool. + +Normal response codes: 200 + +Error response codes: 400, 401, 403, 404, 409, 412 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - subnetpool_id: subnetpool_id + - prefixes: prefixes + +Request Example +--------------- + +.. literalinclude:: samples/subnets/subnetpool-add-prefixes-request.json + :language: javascript + +Response Parameters +------------------- + +.. rest_parameters:: parameters.yaml + + - prefixes: prefixes-response + +Response Example +---------------- + +.. literalinclude:: samples/subnets/subnetpool-add-prefixes-response.json + :language: javascript + +Remove prefixes +=============== + +.. rest_method:: PUT /v2.0/subnetpools/{subnetpool_id}/remove_prefixes + +Remove prefixes from a subnet pool. + +Normal response codes: 200 + +Error response codes: 400, 401, 403, 404, 409, 412 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - subnetpool_id: subnetpool_id + - prefixes: prefixes_remove + +Request Example +--------------- + +.. literalinclude:: samples/subnets/subnetpool-remove-prefixes-request.json + :language: javascript + +Response Parameters +------------------- + +.. rest_parameters:: parameters.yaml + + - prefixes: prefixes-response + +Response Example +---------------- + +.. literalinclude:: samples/subnets/subnetpool-remove-prefixes-response.json + :language: javascript diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index d5f1089e5..b762abd70 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -100,6 +100,7 @@ from neutron_lib.api.definitions import subnet_onboard from neutron_lib.api.definitions import subnet_segmentid_enforce from neutron_lib.api.definitions import subnet_segmentid_writable from neutron_lib.api.definitions import subnetpool +from neutron_lib.api.definitions import subnetpool_prefix_ops from neutron_lib.api.definitions import trunk from neutron_lib.api.definitions import trunk_details from neutron_lib.api.definitions import uplink_status_propagation @@ -200,6 +201,7 @@ _ALL_API_DEFINITIONS = { subnet_segmentid_enforce, subnet_segmentid_writable, subnetpool, + subnetpool_prefix_ops, trunk, trunk_details, uplink_status_propagation, diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index c35d6983b..e5d1f962d 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -137,6 +137,7 @@ KNOWN_EXTENSIONS = ( 'standard-attr-timestamp', 'subnet_allocation', 'subnet_onboard', + 'subnetpool-prefix-ops', 'subnet-segmentid-enforce', 'subnet-segmentid-writable', 'tag', diff --git a/neutron_lib/api/definitions/subnetpool_prefix_ops.py b/neutron_lib/api/definitions/subnetpool_prefix_ops.py new file mode 100644 index 000000000..133f15a88 --- /dev/null +++ b/neutron_lib/api/definitions/subnetpool_prefix_ops.py @@ -0,0 +1,53 @@ +# (c) Copyright 2019 SUSE LLC +# +# All Rights Reserved. +# +# 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 subnetpool as subnetpool_def +from neutron_lib import constants + +ALIAS = "subnetpool-prefix-ops" +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = "Subnet Pool Prefix Operations" +DESCRIPTION = "Provides support for adjusting the prefix list of subnet pools" +UPDATED_TIMESTAMP = "2019-02-08T10:00:00-00:00" + + +RESOURCE_ATTRIBUTE_MAP = { +} + +# The subresource attribute map for the extension. This extension has only +# top level resources, not child resources, so this is set to an empty dict. +SUB_RESOURCE_ATTRIBUTE_MAP = { +} + +# The action map. +ACTION_MAP = { + subnetpool_def.RESOURCE_NAME: { + 'add_prefixes': 'PUT', + 'remove_prefixes': 'PUT' + } +} + +# The action status. +ACTION_STATUS = { +} + +# The list of required extensions. +REQUIRED_EXTENSIONS = [constants.SUBNET_ALLOCATION_EXT_ALIAS] + +# The list of optional extensions. +OPTIONAL_EXTENSIONS = [ +] diff --git a/neutron_lib/tests/unit/api/definitions/base.py b/neutron_lib/tests/unit/api/definitions/base.py index a10bd6f85..f257a6359 100644 --- a/neutron_lib/tests/unit/api/definitions/base.py +++ b/neutron_lib/tests/unit/api/definitions/base.py @@ -110,9 +110,9 @@ class DefinitionBaseTestCase(test_base.BaseTestCase): def test_resource_map(self): if (not self.resource_map and not self.subresource_map and - not self.is_shim_extension): - self.fail('Missing resource and subresource map, ' - 'what is this extension doing?') + not self.is_shim_extension and not self.action_map): + self.fail('Missing resource map, subresource map, ' + 'and action map, what is this extension doing?') elif self.is_shim_extension: self.skipTest('Shim extension with no API changes.') diff --git a/neutron_lib/tests/unit/api/definitions/test_subnetpool_prefix_ops.py b/neutron_lib/tests/unit/api/definitions/test_subnetpool_prefix_ops.py new file mode 100644 index 000000000..bf1cd8252 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_subnetpool_prefix_ops.py @@ -0,0 +1,19 @@ +# 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 subnetpool_prefix_ops +from neutron_lib.tests.unit.api.definitions import base + + +class SubnetPoolPrefixOpsDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = subnetpool_prefix_ops + extension_attributes = () diff --git a/releasenotes/notes/introduce_subnetpool_prefix_ops_extension-e37874c936d2554c.yaml b/releasenotes/notes/introduce_subnetpool_prefix_ops_extension-e37874c936d2554c.yaml new file mode 100644 index 000000000..33e2bfd24 --- /dev/null +++ b/releasenotes/notes/introduce_subnetpool_prefix_ops_extension-e37874c936d2554c.yaml @@ -0,0 +1,5 @@ +--- +features: + - Adds ``subnetpool-prefix-ops`` API definition to neutron-lib. This + extension introduces API's that provide explicit support for removing + prefixes from a subnet pool and adding subnets to a subnet pool.