Workaround BS quota api path issues

In cinder quota-set and quota-class-set controllers are not having any
decorators and are not very usable to the parameter naming. Implement a
post_process fix for that since there are no better points.

Change-Id: I09ca1b0882486bede501e4255fafc0d39fab2958
Signed-off-by: gtema <artem.goncharov@gmail.com>
This commit is contained in:
gtema
2025-09-05 15:10:00 +00:00
parent 2bdb13b3d0
commit 12eb3dfde3

View File

@@ -11,6 +11,7 @@
# under the License.
#
from multiprocessing import Process
from itertools import chain
from pathlib import Path
from ruamel.yaml.scalarstring import LiteralScalarString
@@ -177,6 +178,8 @@ class CinderV3Generator(OpenStackServerSourceBase):
self._process_route(route, openapi_spec, ver_prefix="/v3")
self._post_process(openapi_spec)
self._sanitize_param_ver_info(openapi_spec, self.min_api_version)
if args.api_ref_src:
@@ -208,6 +211,120 @@ class CinderV3Generator(OpenStackServerSourceBase):
if path and ("/consistencygroups" in path or "/cgsnapshots" in path):
operation_spec.deprecated = True
def _post_process(self, openapi_spec):
"""Repair urls and url parametes"""
for path in [
"/v3/{project_id}/os-quota-sets/{id}",
"/v3/{project_id}/os-quota-sets/{id}/defaults",
]:
new_path = path.replace("{project_id}", "{admin_project_id}")
openapi_spec.paths[new_path] = openapi_spec.paths.pop(path)
for par in [
openapi_spec.components.parameters[x.ref.split("/")[-1]]
for x in openapi_spec.paths[new_path].parameters
if x.ref
]:
if par.location == "path" and par.name == "project_id":
par.name = "admin_project_id"
par.description = "The admin project id attribute"
for path in [
"/v3/{admin_project_id}/os-quota-sets/{id}",
"/v3/{admin_project_id}/os-quota-sets/{id}/defaults",
"/v3/os-quota-sets/{id}",
"/v3/os-quota-sets/{id}/defaults",
]:
new_path = path.replace("{id}", "{project_id}")
openapi_spec.paths[new_path] = openapi_spec.paths.pop(path)
for par in [
openapi_spec.components.parameters[x.ref.split("/")[-1]]
for x in openapi_spec.paths[new_path].parameters
if x.ref
]:
if par.location == "path" and par.name == "id":
par.name = "project_id"
par.description = "The quota-set project_id attribute"
if not par.openstack:
par.openstack = {}
par.openstack["resource_link"] = "identity/v3/project.id"
for path in [
"/v3/{admin_project_id}/os-quota-sets/{project_id}",
"/v3/os-quota-sets/{project_id}",
]:
path_spec = openapi_spec.paths[path]
path_spec.get.description = (
"""Show quota for a particular tenant"""
)
path_spec.get.summary = """Show quota for a particular tenant"""
path_spec.get.parameters.append(
ParameterSchema(
ref="#/components/parameters/os_quota_sets_usage"
)
)
path_spec.put.description = (
"""Update quota for a particular tenant"""
)
path_spec.put.summary = """Update quota for a particular tenant"""
path_spec.delete.description = (
"""Delete quota for a particular tenant"""
)
path_spec.delete.summary = (
"""Delete quota for a particular tenant"""
)
openapi_spec.components.parameters["os_quota_sets_usage"] = (
ParameterSchema(
location="query",
name="usage",
type_schema=TypeSchema(type="boolean"),
description="Show projects quota usage information. Default is false.",
)
)
for path in [
"/v3/{project_id}/os-quota-class-sets/{id}",
"/v3/os-quota-class-sets/{id}",
]:
new_path = path.replace(
"{project_id}", "{admin_project_id}"
).replace("{id}", "{name}")
openapi_spec.paths[new_path] = openapi_spec.paths.pop(path)
for par in [
openapi_spec.components.parameters[x.ref.split("/")[-1]]
for x in openapi_spec.paths[new_path].parameters
if x.ref
]:
if par.location == "path" and par.name == "id":
par.name = "name"
elif par.location == "path" and par.name == "project_id":
par.name = "admin_project_id"
path_spec = openapi_spec.paths[new_path]
path_spec.get.description = "Show quota classes for a project"
path_spec.get.summary = "Show quota classes for a project"
path_spec.put.description = "Update quota classes for a project"
path_spec.put.summary = "Update quota classes for a project"
for path in ["/v3/{project_id}/os-hosts", "/v3/os-hosts"]:
new_path = path.replace("{project_id}", "{admin_project_id}")
openapi_spec.paths[new_path] = openapi_spec.paths.pop(path)
path_spec = openapi_spec.paths[new_path]
path_spec.get.description = "List all hosts for a project"
path_spec.get.summary = "List all hosts for a project"
for path in ["/v3/{project_id}/os-hosts/{id}", "/v3/os-hosts/{id}"]:
new_path = path.replace(
"{project_id}", "{admin_project_id}"
).replace("{id}", "{host_name}")
openapi_spec.paths[new_path] = openapi_spec.paths.pop(path)
for par in [
openapi_spec.components.parameters[x.ref.split("/")[-1]]
for x in openapi_spec.paths[new_path].parameters
if x.ref
]:
if par.location == "path" and par.name == "id":
par.name = "host_name"
elif par.location == "path" and par.name == "project_id":
par.name = "admin_project_id"
path_spec = openapi_spec.paths[new_path]
path_spec.get.description = "Show Host Details for a project"
path_spec.get.summary = "Show quota classes for a project"
def _get_schema_ref(
self,
openapi_spec,