Esempio n. 1
0
def find_valid_resource_agent_by_name(
    report_processor, runner, name, allowed_absent=False
):
    if ":" not in name:
        agent = guess_exactly_one_resource_agent_full_name(runner, name)
        report_processor.process(
            reports.agent_name_guessed(name, agent.get_name())
        )
        return agent

    try:
        return ResourceAgent(runner, name).validate_metadata()
    except InvalidResourceAgentName as e:
        raise LibraryError(resource_agent_error_to_report_item(e))
    except UnableToGetAgentMetadata as e:
        if not allowed_absent:
            raise LibraryError(resource_agent_error_to_report_item(e))

        report_processor.process(resource_agent_error_to_report_item(
            e,
            severity=ReportItemSeverity.WARNING,
            forceable=True
        ))

        return AbsentResourceAgent(runner, name)
Esempio n. 2
0
def find_valid_resource_agent_by_name(
    report_processor, runner, name,
    allowed_absent=False, absent_agent_supported=True
):
    """
    Return instance of ResourceAgent corresponding to name

    report_processor is tool for warning/info/error reporting
    runner is tool for launching external commands
    string name specifies a searched agent
    bool absent_agent_supported flag decides if is possible to allow to return
        absent agent: if is produced forceable/no-forcable error
    """
    if ":" not in name:
        agent = guess_exactly_one_resource_agent_full_name(runner, name)
        report_processor.process(
            reports.agent_name_guessed(name, agent.get_name())
        )
        return agent

    return _find_valid_agent_by_name(
        report_processor,
        runner,
        name,
        ResourceAgent,
        AbsentResourceAgent if allowed_absent else None,
        absent_agent_supported=absent_agent_supported,
    )
Esempio n. 3
0
def find_valid_resource_agent_by_name(
    report_processor, runner, name,
    allowed_absent=False, absent_agent_supported=True
):
    """
    Return instance of ResourceAgent corresponding to name

    report_processor is tool for warning/info/error reporting
    runner is tool for launching external commands
    string name specifies a searched agent
    bool absent_agent_supported flag decides if is possible to allow to return
        absent agent: if is produced forceable/no-forcable error
    """
    if ":" not in name:
        agent = guess_exactly_one_resource_agent_full_name(runner, name)
        report_processor.process(
            reports.agent_name_guessed(name, agent.get_name())
        )
        return agent

    return _find_valid_agent_by_name(
        report_processor,
        runner,
        name,
        ResourceAgent,
        AbsentResourceAgent if allowed_absent else None,
        absent_agent_supported=absent_agent_supported,
    )
Esempio n. 4
0
def find_valid_resource_agent_by_name(report_processor, runner, name, allowed_absent=False):
    if ":" not in name:
        agent = guess_exactly_one_resource_agent_full_name(runner, name)
        report_processor.process(reports.agent_name_guessed(name, agent.get_name()))
        return agent

    try:
        return ResourceAgent(runner, name).validate_metadata()
    except InvalidResourceAgentName as e:
        raise LibraryError(resource_agent_error_to_report_item(e))
    except UnableToGetAgentMetadata as e:
        if not allowed_absent:
            raise LibraryError(resource_agent_error_to_report_item(e))

        report_processor.process(
            resource_agent_error_to_report_item(e, severity=ReportItemSeverity.WARNING, forceable=True)
        )

        return AbsentResourceAgent(runner, name)