Add BS.scheduler_stats.pools schema and QP

Change-Id: I40364cff17095a140e478b1de196cc300d35b830
Signed-off-by: Artem Goncharov <artem.goncharov@gmail.com>
This commit is contained in:
Artem Goncharov
2025-12-19 11:09:31 +01:00
parent f36b4ccd12
commit d6058f14fe
3 changed files with 121 additions and 4 deletions

View File

@@ -80,17 +80,17 @@ class TypeSchema(BaseModel):
class ParameterSchema(BaseModel):
model_config = ConfigDict(extra="allow", populate_by_name=True)
location: str = Field(alias="in", default=None)
location: str | None = Field(alias="in", default=None)
name: str | None = None
description: str | None = None
type_schema: TypeSchema = Field(alias="schema", default=None)
type_schema: TypeSchema | None = Field(alias="schema", default=None)
required: bool = False
deprecated: bool = False
style: str | None = None
explode: bool | None = None
uniqueItems: bool | None = None
ref: str = Field(alias="$ref", default=None)
openstack: dict[str, Any] = Field(alias="x-openstack", default=None)
ref: str | None = Field(alias="$ref", default=None)
openstack: dict[str, Any] | None = Field(alias="x-openstack", default=None)
def get_sdk_name(self):
return self.sdk_name or self.name

View File

@@ -33,6 +33,7 @@ from codegenerator.openapi.cinder_schemas import limit
from codegenerator.openapi.cinder_schemas import message
from codegenerator.openapi.cinder_schemas import qos
from codegenerator.openapi.cinder_schemas import resource_filter
from codegenerator.openapi.cinder_schemas import scheduler_stat
from codegenerator.openapi.cinder_schemas import snapshot
from codegenerator.openapi.cinder_schemas import snapshot_manage
from codegenerator.openapi.cinder_schemas import volume
@@ -58,6 +59,7 @@ class CinderV3Generator(OpenStackServerSourceBase):
message,
qos,
resource_filter,
scheduler_stat,
snapshot,
snapshot_manage,
volume,

View File

@@ -0,0 +1,115 @@
# 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.
#
import copy
from typing import Any
from codegenerator.common.schema import ParameterSchema, TypeSchema
POOL_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"capabilities": {
"description": "The capabilities for the back end. The value is either null or a string value that indicates the capabilities for each pool. For example, total_capacity_gb or QoS_support.",
"type": "object",
"properties": {
"driver_version": {
"description": "The driver version.",
"type": "string",
},
"free_capacity_gb": {
"description": "The amount of free capacity for the back-end volume, in GBs. A valid value is a string, such as unknown, or a number (integer or floating point).",
"minimum": 0,
"type": ["string", "integer"],
},
"reserved_percentage": {
"description": "The percentage of the total capacity that is reserved for the internal use by the back end.",
"type": "integer",
},
"storage_protocol": {
"description": "The storage back end for the back-end volume. For example, iSCSI or FC.",
"type": "string",
},
"total_capacity_gb": {
"description": "The total capacity for the back-end volume, in GBs. A valid value is a string, such as unknown, or a number (integer or floating point).",
"minimum": 0,
"type": ["string", "integer"],
},
"QoS_support": {
"description": "The quality of service (QoS) support.",
"type": "boolean",
},
"updated": {
"description": "The date and time stamp when the extension was last updated.",
"type": "string",
"format": "date-time",
},
"volume_backend_name": {
"description": "The name of the back-end volume.",
"type": "string",
},
},
},
"name": {
"description": "The name of the backend pool.",
"type": "string",
},
},
}
POOLS_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"pools": {"type": "array", "items": copy.deepcopy(POOL_SCHEMA)}
},
}
POOL_LIST_PARAMETERS: dict[str, Any] = {
"detail": {
"in": "query",
"name": "detail",
"description": "Indicates whether to show pool details or only pool names in the response. Set to true to show pool details. Set to false to show only pool names. Default is false.",
"schema": {"type": "boolean"},
}
}
def _post_process_operation_hook(
openapi_spec, operation_spec, path: str | None = None
):
"""Hook to allow service specific generator to modify details"""
operationId = operation_spec.operationId
if operationId in ["scheduler-stats/get_pools:get"]:
for key, val in POOL_LIST_PARAMETERS.items():
openapi_spec.components.parameters.setdefault(
key, ParameterSchema(**val)
)
ref = f"#/components/parameters/{key}"
if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))
def _get_schema_ref(
openapi_spec, name, description=None, schema_def=None, action_name=None
) -> tuple[str | None, str | None, bool]:
mime_type: str = "application/json"
ref: str
if name == "Scheduler_StatsGet_PoolsResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**POOLS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
else:
return (None, None, False)
return (ref, mime_type, True)