From b03226d59739fafe036bc60c62f165da598ca947 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Wed, 4 Apr 2018 18:37:05 +0000 Subject: [PATCH] Annotate network parameters for sort_key Add a 'is_sort_key' keyword for each network's attribute that can be used as a sort_key. In the future, we will rely on this keyword to perform validation: https://review.openstack.org/#/c/554368/ . Change-Id: I6104a1b534a7ddc4856bd1a25d77e12b1ed5421f Related-Bug: #1749820 --- doc/source/contributor/api_attributes.rst | 1 + neutron_lib/api/definitions/base.py | 3 ++- neutron_lib/api/definitions/network.py | 8 ++++++-- neutron_lib/api/definitions/network_availability_zone.py | 1 + neutron_lib/api/definitions/network_mtu.py | 2 +- neutron_lib/tests/unit/api/definitions/base.py | 1 + ...ort_key-keyword-to-attribute-map-75342446d99f4490.yaml | 5 +++++ 7 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-is_sort_key-keyword-to-attribute-map-75342446d99f4490.yaml diff --git a/doc/source/contributor/api_attributes.rst b/doc/source/contributor/api_attributes.rst index 7d5913e18..514ddec7e 100644 --- a/doc/source/contributor/api_attributes.rst +++ b/doc/source/contributor/api_attributes.rst @@ -85,6 +85,7 @@ The following are the defined keys for attribute maps: ``convert_to`` transformation to apply to the value before it is returned ``convert_list_to`` if the value is a list, apply this transformation to the value before it is returned ``is_filter`` the attribute can be used in ``GET`` requests as filter +``is_sort_key`` the attribute can be used in ``GET`` requests as sort_key ``is_visible`` the attribute is returned in ``GET`` responses ``required_by_policy`` the attribute is required by the policy engine and should therefore be filled by the API layer even if not present in request body ``enforce_policy`` the attribute is actively part of the policy enforcing mechanism, ie: there might be rules which refer to this attribute diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index dc32193eb..340dd5c18 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -141,8 +141,9 @@ KNOWN_KEYWORDS = ( 'convert_list_to', 'default', 'enforce_policy', - 'is_visible', 'is_filter', + 'is_sort_key', + 'is_visible', 'primary_key', 'required_by_policy', 'validate', diff --git a/neutron_lib/api/definitions/network.py b/neutron_lib/api/definitions/network.py index 64f9bcdce..91a5a1493 100644 --- a/neutron_lib/api/definitions/network.py +++ b/neutron_lib/api/definitions/network.py @@ -37,11 +37,13 @@ RESOURCE_ATTRIBUTE_MAP = { 'validate': {'type:uuid': None}, 'is_visible': True, 'is_filter': True, + 'is_sort_key': True, 'primary_key': True}, 'name': {'allow_post': True, 'allow_put': True, 'validate': { 'type:string': db_const.NAME_FIELD_SIZE}, - 'default': '', 'is_visible': True, 'is_filter': True}, + 'default': '', 'is_visible': True, 'is_filter': True, + 'is_sort_key': True}, subnet.COLLECTION_NAME: {'allow_post': False, 'allow_put': False, 'default': [], 'is_visible': True}, @@ -49,14 +51,16 @@ RESOURCE_ATTRIBUTE_MAP = { 'default': True, 'convert_to': converters.convert_to_boolean, 'is_filter': True, + 'is_sort_key': True, 'is_visible': True}, 'status': {'allow_post': False, 'allow_put': False, - 'is_visible': True, 'is_filter': True}, + 'is_visible': True, 'is_filter': True, 'is_sort_key': True}, 'tenant_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}, constants.SHARED: { 'allow_post': True, diff --git a/neutron_lib/api/definitions/network_availability_zone.py b/neutron_lib/api/definitions/network_availability_zone.py index 693c349a1..57dfe2414 100644 --- a/neutron_lib/api/definitions/network_availability_zone.py +++ b/neutron_lib/api/definitions/network_availability_zone.py @@ -31,6 +31,7 @@ RESOURCE_ATTRIBUTE_MAP = { }, az_def.AZ_HINTS: { 'allow_post': True, 'allow_put': False, 'is_visible': True, + 'is_sort_key': True, 'validate': {'type:availability_zone_hint_list': None}, 'default': [] } diff --git a/neutron_lib/api/definitions/network_mtu.py b/neutron_lib/api/definitions/network_mtu.py index 085103c5b..d68d252dd 100644 --- a/neutron_lib/api/definitions/network_mtu.py +++ b/neutron_lib/api/definitions/network_mtu.py @@ -53,7 +53,7 @@ UPDATED_TIMESTAMP = "2015-03-25T10:00:00-00:00" RESOURCE_ATTRIBUTE_MAP = { network.COLLECTION_NAME: { MTU: {'allow_post': False, 'allow_put': False, - 'is_visible': True, 'is_filter': True}, + 'is_visible': True, 'is_filter': True, 'is_sort_key': True}, }, } diff --git a/neutron_lib/tests/unit/api/definitions/base.py b/neutron_lib/tests/unit/api/definitions/base.py index 1e3a84ea0..586fc20f8 100644 --- a/neutron_lib/tests/unit/api/definitions/base.py +++ b/neutron_lib/tests/unit/api/definitions/base.py @@ -59,6 +59,7 @@ ASSERT_FUNCTIONS = { 'default': assert_converter, 'enforce_policy': assert_bool, 'is_filter': assert_bool, + 'is_sort_key': assert_bool, 'is_visible': assert_bool, 'primary_key': assert_true, 'required_by_policy': assert_bool, diff --git a/releasenotes/notes/add-is_sort_key-keyword-to-attribute-map-75342446d99f4490.yaml b/releasenotes/notes/add-is_sort_key-keyword-to-attribute-map-75342446d99f4490.yaml new file mode 100644 index 000000000..133960422 --- /dev/null +++ b/releasenotes/notes/add-is_sort_key-keyword-to-attribute-map-75342446d99f4490.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add a new keyword ``is_sort_key`` to attribute maps. This keyword indicates + that the attribute can be used as a sort key for sorting list result.