From fc2f383dd698321f01dc8ec56dff44ba4ec66157 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 2 Feb 2024 06:26:13 +0000 Subject: [PATCH] Add extension "subnet-external-network" This extension adds a new field to the "subnet" resource: "router:external". This boolean field, that is False by default, represents if the subnet belongs to an external network. Related-Bug: #2051831 Change-Id: I75a9c30f1e8031d40a548df345b02fbe0bc47706 --- api-ref/source/v2/parameters.yaml | 6 +++ .../subnets/subnet-create-response.json | 3 +- .../samples/subnets/subnet-show-response.json | 3 +- .../subnets/subnet-update-response.json | 3 +- .../subnets/subnets-list-response.json | 6 ++- api-ref/source/v2/subnets.inc | 5 ++ neutron_lib/api/definitions/__init__.py | 2 + .../definitions/subnet_external_network.py | 49 +++++++++++++++++++ .../test_subnet_external_network.py | 22 +++++++++ ...net-external-network-ddb816aa51883752.yaml | 8 +++ 10 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 neutron_lib/api/definitions/subnet_external_network.py create mode 100644 neutron_lib/tests/unit/api/definitions/test_subnet_external_network.py create mode 100644 releasenotes/notes/subnet-external-network-ddb816aa51883752.yaml diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index a37fda39e..d3811bf0e 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -1661,6 +1661,12 @@ subnet-network_id-query: in: query required: false type: string +subnet-router:external: + description: | + The membership of a subnet to an external network. + in: query + required: false + type: boolean subnet-segment_id-query: description: | Filter the subnet list result by the ID of a network segment the subnet diff --git a/api-ref/source/v2/samples/subnets/subnet-create-response.json b/api-ref/source/v2/samples/subnets/subnet-create-response.json index c1db52b27..05d8c4253 100644 --- a/api-ref/source/v2/samples/subnets/subnet-create-response.json +++ b/api-ref/source/v2/samples/subnets/subnet-create-response.json @@ -27,6 +27,7 @@ "service_types": [], "subnetpool_id": null, "tags": ["tag1,tag2"], - "updated_at": "2016-10-10T14:35:47Z" + "updated_at": "2016-10-10T14:35:47Z", + "router:external": false } } diff --git a/api-ref/source/v2/samples/subnets/subnet-show-response.json b/api-ref/source/v2/samples/subnets/subnet-show-response.json index e8a0aa8a3..8b9b6f859 100644 --- a/api-ref/source/v2/samples/subnets/subnet-show-response.json +++ b/api-ref/source/v2/samples/subnets/subnet-show-response.json @@ -27,6 +27,7 @@ "revision_number": 2, "service_types": [], "subnetpool_id": null, - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "router:external": false } } diff --git a/api-ref/source/v2/samples/subnets/subnet-update-response.json b/api-ref/source/v2/samples/subnets/subnet-update-response.json index 7389b470b..f0e0350da 100644 --- a/api-ref/source/v2/samples/subnets/subnet-update-response.json +++ b/api-ref/source/v2/samples/subnets/subnet-update-response.json @@ -24,6 +24,7 @@ "updated_at": "2016-03-08T20:19:41", "id": "08eae331-0402-425a-923c-34f7cfe39c1b", "description": "", - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "router:external": false } } diff --git a/api-ref/source/v2/samples/subnets/subnets-list-response.json b/api-ref/source/v2/samples/subnets/subnets-list-response.json index 8eabe6cd6..e2e3274bd 100644 --- a/api-ref/source/v2/samples/subnets/subnets-list-response.json +++ b/api-ref/source/v2/samples/subnets/subnets-list-response.json @@ -28,7 +28,8 @@ "service_types": [], "subnetpool_id": null, "tags": ["tag1,tag2"], - "updated_at": "2016-10-10T14:35:34Z" + "updated_at": "2016-10-10T14:35:34Z", + "router:external": false }, { "name": "my_subnet", @@ -58,7 +59,8 @@ "service_types": [], "subnetpool_id": null, "tags": ["tag1,tag2"], - "updated_at": "2016-10-10T14:35:47Z" + "updated_at": "2016-10-10T14:35:47Z", + "router:external": true } ] } diff --git a/api-ref/source/v2/subnets.inc b/api-ref/source/v2/subnets.inc index cc510c1e5..bbec1679d 100644 --- a/api-ref/source/v2/subnets.inc +++ b/api-ref/source/v2/subnets.inc @@ -165,6 +165,7 @@ Response Parameters - updated_at: updated_at_resource - tags: tags - dns_publish_fixed_ip: subnet-dns_publish_fixed_ip + - router:external: subnet-router:external Response Example ---------------- @@ -289,6 +290,7 @@ Response Parameters - updated_at: updated_at_resource - tags: tags - dns_publish_fixed_ip: subnet-dns_publish_fixed_ip + - router:external: subnet-router:external Response Example ---------------- @@ -372,6 +374,7 @@ Response Parameters - updated_at: updated_at_resource - tags: tags - dns_publish_fixed_ip: subnet-dns_publish_fixed_ip + - router:external: subnet-router:external Response Example ---------------- @@ -428,6 +431,7 @@ Response Parameters - subnetpool_id: subnet-subnetpool_id - tags: tags - dns_publish_fixed_ip: subnet-dns_publish_fixed_ip + - router:external: subnet-router:external Response Example ---------------- @@ -502,6 +506,7 @@ Response Parameters - updated_at: updated_at_resource - tags: tags - dns_publish_fixed_ip: subnet-dns_publish_fixed_ip + - router:external: subnet-router:external Response Example ---------------- diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 46fc62f8f..f404c10bd 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -145,6 +145,7 @@ from neutron_lib.api.definitions import standard_attr_segment from neutron_lib.api.definitions import stateful_security_group from neutron_lib.api.definitions import subnet from neutron_lib.api.definitions import subnet_dns_publish_fixed_ip +from neutron_lib.api.definitions import subnet_external_network 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 @@ -300,6 +301,7 @@ _ALL_API_DEFINITIONS = { stateful_security_group, subnet, subnet_dns_publish_fixed_ip, + subnet_external_network, subnet_onboard, subnet_segmentid_enforce, subnet_segmentid_writable, diff --git a/neutron_lib/api/definitions/subnet_external_network.py b/neutron_lib/api/definitions/subnet_external_network.py new file mode 100644 index 000000000..a5bab8bad --- /dev/null +++ b/neutron_lib/api/definitions/subnet_external_network.py @@ -0,0 +1,49 @@ +# Copyright (c) 2024 Red Hat Inc. +# 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 import converters +from neutron_lib.api.definitions import external_net as extnet_def +from neutron_lib.api.definitions import subnet as subnet_def + + +ALIAS = 'subnet-external-network' +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Subnet belongs to an external network' +API_PREFIX = '' +DESCRIPTION = 'Informs if the subnet belongs to an external network' +UPDATED_TIMESTAMP = '2024-02-05T18:00:00-00:00' +RESOURCE_NAME = extnet_def.EXTERNAL # 'router:external' + +RESOURCE_ATTRIBUTE_MAP = { + subnet_def.COLLECTION_NAME: { + RESOURCE_NAME: { + 'allow_post': False, + 'allow_put': False, + 'default': False, + 'is_visible': True, + 'is_filter': False, + 'convert_to': converters.convert_to_boolean, + 'enforce_policy': True, + 'required_by_policy': True + } + } +} + +SUB_RESOURCE_ATTRIBUTE_MAP = {} +ACTION_MAP = {} +ACTION_STATUS = {} +REQUIRED_EXTENSIONS = [] +OPTIONAL_EXTENSIONS = [] diff --git a/neutron_lib/tests/unit/api/definitions/test_subnet_external_network.py b/neutron_lib/tests/unit/api/definitions/test_subnet_external_network.py new file mode 100644 index 000000000..b1549d1c5 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_subnet_external_network.py @@ -0,0 +1,22 @@ +# Copyright (c) 2024 Red Hat Inc. +# 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 subnet_external_network +from neutron_lib.tests.unit.api.definitions import base + + +class SubnetExternalNetworkDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = subnet_external_network + extension_attributes = (subnet_external_network.RESOURCE_NAME,) diff --git a/releasenotes/notes/subnet-external-network-ddb816aa51883752.yaml b/releasenotes/notes/subnet-external-network-ddb816aa51883752.yaml new file mode 100644 index 000000000..19b4c04b3 --- /dev/null +++ b/releasenotes/notes/subnet-external-network-ddb816aa51883752.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Added new extension ``subnet-router:external``. This extension adds a + new field to the ``subnet`` resource definition, called + ``router:external``, that is a boolean that represents if the subnet + belongs to an external network. This is the same parameter name used in + the external network flag.