diff --git a/api-ref/source/v2/agents.inc b/api-ref/source/v2/agents.inc index fcc38635c..65621fd19 100644 --- a/api-ref/source/v2/agents.inc +++ b/api-ref/source/v2/agents.inc @@ -51,6 +51,8 @@ Request - id: id-query - topic: topic-query - fields: fields + - sort_dir: sort_dir + - sort_key: agent-sort_key Response Parameters ------------------- diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index 2620eb7bf..ff085fb05 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -327,6 +327,25 @@ admin_state_up_trunk-query: in: query required: false type: boolean +agent-sort_key: + description: | + Sorts by agent attributes. You can specify multiple pairs of sort key + and sort direction query parameters. The sort keys are limited to: + + - ``admin_state_up`` + - ``agent_type`` + - ``alive`` + - ``binary`` + - ``created_at`` + - ``description`` + - ``heartbeat_timestamp`` + - ``host`` + - ``id`` + - ``started_at`` + - ``topic`` + in: query + required: false + type: string agent_type-query: description: | Filter the list result by the type of agent such as ``Open vSwitch agent`` diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 94bf81d84..a200c2fb1 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -13,6 +13,7 @@ from neutron_lib.api.definitions import address_scope from neutron_lib.api.definitions import agent from neutron_lib.api.definitions import agent_resources_synced +from neutron_lib.api.definitions import agent_sort_key from neutron_lib.api.definitions import allowedaddresspairs from neutron_lib.api.definitions import auto_allocated_topology from neutron_lib.api.definitions import availability_zone @@ -124,6 +125,7 @@ _ALL_API_DEFINITIONS = { address_scope, agent, agent_resources_synced, + agent_sort_key, allowedaddresspairs, auto_allocated_topology, availability_zone, diff --git a/neutron_lib/api/definitions/agent_sort_key.py b/neutron_lib/api/definitions/agent_sort_key.py new file mode 100644 index 000000000..e0024ac40 --- /dev/null +++ b/neutron_lib/api/definitions/agent_sort_key.py @@ -0,0 +1,36 @@ +# Copyright (c) 2013 OpenStack Foundation. +# +# 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 agent + +ALIAS = 'agent_sort_key' +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Agents Sort Key' +API_PREFIX = '' +DESCRIPTION = 'Enabling the keyword sort_key for sorting in agents.' +UPDATED_TIMESTAMP = '2013-02-03T10:00:00-00:00' +is_sort_key = {'is_sort_key': True} +agents_collection = agent.RESOURCE_ATTRIBUTE_MAP[agent.COLLECTION_NAME] +RESOURCE_ATTRIBUTE_MAP = { + agent.COLLECTION_NAME: { + k: {**v, **is_sort_key} for k, v in agents_collection.items() if + k != "configurations"} +} +SUB_RESOURCE_ATTRIBUTE_MAP = {} +ACTION_MAP = {} +REQUIRED_EXTENSIONS = [] +OPTIONAL_EXTENSIONS = [] +ACTION_STATUS = {} diff --git a/neutron_lib/tests/unit/api/definitions/test_agent_sort_key.py b/neutron_lib/tests/unit/api/definitions/test_agent_sort_key.py new file mode 100644 index 000000000..fec115496 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_agent_sort_key.py @@ -0,0 +1,25 @@ +# 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 agent +from neutron_lib.api.definitions import agent_sort_key +from neutron_lib.tests.unit.api.definitions import base + + +class AgentDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = agent_sort_key + extension_resources = (agent.COLLECTION_NAME,) + extension_attributes = ('topic', 'agent_type', 'created_at', + 'configurations', 'heartbeat_timestamp', + 'binary', 'started_at', 'host', 'alive',) diff --git a/releasenotes/notes/bug-1877254-2b997b3911e98079.yaml b/releasenotes/notes/bug-1877254-2b997b3911e98079.yaml new file mode 100644 index 000000000..a8afe9a14 --- /dev/null +++ b/releasenotes/notes/bug-1877254-2b997b3911e98079.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add keyword ``is_sort_key`` to agents. Make the agent's + attribute can be used as a sort key for sorting list result.