Add placement.reshaper schema
Change-Id: I65850fac2520f9fa030eaa2325231d1fb2726324
This commit is contained in:
2 changed files with 357 additions and 1 deletions
@@ -26,12 +26,13 @@ from codegenerator.openapi.base import OpenStackServerSourceBase
from codegenerator.openapi.utils import merge_api_ref_doc
from codegenerator.openapi.placement_schemas import resource_class
from codegenerator.openapi.placement_schemas import trait
from codegenerator.openapi.placement_schemas import reshaper
class PlacementGenerator(OpenStackServerSourceBase):
URL_TAG_MAP = {"/versions": "version"}
RESOURCE_MODULES = [resource_class, trait]
RESOURCE_MODULES = [reshaper, resource_class, trait]
VERSIONED_METHODS: dict = {}
355
codegenerator/openapi/placement_schemas/reshaper.py
Normal file
355
codegenerator/openapi/placement_schemas/reshaper.py
Normal file
@@ -0,0 +1,355 @@
# 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
# jsonschema in placement is not very valid and it's easier to copy it here
# rather then fix inline
RESHAPER_POST_SCHEMA: dict[str, Any] = {
"oneOf": [
{
"type": "object",
"properties": {
"inventories": {
"type": "object",
"description": "A dictionary of multiple inventories, keyed by resource provider uuid. Each inventory describes the desired full inventory for each resource provider. An empty dictionary causes the inventory for that provider to be deleted.",
"patternProperties": {
"^[0-9a-fA-F-]{36}$": {
"type": "object",
"properties": {
"resource_provider_generation": {
"type": "integer",
"description": "A consistent view marker that assists with the management of concurrent resource provider updates.",
},
"inventories": {
"type": "object",
"description": "A dictionary of inventories keyed by resource classes.",
"patternProperties": {
"^[A-Z0-9_]+$": {
"type": "object",
"properties": {
"resource_provider_generation": {
"type": "integer"
},
"total": {
"type": "integer",
"minimum": 1,
},
"reserved": {
"type": "integer",
"minimum": 0,
},
"min_unit": {
"type": "integer",
"minimum": 1,
},
"max_unit": {
"type": "integer",
"minimum": 1,
},
"step_size": {
"type": "integer",
"minimum": 1,
},
"allocation_ratio": {
"type": "number"
},
},
"required": ["total"],
"additionalProperties": False,
}
},
},
},
"required": [
"resource_provider_generation",
"inventories",
],
"additionalProperties": False,
}
},
"minProperties": 1,
"additionalProperties": False,
},
"allocations": {
"type": "object",
"description": "A dictionary of multiple allocations, keyed by consumer uuid. Each collection of allocations describes the full set of allocations for each consumer. Each consumer allocations dict is itself a dictionary of resource allocations keyed by resource provider uuid. An empty dictionary indicates no change in existing allocations, whereas an empty allocations dictionary within a consumer dictionary indicates that all allocations for that consumer should be deleted.",
"minProperties": 0,
"additionalProperties": False,
"patternProperties": {
"^[0-9a-fA-F-]{36}$": {
"type": "object",
"properties": {
"allocations": {
"type": "object",
"description": "A dictionary of resource allocations keyed by resource provider uuid. If this is an empty object, allocations for this consumer will be removed.",
"minProperties": 0,
"patternProperties": {
"^[0-9a-fA-F-]{36}$": {
"type": "object",
"properties": {
"generation": {
"type": "integer"
},
"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,
},
"project_id": {
"type": "string",
"description": "The uuid of a project.",
"minLength": 1,
"maxLength": 255,
},
"user_id": {
"type": "string",
"description": "The uuid of a user.",
"minLength": 1,
"maxLength": 255,
},
"consumer_generation": {
"type": ["integer", "null"],
"description": "The generation of the consumer. Should be set to null when indicating that the caller expects the consumer does not yet exist.",
},
"mappings": {
"type": "object",
"description": "A dictionary associating request group suffixes with a list of uuids identifying the resource providers that satisfied each group. The empty string and [a-zA-Z0-9_-]+ are valid suffixes. This field may be sent when writing allocations back to the server but will be ignored; this preserves symmetry between read and write representations.",
"minProperties": 1,
"patternProperties": {
"[a-zA-Z0-9_-]{1,64}": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"format": "uuid",
},
}
},
},
},
"additionalProperties": False,
"required": [
"allocations",
"project_id",
"user_id",
"consumer_generation",
],
}
},
},
},
"required": ["inventories", "allocations"],
"additionalProperties": False,
"x-openstack": {"min-ver": "1.34", "max-ver": "1.37"},
},
{
"type": "object",
"properties": {
"inventories": {
"type": "object",
"description": "A dictionary of multiple inventories, keyed by resource provider uuid. Each inventory describes the desired full inventory for each resource provider. An empty dictionary causes the inventory for that provider to be deleted.",
"patternProperties": {
"^[0-9a-fA-F-]{36}$": {
"type": "object",
"properties": {
"resource_provider_generation": {
"type": "integer",
"description": "A consistent view marker that assists with the management of concurrent resource provider updates.",
},
"inventories": {
"type": "object",
"description": "A dictionary of inventories keyed by resource classes.",
"patternProperties": {
"^[A-Z0-9_]+$": {
"type": "object",
"properties": {
"resource_provider_generation": {
"type": "integer"
},
"total": {
"type": "integer",
"minimum": 1,
},
"reserved": {
"type": "integer",
"minimum": 0,
},
"min_unit": {
"type": "integer",
"minimum": 1,
},
"max_unit": {
"type": "integer",
"minimum": 1,
},
"step_size": {
"type": "integer",
"minimum": 1,
},
"allocation_ratio": {
"type": "number"
},
},
"required": ["total"],
"additionalProperties": False,
}
},
},
},
"required": [
"resource_provider_generation",
"inventories",
],
"additionalProperties": False,
}
},
"minProperties": 1,
"additionalProperties": False,
},
"allocations": {
"type": "object",
"description": "A dictionary of multiple allocations, keyed by consumer uuid. Each collection of allocations describes the full set of allocations for each consumer. Each consumer allocations dict is itself a dictionary of resource allocations keyed by resource provider uuid. An empty dictionary indicates no change in existing allocations, whereas an empty allocations dictionary within a consumer dictionary indicates that all allocations for that consumer should be deleted.",
"minProperties": 0,
"additionalProperties": False,
"patternProperties": {
"^[0-9a-fA-F-]{36}$": {
"type": "object",
"properties": {
"allocations": {
"type": "object",
"description": "A dictionary of resource allocations keyed by resource provider uuid. If this is an empty object, allocations for this consumer will be removed.",
"minProperties": 0,
"patternProperties": {
"^[0-9a-fA-F-]{36}$": {
"type": "object",
"properties": {
"generation": {
"type": "integer"
},
"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,
},
"project_id": {
"type": "string",
"description": "The uuid of a project.",
"minLength": 1,
"maxLength": 255,
},
"user_id": {
"type": "string",
"description": "The uuid of a user.",
"minLength": 1,
"maxLength": 255,
},
"consumer_generation": {
"type": ["integer", "null"],
"description": "The generation of the consumer. Should be set to null when indicating that the caller expects the consumer does not yet exist.",
},
"mappings": {
"type": "object",
"description": "A dictionary associating request group suffixes with a list of uuids identifying the resource providers that satisfied each group. The empty string and [a-zA-Z0-9_-]+ are valid suffixes. This field may be sent when writing allocations back to the server but will be ignored; this preserves symmetry between read and write representations.",
"minProperties": 1,
"patternProperties": {
"[a-zA-Z0-9_-]{1,64}": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"format": "uuid",
},
}
},
},
"consumer_type": {
"type": "string",
"description": "A string that consists of numbers, A-Z, and _ describing what kind of consumer is creating, or has created, allocations using a quantity of inventory. The string is determined by the client when writing allocations and it is up to the client to ensure correct choices amongst collaborating services. For example, the compute service may choose to type some consumers ‘INSTANCE’ and others ‘MIGRATION’.",
"pattern": "^[A-Z0-9_]+$",
"minLength": 1,
"maxLength": 255,
},
},
"additionalProperties": False,
"required": [
"allocations",
"project_id",
"user_id",
"consumer_generation",
"consumer_type",
],
}
},
},
},
"required": ["inventories", "allocations"],
"additionalProperties": False,
"x-openstack": {"min-ver": "1.38"},
},
],
"x-openstack": {"discriminator": "microversion"},
}
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 == "ReshaperReshapeRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**RESHAPER_POST_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "ReshaperReshapeResponse":
# Reshaper Create response has no body
return (None, None, True)
else:
return (None, None, False)
return (ref, mime_type, True)
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.