Handling metadata in single module becomes not manageable. Split it into separate service-related modules. Change-Id: I7551b4a96cf030c57bfb0a7b9eb868cd760a6de5
70 lines
2.4 KiB
Python
70 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
|
|
path_elements: list[str] = path.split("/")
|
|
|
|
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
|
|
):
|
|
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.replace("delete-all", "purge")
|
|
|
|
return operation
|