Add neutron pagination and sort query parameters

Pagination and sorting is implemented deep inside neutron and is not
directly visible on the resource schemas. Add those by default to every
indexing method (except of extensions where it is known to be ignored).

Change-Id: Ia8055d1edd08581193f2e722f911a50f6a3c63d3
This commit is contained in:
Artem Goncharov 2024-08-22 10:18:01 +02:00
parent c5461caef2
commit 76269d0283

View File

@ -281,7 +281,40 @@ class NeutronGenerator(OpenStackServerSourceBase):
}
},
headers={},
parameters={},
parameters={
"limit": ParameterSchema(
name="limit",
location="query",
description="Requests a page size of items. Returns a number of items up to a limit value. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.",
type_schema=TypeSchema(type="integer", minimum=0),
),
"marker": ParameterSchema(
name="marker",
location="query",
description="The ID of the last-seen item. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.",
type_schema=TypeSchema(type="string"),
),
"page_reverse": ParameterSchema(
name="page_reverse",
location="query",
description="Reverse the page direction",
type_schema=TypeSchema(type="boolean"),
),
"sort_key": ParameterSchema(
name="sort_key",
location="query",
description="Sort results by the attribute. This is an optional feature and may be silently ignored by the server.",
type_schema=TypeSchema(type="string"),
),
"sort_dir": ParameterSchema(
name="sort_dir",
location="query",
description="Sort direction. This is an optional feature and may be silently ignored by the server.",
type_schema=TypeSchema(
type="string", enum=["asc", "desc"]
),
),
},
schemas={},
),
)
@ -724,7 +757,26 @@ class NeutronGenerator(OpenStackServerSourceBase):
operation_spec.parameters.append(
ParameterSchema(ref=param_ref_name)
)
if path != "/v2.0/extensions" and collection not in ["extensions"]:
# All Neutron LIST operations support pagination and sorting (as
# much as possible). Sadly there is no preciese info whether
# certain operations do not support that so we add it everywhere
# by default.
operation_spec.parameters.append(
ParameterSchema(ref="#/components/parameters/sort_key")
)
operation_spec.parameters.append(
ParameterSchema(ref="#/components/parameters/sort_dir")
)
operation_spec.parameters.append(
ParameterSchema(ref="#/components/parameters/limit")
)
operation_spec.parameters.append(
ParameterSchema(ref="#/components/parameters/marker")
)
operation_spec.parameters.append(
ParameterSchema(ref="#/components/parameters/page_reverse")
)
responses_spec = operation_spec.responses
if method == "DELETE":
response_code = "204"