diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index e7e866c02..c50148f89 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -5500,6 +5500,12 @@ state: in: body required: true type: string +stateful_enabled: + description: | + Indicates if the security group is stateful or stateless. + in: body + required: false + type: boolean status_description: description: | Human-readable description of the status. diff --git a/api-ref/source/v2/samples/security-groups/security-group-create-request.json b/api-ref/source/v2/samples/security-groups/security-group-create-request.json index 8a93ef934..44bb8b7e5 100644 --- a/api-ref/source/v2/samples/security-groups/security-group-create-request.json +++ b/api-ref/source/v2/samples/security-groups/security-group-create-request.json @@ -1,6 +1,7 @@ { "security_group": { "name": "new-webservers", - "description": "security group for webservers" + "description": "security group for webservers", + "stateful": true } } diff --git a/api-ref/source/v2/samples/security-groups/security-group-create-response.json b/api-ref/source/v2/samples/security-groups/security-group-create-response.json index 74416c7a9..31a91fc27 100644 --- a/api-ref/source/v2/samples/security-groups/security-group-create-response.json +++ b/api-ref/source/v2/samples/security-groups/security-group-create-response.json @@ -47,6 +47,7 @@ "updated_at": "2018-03-19T19:16:56Z", "revision_number": 1, "tags": ["tag1,tag2"], - "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550", + "stateful": true } } diff --git a/api-ref/source/v2/samples/security-groups/security-group-show-response.json b/api-ref/source/v2/samples/security-groups/security-group-show-response.json index a411fef04..a1aed4b06 100644 --- a/api-ref/source/v2/samples/security-groups/security-group-show-response.json +++ b/api-ref/source/v2/samples/security-groups/security-group-show-response.json @@ -82,6 +82,7 @@ "updated_at": "2018-03-19T19:16:56Z", "revision_number": 4, "tags": ["tag1,tag2"], - "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550", + "stateful": true } } diff --git a/api-ref/source/v2/samples/security-groups/security-group-update-request.json b/api-ref/source/v2/samples/security-groups/security-group-update-request.json index 67bfda27c..44e2036a7 100644 --- a/api-ref/source/v2/samples/security-groups/security-group-update-request.json +++ b/api-ref/source/v2/samples/security-groups/security-group-update-request.json @@ -1,6 +1,7 @@ { "security_group": { "name": "mysecgroup", - "description": "my security group" + "description": "my security group", + "stateful": true } } diff --git a/api-ref/source/v2/samples/security-groups/security-group-update-response.json b/api-ref/source/v2/samples/security-groups/security-group-update-response.json index d94141610..e2b1cf4fe 100644 --- a/api-ref/source/v2/samples/security-groups/security-group-update-response.json +++ b/api-ref/source/v2/samples/security-groups/security-group-update-response.json @@ -9,6 +9,7 @@ "id": "01fbade5-b664-42f6-83ae-4e214f4263fa", "name": "mysecgroup", "description": "my security group", - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "stateful": true } } diff --git a/api-ref/source/v2/samples/security-groups/security-groups-list-response.json b/api-ref/source/v2/samples/security-groups/security-groups-list-response.json index b4b9506e6..642c63e72 100644 --- a/api-ref/source/v2/samples/security-groups/security-groups-list-response.json +++ b/api-ref/source/v2/samples/security-groups/security-groups-list-response.json @@ -83,7 +83,8 @@ "created_at": "2018-03-19T19:16:56Z", "updated_at": "2018-03-19T19:16:56Z", "tags": ["tag1,tag2"], - "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" + "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550", + "stateful": true } ] } diff --git a/api-ref/source/v2/security-groups.inc b/api-ref/source/v2/security-groups.inc index d0c10c33c..230d51ce3 100644 --- a/api-ref/source/v2/security-groups.inc +++ b/api-ref/source/v2/security-groups.inc @@ -20,6 +20,14 @@ The ``standard-attr-tag`` adds Tag support for resources with standard attributes by adding the ``tags`` attribute allowing consumers to associate tags with resources. +Stateful security groups extension (``stateful-security-group``) +================================================================ + +The stateful security group extension (``stateful-security-group``) adds the +``stateful`` field to security groups, allowing users to configure stateful +or stateless security groups for ``ports``. The existing security groups +will all be considered as stateful. Update of the ``stateful`` attribute is +allowed when there is no port associated with the security group. List security groups ==================== @@ -76,6 +84,7 @@ Response Parameters - description: description - security_group_rules: security_group_rules - tags: tags + - stateful: stateful_enabled Response Example ---------------- @@ -107,6 +116,7 @@ Request - project_id: project_id - description: description-request - name: name + - stateful: stateful_enabled Request Example --------------- @@ -130,6 +140,7 @@ Response Parameters - description: description - security_group_rules: security_group_rules - tags: tags + - stateful: stateful_enabled Response Example ---------------- @@ -181,6 +192,7 @@ Response Parameters - description: description - security_group_rules: security_group_rules - tags: tags + - stateful: stateful_enabled Response Example ---------------- @@ -231,6 +243,7 @@ Response Parameters - description: description - security_group_rules: security_group_rules - tags: tags + - stateful: stateful_enabled Response Example ---------------- diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 04ba25666..f522a9d4b 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -96,6 +96,7 @@ from neutron_lib.api.definitions import sfc from neutron_lib.api.definitions import sort_key_validation from neutron_lib.api.definitions import sorting 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_onboard @@ -200,6 +201,7 @@ _ALL_API_DEFINITIONS = { sort_key_validation, sorting, standard_attr_segment, + stateful_security_group, subnet, subnet_dns_publish_fixed_ip, subnet_onboard, diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index a4dd0aab5..4ab079402 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -55,7 +55,8 @@ KNOWN_RESOURCES = ( 'ports', 'routers', 'subnets', - 'subnetpools' + 'subnetpools', + 'security_groups' ) KNOWN_HTTP_ACTIONS = ( diff --git a/neutron_lib/api/definitions/stateful_security_group.py b/neutron_lib/api/definitions/stateful_security_group.py new file mode 100644 index 000000000..b056d85f7 --- /dev/null +++ b/neutron_lib/api/definitions/stateful_security_group.py @@ -0,0 +1,61 @@ +# Copyright 2018 NOKIA +# +# 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 + + +# The alias of the extension. +ALIAS = 'stateful-security-group' + +IS_SHIM_EXTENSION = False + +IS_STANDARD_ATTR_EXTENSION = False + +# The name of the extension. +NAME = 'Stateful security group' + +# The description of the extension. +DESCRIPTION = "Indicates if the security group is stateful or not" + +# A timestamp of when the extension was introduced. +UPDATED_TIMESTAMP = "2019-11-26T09:00:00-00:00" + +# The resource attribute map for the extension. +RESOURCE_ATTRIBUTE_MAP = { + 'security_groups': { + 'stateful': {'allow_post': True, 'allow_put': True, + 'is_visible': True, 'default': True, + 'convert_to': converters.convert_to_boolean} + } +} + +# The subresource attribute map for the extension. +SUB_RESOURCE_ATTRIBUTE_MAP = { +} + +# The action map. +ACTION_MAP = { +} + +# The action status. +ACTION_STATUS = { +} + +# The list of required extensions. +REQUIRED_EXTENSIONS = ['security-group'] + +# The list of optional extensions. +OPTIONAL_EXTENSIONS = [ +] diff --git a/neutron_lib/tests/unit/api/definitions/test_stateful_security_group.py b/neutron_lib/tests/unit/api/definitions/test_stateful_security_group.py new file mode 100644 index 000000000..bd7c17ef8 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_stateful_security_group.py @@ -0,0 +1,23 @@ +# Copyright 2018 NOKIA +# +# 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 stateful_security_group +from neutron_lib.tests.unit.api.definitions import base + + +class StatefulSecurityGroupDefinitionTestCase(base.DefinitionBaseTestCase): + + extension_module = stateful_security_group + extension_attributes = ('stateful',) diff --git a/releasenotes/notes/stateful-security-group-a1ece5472f029dc1.yaml b/releasenotes/notes/stateful-security-group-a1ece5472f029dc1.yaml new file mode 100644 index 000000000..fde687a43 --- /dev/null +++ b/releasenotes/notes/stateful-security-group-a1ece5472f029dc1.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The API defintion for the ``stateful-security-group`` extension is + now available in ``neutron_lib.api.definitions.stateful_security_group``. \ No newline at end of file