diff --git a/codegenerator/openapi/placement.py b/codegenerator/openapi/placement.py index 5a8084c..12920a6 100644 --- a/codegenerator/openapi/placement.py +++ b/codegenerator/openapi/placement.py @@ -32,6 +32,7 @@ from codegenerator.openapi.placement_schemas import reshaper from codegenerator.openapi.placement_schemas import resource_class from codegenerator.openapi.placement_schemas import resource_provider from codegenerator.openapi.placement_schemas import trait +from codegenerator.openapi.placement_schemas import usage class PlacementGenerator(OpenStackServerSourceBase): @@ -46,6 +47,7 @@ class PlacementGenerator(OpenStackServerSourceBase): resource_class, resource_provider, trait, + usage, ] VERSIONED_METHODS: dict = {} diff --git a/codegenerator/openapi/placement_schemas/usage.py b/codegenerator/openapi/placement_schemas/usage.py new file mode 100644 index 0000000..5800a47 --- /dev/null +++ b/codegenerator/openapi/placement_schemas/usage.py @@ -0,0 +1,98 @@ +# 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 TypeSchema +from codegenerator.common.schema import ParameterSchema + +USAGES_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "usages": { + "type": "object", + "patternProperties": { + "^[A-Z0-9_]+$": { + "type": "object", + "properties": { + "consumer_count": { + "type": "integer", + "description": "The number of consumers of a particular consumer_type.", + "x-openstack": {"min-ver": "1.38"}, + } + }, + "patternProperties": {"^[A-Z0-9_]+$": {"type": "integer"}}, + } + }, + } + }, + "required": ["usages"], + "additionalProperties": False, +} + +USAGE_LIST_PARAMETERS: dict[str, Any] = { + "project_id": { + "in": "query", + "name": "project_id", + "description": "The uuid of a project.", + "schema": {"type": "string", "format": "uuid"}, + }, + "user_id": { + "in": "query", + "name": "user_id", + "description": "The uuid of a user.", + "schema": {"type": "string", "format": "uuid"}, + }, + "consumer_type": { + "in": "query", + "name": "consumer_type", + "description": "A string that consists of numbers, A-Z, and _ describing the consumer type by which to filter usage results. For example, to retrieve only usage information for ‘INSTANCE’ type consumers a parameter of consumer_type=INSTANCE should be provided. The all query parameter may be specified to group all results under one key, all. The unknown query parameter may be specified to group all results under one key, unknown.", + "schema": {"type": "string"}, + "x-openstack": {"min-ver": "1.38"}, + }, +} + + +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 == "usages:get": + for key, val in USAGE_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 == "UsagesGet_Total_UsagesResponse": + openapi_spec.components.schemas.setdefault( + name, TypeSchema(**USAGES_SCHEMA) + ) + ref = f"#/components/schemas/{name}" + + else: + return (None, None, False) + + return (ref, mime_type, True) diff --git a/metadata/placement_metadata.yaml b/metadata/placement_metadata.yaml new file mode 100644 index 0000000..bff9257 --- /dev/null +++ b/metadata/placement_metadata.yaml @@ -0,0 +1,413 @@ +resources: + placement.version: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + get: + operation_id: :get + operation_type: get + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: get + sdk_mod_name: get + cli_full_command: version get + placement.resource_class: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + list: + operation_id: resource_classes:get + operation_type: list + targets: + rust-sdk: + module_name: list + rust-cli: + module_name: list + sdk_mod_name: list + cli_full_command: resource-class list + create: + operation_id: resource_classes:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: resource-class create + show: + operation_id: resource_classes/name:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: resource-class show + update: + operation_id: resource_classes/name:put + operation_type: set + targets: + rust-sdk: + module_name: set + rust-cli: + module_name: set + sdk_mod_name: set + cli_full_command: resource-class set + delete: + operation_id: resource_classes/name:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: resource-class delete + placement.resource_provider: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + list: + operation_id: resource_providers:get + operation_type: list + targets: + rust-sdk: + module_name: list + rust-cli: + module_name: list + sdk_mod_name: list + cli_full_command: resource-provider list + create: + operation_id: resource_providers:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: resource-provider create + show: + operation_id: resource_providers/uuid:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: resource-provider show + update: + operation_id: resource_providers/uuid:put + operation_type: set + targets: + rust-sdk: + module_name: set + rust-cli: + module_name: set + sdk_mod_name: set + cli_full_command: resource-provider set + delete: + operation_id: resource_providers/uuid:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: resource-provider delete + placement.resource_provider/inventory: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + list: + operation_id: resource_providers/uuid/inventories:get + operation_type: list + targets: + rust-sdk: + module_name: list + rust-cli: + module_name: list + sdk_mod_name: list + cli_full_command: resource-provider inventory list + replace: + operation_id: resource_providers/uuid/inventories:put + operation_type: set + targets: + rust-sdk: + module_name: replace + rust-cli: + module_name: replace + sdk_mod_name: replace + cli_full_command: resource-provider inventory replace + create: + operation_id: resource_providers/uuid/inventories:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: resource-provider inventory create + delete_all: + operation_id: resource_providers/uuid/inventories:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete_all + rust-cli: + module_name: delete_all + sdk_mod_name: delete_all + cli_full_command: resource-provider inventory delete-all + show: + operation_id: resource_providers/uuid/inventories/resource_class:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: resource-provider inventory show + update: + operation_id: resource_providers/uuid/inventories/resource_class:put + operation_type: set + targets: + rust-sdk: + module_name: set + rust-cli: + module_name: set + sdk_mod_name: set + cli_full_command: resource-provider inventory set + delete: + operation_id: resource_providers/uuid/inventories/resource_class:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: resource-provider inventory delete + placement.resource_provider/usage: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + get: + operation_id: resource_providers/uuid/usages:get + operation_type: get + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: get + sdk_mod_name: get + cli_full_command: resource-provider usage get + placement.resource_provider/aggregate: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + get: + operation_id: resource_providers/uuid/aggregates:get + operation_type: get + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: get + sdk_mod_name: get + cli_full_command: resource-provider aggregate get + aggregates: + operation_id: resource_providers/uuid/aggregates:put + operation_type: action + targets: + rust-sdk: + module_name: aggregates + rust-cli: + module_name: aggregates + sdk_mod_name: aggregates + cli_full_command: resource-provider aggregate aggregates + placement.resource_provider/allocation: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + get: + operation_id: resource_providers/uuid/allocations:get + operation_type: get + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: get + sdk_mod_name: get + cli_full_command: resource-provider allocation get + placement.allocation: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + create: + operation_id: allocations:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: allocation create + show: + operation_id: allocations/consumer_uuid:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: allocation show + update: + operation_id: allocations/consumer_uuid:put + operation_type: set + targets: + rust-sdk: + module_name: set + rust-cli: + module_name: set + sdk_mod_name: set + cli_full_command: allocation set + delete: + operation_id: allocations/consumer_uuid:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: allocation delete + placement.allocation_candidate: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + show: + operation_id: allocation_candidates:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: allocation-candidate show + placement.trait: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + list: + operation_id: traits:get + operation_type: list + targets: + rust-sdk: + module_name: list + rust-cli: + module_name: list + sdk_mod_name: list + cli_full_command: trait list + show: + operation_id: traits/name:get + operation_type: show + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: show + sdk_mod_name: get + cli_full_command: trait show + update: + operation_id: traits/name:put + operation_type: set + targets: + rust-sdk: + module_name: set + rust-cli: + module_name: set + sdk_mod_name: set + cli_full_command: trait set + delete: + operation_id: traits/name:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: trait delete + placement.resource_provider/trait: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + get: + operation_id: resource_providers/uuid/traits:get + operation_type: get + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: get + sdk_mod_name: get + cli_full_command: resource-provider trait get + traits: + operation_id: resource_providers/uuid/traits:put + operation_type: action + targets: + rust-sdk: + module_name: traits + rust-cli: + module_name: traits + sdk_mod_name: traits + cli_full_command: resource-provider trait traits + delete: + operation_id: resource_providers/uuid/traits:delete + operation_type: delete + targets: + rust-sdk: + module_name: delete + rust-cli: + module_name: delete + sdk_mod_name: delete + cli_full_command: resource-provider trait delete + placement.usage: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + get: + operation_id: usages:get + operation_type: get + targets: + rust-sdk: + module_name: get + rust-cli: + module_name: get + sdk_mod_name: get + cli_full_command: usage get + placement.reshaper: + spec_file: wrk/openapi_specs/placement/v1.yaml + api_version: v1 + operations: + create: + operation_id: reshaper:post + operation_type: create + targets: + rust-sdk: + module_name: create + rust-cli: + module_name: create + sdk_mod_name: create + cli_full_command: reshaper create

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