From c2e02f1dfb1fd5857b62f21e017a9b6cba18dfb6 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Wed, 6 Nov 2024 10:34:58 +0100 Subject: [PATCH] Add placement RP allocation and traits schemas Change-Id: Ifd95748430564cc1bbfff4874e77cb1ed5b6a104 --- .../openapi/placement_schemas/allocation.py | 46 +++++++++++++++++++ .../openapi/placement_schemas/trait.py | 26 +++++++++++ 2 files changed, 72 insertions(+) diff --git a/codegenerator/openapi/placement_schemas/allocation.py b/codegenerator/openapi/placement_schemas/allocation.py index 3ed2a61..50c1a41 100644 --- a/codegenerator/openapi/placement_schemas/allocation.py +++ b/codegenerator/openapi/placement_schemas/allocation.py @@ -76,6 +76,44 @@ ALLOCATION_POST_REQUEST_SCHEMA: dict[str, Any] = { "x-openstack": {"discriminator": "microversion"}, } +ALLOCATION_RP_RESPONSE_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "allocations": { + "type": "object", + "minProperties": 0, + "patternProperties": { + "^[0-9a-fA-F-]{36}$": { + "type": "object", + "description": "A dictionary of allocation records keyed by consumer uuid.", + "properties": { + "resources": { + "type": "object", + "description": "A dictionary of resource records keyed by resource class name.", + "minProperties": 1, + "patternProperties": { + "^[A-Z0-9_]+$": { + "type": "integer", + "minimum": 1, + } + }, + "additionalProperties": False, + }, + "required": ["resources"], + "additionalProperties": False, + }, + "additionalProperties": False, + } + }, + }, + "resource_provider_generation": { + "type": "integer", + "description": "A consistent view marker that assists with the management of concurrent resource provider updates.", + }, + }, + "required": ["allocations", "resource_provider_generation"], +} + def _get_schema_ref( openapi_spec, name, description=None, schema_def=None, action_name=None @@ -99,6 +137,14 @@ def _get_schema_ref( name, TypeSchema(**ALLOCATION_UPDATE_REQUEST_SCHEMA) ) ref = f"#/components/schemas/{name}" + elif ( + name + == "Resource_ProvidersAllocationsList_For_Resource_ProviderResponse" + ): + openapi_spec.components.schemas.setdefault( + name, TypeSchema(**ALLOCATION_RP_RESPONSE_SCHEMA) + ) + ref = f"#/components/schemas/{name}" elif name == "AllocationSet_Allocations_For_ConsumerResponse": return (None, None, True) diff --git a/codegenerator/openapi/placement_schemas/trait.py b/codegenerator/openapi/placement_schemas/trait.py index ead6592..de48a2e 100644 --- a/codegenerator/openapi/placement_schemas/trait.py +++ b/codegenerator/openapi/placement_schemas/trait.py @@ -46,6 +46,23 @@ TRAIT_LIST_PARAMETERS: dict[str, Any] = { }, } +RP_TRAITS_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "traits": { + "type": "array", + "items": {"type": "string", "minLength": 1, "maxLength": 255}, + "description": "A list of resource_class objects.", + }, + "resource_provider_generation": { + "type": "integer", + "description": "A consistent view marker that assists with the management of concurrent resource provider updates.", + }, + }, + "required": ["traits", "resource_provider_generation"], + "additionalProperties": False, +} + def _post_process_operation_hook( openapi_spec, operation_spec, path: str | None = None @@ -82,6 +99,15 @@ def _get_schema_ref( ]: # Traits have no bodies return (None, None, True) + elif name in [ + "Resource_ProvidersTraitsList_Traits_For_Resource_ProviderResponse", + "Resource_ProvidersTraitsUpdate_Traits_For_Resource_ProviderRequest", + "Resource_ProvidersTraitsUpdate_Traits_For_Resource_ProviderResponse", + ]: + openapi_spec.components.schemas.setdefault( + name, TypeSchema(**TRAITS_SCHEMA) + ) + ref = f"#/components/schemas/{name}" else: return (None, None, False)

AltStyle によって変換されたページ (->オリジナル) /