Ejemplo n.º 1
0
def _agent_metadata_to_dict(
    agent: ResourceAgentMetadata, describe: bool = False
) -> Dict[str, str]:
    agent_dto = agent.to_dto()
    agent_dict = to_dict(agent_dto)
    del agent_dict["name"]
    agent_dict["name"] = agent.name.full_name
    agent_dict["standard"] = agent.name.standard
    agent_dict["provider"] = agent.name.provider
    agent_dict["type"] = agent.name.type

    agent_dict["actions"] = [
        _action_to_operation(action) for action in agent_dto.actions
    ]
    operations_defaults = {
        "OCF_CHECK_LEVEL": None,
        "automatic": False,
        "on_target": False,
    }
    agent_dict["default_actions"] = (
        [
            operation_dto_to_legacy_dict(op, operations_defaults)
            for op in get_default_operations(agent)
        ]
        if describe
        else []
    )
    return agent_dict
Ejemplo n.º 2
0
def prepare(
    report_processor: ReportProcessor,
    raw_operation_list: Iterable[ResourceOperationFilteredIn],
    default_operation_list: Iterable[CibResourceOperationDto],
    allowed_operation_name_list: Iterable[str],
    new_role_names_supported: bool,
    allow_invalid: bool = False,
) -> List[ResourceOperationFilteredOut]:
    """
    Return operation_list prepared from raw_operation_list and
    default_operation_list.

    report_processor -- tool for warning/info/error reporting
    raw_operation_list -- user entered operations that require follow-up care
    default_operation_list -- operations defined as default by (most probably)
        a resource agent
    allowed_operation_name_list -- operation names defined by a resource agent
    allow_invalid -- flag for validation skipping
    """
    operations_to_validate = _operations_to_normalized(raw_operation_list)

    report_list: ReportItemList = []
    report_list.extend(
        _validate_operation_list(operations_to_validate,
                                 allowed_operation_name_list, allow_invalid))

    operation_list = _normalized_to_operations(operations_to_validate,
                                               new_role_names_supported)

    report_list.extend(validate_different_intervals(operation_list))

    if report_processor.report_list(report_list).has_errors:
        raise LibraryError()

    report_list, remaining_default_operations = uniquify_operations_intervals(
        _get_remaining_defaults(
            operation_list,
            default_operation_list,
        ))
    if report_processor.report_list(report_list).has_errors:
        raise LibraryError()

    return [
        _filter_op_dict(op, new_role_names_supported)
        for op in complete_operations_options(operation_list) + [
            operation_dto_to_legacy_dict(op, {})
            for op in remaining_default_operations
        ]
    ]