
- keypair create response does not contain ID - server create response has a response_key (server). This is not really true, since creation may return reservation_id, but this is not typical and we can try to find a solution for that later. For now make sure cli server creation works. Change-Id: I3f52f0e6686767dcc8862543c4c3a155f42ead0e
231 lines
9.9 KiB
Python
231 lines
9.9 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.types import OperationTargetParams
|
|
from codegenerator.metadata.base import MetadataBase
|
|
|
|
|
|
class ComputeMetadata(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 == "flavor/flavor_access" and method == "get":
|
|
operation_key = "list"
|
|
elif resource_name == "aggregate/image" and method == "post":
|
|
operation_key = "action"
|
|
elif resource_name == "server/security_group" and method == "get":
|
|
operation_key = "list"
|
|
elif resource_name == "server/topology" and method == "get":
|
|
operation_key = "list"
|
|
elif resource_name == "quota_set" and path.endswith("defaults"):
|
|
operation_key = "defaults"
|
|
elif resource_name == "quota_set" and path.endswith("detail"):
|
|
# normalize "details" name
|
|
operation_key = "details"
|
|
|
|
elif resource_name == "limit" and method == "get":
|
|
operation_key = "list"
|
|
|
|
return (operation_key, skip)
|
|
|
|
@staticmethod
|
|
def post_process_operation(
|
|
resource_name: str, operation_name: str, operation
|
|
):
|
|
if resource_name == "aggregate":
|
|
if operation_name in ["set-metadata", "add-host", "remove-host"]:
|
|
operation.targets["rust-sdk"].response_key = "aggregate"
|
|
operation.targets["rust-cli"].response_key = "aggregate"
|
|
elif resource_name == "availability_zone":
|
|
if operation_name == "get":
|
|
operation.operation_type = "list"
|
|
operation.targets["rust-sdk"].operation_name = "list"
|
|
operation.targets[
|
|
"rust-sdk"
|
|
].response_key = "availabilityZoneInfo"
|
|
operation.targets["rust-sdk"].module_name = "list"
|
|
operation.targets[
|
|
"rust-cli"
|
|
].response_key = "availabilityZoneInfo"
|
|
operation.targets["rust-cli"].module_name = "list"
|
|
operation.targets["rust-cli"].sdk_mod_name = "list"
|
|
operation.targets["rust-cli"].operation_name = "list"
|
|
operation.targets[
|
|
"rust-sdk"
|
|
].response_key = "availabilityZoneInfo"
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = "availability-zone list"
|
|
elif operation_name == "list_detailed":
|
|
operation.operation_type = "list"
|
|
operation.targets["rust-sdk"].operation_name = "list_detail"
|
|
operation.targets[
|
|
"rust-sdk"
|
|
].response_key = "availabilityZoneInfo"
|
|
operation.targets["rust-sdk"].module_name = "list_detail"
|
|
operation.targets[
|
|
"rust-cli"
|
|
].response_key = "availabilityZoneInfo"
|
|
operation.targets["rust-cli"].operation_name = "list"
|
|
operation.targets["rust-cli"].module_name = "list_detail"
|
|
operation.targets["rust-cli"].sdk_mod_name = "list_detail"
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = "availability-zone list-detail"
|
|
|
|
elif resource_name == "keypair":
|
|
if operation_name == "list":
|
|
operation.targets[
|
|
"rust-sdk"
|
|
].response_list_item_key = "keypair"
|
|
|
|
elif resource_name == "server":
|
|
if "create" in operation_name:
|
|
operation.targets["rust-sdk"].response_key = "server"
|
|
operation.targets["rust-cli"].response_key = "server"
|
|
elif "migrate-live" in operation_name:
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("migrate-live", "live-migrate")
|
|
elif resource_name == "server/instance_action":
|
|
if operation_name == "list":
|
|
operation.targets["rust-sdk"].response_key = "instanceActions"
|
|
operation.targets["rust-cli"].response_key = "instanceActions"
|
|
else:
|
|
operation.targets["rust-sdk"].response_key = "instanceAction"
|
|
operation.targets["rust-cli"].response_key = "instanceAction"
|
|
elif resource_name == "server/topology":
|
|
if operation_name == "list":
|
|
operation.targets["rust-sdk"].response_key = "nodes"
|
|
operation.targets["rust-cli"].response_key = "nodes"
|
|
elif resource_name == "server/volume_attachment":
|
|
if operation_name == "list":
|
|
operation.targets[
|
|
"rust-sdk"
|
|
].response_key = "volumeAttachments"
|
|
operation.targets[
|
|
"rust-cli"
|
|
].response_key = "volumeAttachments"
|
|
elif operation_name in ["create", "show", "update"]:
|
|
operation.targets["rust-sdk"].response_key = "volumeAttachment"
|
|
operation.targets["rust-cli"].response_key = "volumeAttachment"
|
|
elif resource_name == "server/server_password":
|
|
operation.targets["rust-cli"].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("server-password", "password")
|
|
operation.targets["rust-cli"].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("get", "show")
|
|
elif resource_name == "server/security_group":
|
|
operation.targets["rust-cli"].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace(
|
|
"security-group list", "security-groups"
|
|
)
|
|
if operation_name == "get":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("get", "show")
|
|
|
|
elif resource_name == "flavor":
|
|
if operation_name == "add-tenant-access":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("add-tenant-access", "access add")
|
|
elif operation_name == "list-tenant-access":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("list-tenant-access", "access list")
|
|
elif operation_name == "remove-tenant-access":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace(
|
|
"remove-tenant-access", "access remove"
|
|
)
|
|
|
|
if resource_name == "limit":
|
|
# Limits API return object and not a list
|
|
operation.targets["rust-cli"].operation_type = "show"
|
|
operation.targets["rust-cli"].response_key = "limits"
|
|
operation.targets["rust-sdk"].response_key = "limits"
|
|
|
|
if "/tag" in resource_name:
|
|
if operation_name == "update":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("set", "add")
|
|
elif operation_name == "show":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("show", "check")
|
|
|
|
if operation_name == "delete_all":
|
|
operation.targets["rust-cli"].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("delete-all", "purge")
|
|
|
|
if (
|
|
(
|
|
resource_name in ["aggregate", "server/instance_action"]
|
|
and operation_name in ["list", "delete", "show"]
|
|
)
|
|
or (
|
|
resource_name == "server"
|
|
and operation_name
|
|
in ["list_detailed", "delete", "show", "os-get-console-output"]
|
|
)
|
|
or (
|
|
resource_name in ["flavor", "hypervisor"]
|
|
and operation_name in ["list_detailed", "show"]
|
|
)
|
|
or (resource_name == "quota_set" and operation_name == "details")
|
|
):
|
|
op = operation.targets.setdefault(
|
|
"rust-tui",
|
|
OperationTargetParams(
|
|
module_name=operation.targets["rust-sdk"].module_name
|
|
),
|
|
)
|
|
if operation_name == "os-get-console-output":
|
|
op.module_name = operation.targets[
|
|
"rust-sdk"
|
|
].module_name.replace("os_", "")
|
|
op.sdk_mod_name = operation.targets["rust-sdk"].module_name
|
|
op.operation_name = operation.targets[
|
|
"rust-sdk"
|
|
].operation_name
|
|
|
|
return operation
|