Module core.default.commands.utils

Expand source code
from dataclasses import dataclass, field
from typing import Dict, List, Tuple

from core.constructs.resource import ResourceModel
from core.constructs.workspace import Workspace
from core.utils.exceptions import cdev_core_error


###############################
##### Exceptions
###############################


@dataclass
class ResourceNameError(cdev_core_error):
    help_message: str = (
        "   Resource should be identified by <comp_name>.<resource_name>"
    )
    help_resources: List[str] = field(default_factory=lambda: [])


###############################
##### API
###############################


def get_cloud_output_from_cdev_name(
    component_name: str, ruuid: str, cdev_name: str
) -> Dict:
    ws = Workspace.instance()

    cloud_output = ws.get_backend().get_cloud_output_by_name(
        ws.get_resource_state_uuid(), component_name, ruuid, cdev_name
    )

    return cloud_output


def get_resource_from_cdev_name(
    component_name: str, ruuid: str, cdev_name: str
) -> ResourceModel:
    ws = Workspace.instance()

    resource = ws.get_backend().get_resource_by_name(
        ws.get_resource_state_uuid(), component_name, ruuid, cdev_name
    )

    return resource


def get_component_and_resource_from_qualified_name(full_name: str) -> Tuple[str, str]:
    component_and_function = full_name.split(".")

    if len(component_and_function) != 2:
        raise ResourceNameError(
            error_message=f"'{full_name}' is not properly structured as resource identifier"
        )

    component_name = component_and_function[0]
    resource_name = component_and_function[1]

    return component_name, resource_name

Functions

def get_cloud_output_from_cdev_name(component_name: str, ruuid: str, cdev_name: str) ‑> Dict[~KT, ~VT]
Expand source code
def get_cloud_output_from_cdev_name(
    component_name: str, ruuid: str, cdev_name: str
) -> Dict:
    ws = Workspace.instance()

    cloud_output = ws.get_backend().get_cloud_output_by_name(
        ws.get_resource_state_uuid(), component_name, ruuid, cdev_name
    )

    return cloud_output
def get_component_and_resource_from_qualified_name(full_name: str) ‑> Tuple[str, str]
Expand source code
def get_component_and_resource_from_qualified_name(full_name: str) -> Tuple[str, str]:
    component_and_function = full_name.split(".")

    if len(component_and_function) != 2:
        raise ResourceNameError(
            error_message=f"'{full_name}' is not properly structured as resource identifier"
        )

    component_name = component_and_function[0]
    resource_name = component_and_function[1]

    return component_name, resource_name
def get_resource_from_cdev_name(component_name: str, ruuid: str, cdev_name: str) ‑> ResourceModel
Expand source code
def get_resource_from_cdev_name(
    component_name: str, ruuid: str, cdev_name: str
) -> ResourceModel:
    ws = Workspace.instance()

    resource = ws.get_backend().get_resource_by_name(
        ws.get_resource_state_uuid(), component_name, ruuid, cdev_name
    )

    return resource

Classes

class ResourceNameError (error_message: str, help_message: str = ' Resource should be identified by <comp_name>.<resource_name>', help_resources: List[str] = <factory>)

ResourceNameError(error_message: str, help_message: str = ' Resource should be identified by .', help_resources: List[str] = )

Expand source code
class ResourceNameError(cdev_core_error):
    help_message: str = (
        "   Resource should be identified by <comp_name>.<resource_name>"
    )
    help_resources: List[str] = field(default_factory=lambda: [])

Ancestors

Class variables

var help_message : str
var help_resources : List[str]