示例#1
0
def list_agents(lib_env, describe=True, search=None):
    """
    List all resource agents on the local host, optionally filtered and
        described
    bool describe load and return agents' description as well
    string search return only agents which name contains this string
    """
    runner = lib_env.cmd_runner()

    # list agents for all standards and providers
    agent_names = []
    for std in resource_agent.list_resource_agents_standards_and_providers(
        runner
    ):
        agent_names += [
            "{0}:{1}".format(std, agent)
            for agent in resource_agent.list_resource_agents(runner, std)
        ]
    agent_names.sort(
        # works with both str and unicode in both python 2 and 3
        key=lambda x: x.lower()
    )
    return _complete_agent_list(
        runner,
        agent_names,
        describe,
        search,
        resource_agent.ResourceAgent
    )
示例#2
0
def list_agents(
    lib_env: LibraryEnvironment,
    describe: bool = True,
    search: Optional[str] = None,
) -> List[Dict[str, Any]]:
    """
    List all resource agents on the local host, optionally filtered and
        described

    describe -- load and return agents' metadata as well
    search -- return only agents which name contains this string
    """
    runner = lib_env.cmd_runner()

    # list agents for all standards and providers
    agent_names = []
    for std_prov in list_resource_agents_standards_and_providers(runner):
        if std_prov.is_stonith:
            continue
        agent_names.extend(_get_agent_names(runner, std_prov))
    return _complete_agent_list(
        runner,
        lib_env.report_processor,
        sorted(agent_names, key=lambda item: item.full_name),
        describe,
        search,
    )
示例#3
0
def get_agents_list(lib_env: LibraryEnvironment) -> ListResourceAgentNameDto:
    """
    List all resource agents on the local host
    """
    runner = lib_env.cmd_runner()
    agent_names = []
    for std_prov in list_resource_agents_standards_and_providers(runner):
        agent_names.extend(_get_agent_names(runner, std_prov))
    return ListResourceAgentNameDto(names=[
        name.to_dto()
        for name in sorted(agent_names, key=lambda item: item.full_name)
    ])
示例#4
0
    def test_success(self):
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.side_effect = [
            (
                "\n".join([
                    "ocf",
                    "lsb",
                    "service",
                    "systemd",
                    "nagios",
                    "stonith",
                    "",
                ]),
                "",
                0
            ),
            (
                "\n".join([
                    "heartbeat",
                    "openstack",
                    "pacemaker",
                    "booth",
                    "",
                ]),
                "",
                0
            ),
        ]

        self.assertEqual(
            lib_ra.list_resource_agents_standards_and_providers(mock_runner),
            [
                "lsb",
                "nagios",
                "ocf:booth",
                "ocf:heartbeat",
                "ocf:openstack",
                "ocf:pacemaker",
                "service",
                "systemd",
            ]
        )

        self.assertEqual(2, len(mock_runner.run.mock_calls))
        mock_runner.run.assert_has_calls([
            mock.call(["/usr/sbin/crm_resource", "--list-standards"]),
            mock.call(["/usr/sbin/crm_resource", "--list-ocf-providers"]),
        ])
示例#5
0
def list_agents(lib_env, describe=True, search=None):
    """
    List all resource agents on the local host, optionally filtered and
        described
    bool describe load and return agents' description as well
    string search return only agents which name contains this string
    """
    runner = lib_env.cmd_runner()

    # list agents for all standards and providers
    agent_names = []
    for std in resource_agent.list_resource_agents_standards_and_providers(
            runner):
        agent_names += [
            "{0}:{1}".format(std, agent)
            for agent in resource_agent.list_resource_agents(runner, std)
        ]
    agent_names.sort(
        # works with both str and unicode in both python 2 and 3
        key=lambda x: x.lower())
    return _complete_agent_list(runner, agent_names, describe, search,
                                resource_agent.ResourceAgent)
示例#6
0
def list_agents_for_standard_and_provider(
        lib_env: LibraryEnvironment,
        standard_provider: Optional[str] = None) -> List[str]:
    """
    List resource agents for specified standard on the local host

    standard_provider -- standard[:provider], e.g. None, ocf, ocf:pacemaker
    """
    if standard_provider:
        if standard_provider[-1] == ":":
            standard_provider = standard_provider[:-1]
        std_prov_list = [
            StandardProviderTuple(*standard_provider.split(":", 1))
        ]
    else:
        std_prov_list = list_resource_agents_standards_and_providers(
            lib_env.cmd_runner())
    agents = []
    for std_prov in std_prov_list:
        if std_prov.is_stonith:
            continue
        agents += list_resource_agents(lib_env.cmd_runner(), std_prov)
    return sorted(agents, key=str.lower)