Files
codegenerator/codegenerator/metadata/placement.py
Artem Goncharov 721705d837 Rename operation_name with action_name in the metadata
Currently we comment the operation_name attribute in the metadata that
it is used as an action name. This only creates confusion especially if
we want to use something different as the operation_name (i.e.
operation_name or opertaion_type for neutron router results in
"action"). So in addition to the renaming of the metadata attribute
explicitly pass the metadata operation key as operation_name parameters
into the generator (when unset).

Change-Id: Ic04eafe5b6dea012ca18b9835cd5c86fefa87055
Signed-off-by: Artem Goncharov <artem.goncharov@gmail.com>
2025-06-05 15:02:09 +00:00

69 lines
2.4 KiB
Python

# 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 typing as ty
from codegenerator.types import OperationModel
from codegenerator.metadata.base import MetadataBase
class PlacementMetadata(MetadataBase):
@staticmethod
def get_operation_key(
operation, path: str, method: str, resource_name: str
) -> ty.Tuple[str | None, bool]:
skip: bool = False
operation_key: str | None = None
if (
resource_name
in [
"allocation_candidate",
"resource_provider/allocation",
"usage",
]
and method == "get"
):
operation_key = "list"
elif (
resource_name
in ["resource_provider/aggregate", "resource_provider/trait"]
and method == "put"
):
operation_key = "update"
return (operation_key, skip)
@staticmethod
def post_process_operation(
resource_name: str, operation_name: str, operation: OperationModel
):
if resource_name == "allocation_candidate":
if operation_name == "list":
operation.operation_type = "show"
elif resource_name == "resource_provider/aggregate":
if operation_name == "list":
operation.operation_type = "show"
elif resource_name == "resource_provider/allocation":
if operation_name == "list":
operation.operation_type = "show"
elif resource_name == "resource_provider/trait":
if operation_name == "list":
operation.operation_type = "show"
if operation_name == "delete_all":
operation.targets["rust-cli"].cli_full_command = (
operation.targets["rust-cli"].cli_full_command or "purge"
).replace("delete-all", "purge")
return operation