Пример #1
0
    def cic_install(self, log, parallelism=10):
        """
        Install RPMs, PIP libs and send config files
        :param send_fpath_dict: key is the fpath on localhost, value is the
        fpath on remote host.
        """
        # pylint: disable=too-many-locals
        # Prepare the local repo config file
        local_host = self.cic_local_host
        command = ("mkdir -p %s" % (self.cic_workspace))
        retval = local_host.sh_run(log, command)
        if retval.cr_exit_status:
            log.cl_error(
                "failed to run command [%s] on host [%s], "
                "ret = [%d], stdout = [%s], stderr = [%s]", command,
                local_host.sh_hostname, retval.cr_exit_status,
                retval.cr_stdout, retval.cr_stderr)
            return -1

        packages_dir = self.cic_iso_dir + "/" + constant.BUILD_PACKAGES
        generate_repo_file(self.cic_repo_config_fpath, packages_dir, "Coral")

        args_array = []
        thread_ids = []
        hosts = []
        for installation_host in self.cic_installation_hosts:
            args = (installation_host, self.cic_repo_config_fpath)
            args_array.append(args)
            thread_id = "host_install_%s" % installation_host.cih_host.sh_hostname
            thread_ids.append(thread_id)
            hosts.append(installation_host.cih_host)

        ret = ssh_host.check_clocks_diff(log, hosts, max_diff=60)
        if ret:
            log.cl_error("too much clock difference between hosts")
            return -1

        parallel_execute = parallel.ParallelExecute(log,
                                                    self.cic_workspace,
                                                    "install",
                                                    cluster_host_install,
                                                    args_array,
                                                    thread_ids=thread_ids,
                                                    parallelism=parallelism)
        ret = parallel_execute.pe_run()
        if ret:
            log.cl_error("failed to install hosts in parallel")
            return -1
        return 0
Пример #2
0
def print_servers(log,
                  barreleye_instance,
                  servers,
                  status=False,
                  print_table=True,
                  field_string=None):
    """
    Print table of BarreleServer.
    """
    # pylint: disable=too-many-branches,too-many-locals,too-many-statements
    if not print_table and len(servers) > 1:
        log.cl_error("failed to print non-table output with multiple "
                     "servers")
        return -1

    quick_fields = [barrele_constant.BARRELE_FIELD_HOST]
    slow_fields = [
        barrele_constant.BARRELE_FIELD_UP,
        barrele_constant.BARRELE_FIELD_INFLUXDB,
        barrele_constant.BARRELE_FIELD_GRAFANA
    ]
    none_table_fields = [
        barrele_constant.BARRELE_FIELD_INFLUXDB_VERSION,
        barrele_constant.BARRELE_FIELD_GRAFANA_VERSION
    ]
    table_fields = quick_fields + slow_fields
    all_fields = table_fields + none_table_fields

    if isinstance(field_string, bool):
        cmd_general.print_all_fields(log, all_fields)
        return 0

    field_names = cmd_general.parse_field_string(log,
                                                 field_string,
                                                 quick_fields,
                                                 table_fields,
                                                 all_fields,
                                                 print_status=status,
                                                 print_table=print_table)
    if field_names is None:
        log.cl_error("invalid field string [%s] for server", field_string)
        return -1

    server_status_list = []
    for server in servers:
        server_status = BarreleServerStatusCache(barreleye_instance, server)
        server_status_list.append(server_status)

    if (len(server_status_list) > 0 and
            not server_status_list[0].bssc_can_skip_init_fields(field_names)):
        args_array = []
        thread_ids = []
        for server_status in server_status_list:
            args = (server_status, field_names)
            args_array.append(args)
            server = server_status.bssc_server
            hostname = server.bes_server_host.sh_hostname
            thread_id = "server_status_%s" % hostname
            thread_ids.append(thread_id)

        parallel_execute = parallel.ParallelExecute(
            log,
            barreleye_instance.bei_workspace,
            "server_status",
            server_status_init,
            args_array,
            thread_ids=thread_ids,
            parallelism=10)
        ret = parallel_execute.pe_run()
        if ret:
            log.cl_error("failed to init fields %s for servers", field_names)
            return -1

    rc = cmd_general.print_list(log,
                                server_status_list,
                                quick_fields,
                                slow_fields,
                                none_table_fields,
                                server_status_field,
                                print_table=print_table,
                                print_status=status,
                                field_string=field_string)
    return rc
Пример #3
0
def print_agents(log,
                 barreleye_instance,
                 agents,
                 status=False,
                 print_table=True,
                 field_string=None):
    """
    Print table of BarreleAgent.
    """
    # pylint: disable=too-many-branches,too-many-locals,too-many-statements
    if not print_table and len(agents) > 1:
        log.cl_error("failed to print non-table output with multiple "
                     "agents")
        return -1

    quick_fields = [barrele_constant.BARRELE_FIELD_HOST]
    slow_fields = [
        barrele_constant.BARRELE_FIELD_UP,
        barrele_constant.BARRELE_FIELD_COLLECTD,
        barrele_constant.BARRELE_FIELD_COLLECTD_VERSION
    ]
    none_table_fields = []
    table_fields = quick_fields + slow_fields
    all_fields = table_fields + none_table_fields

    if isinstance(field_string, bool):
        cmd_general.print_all_fields(log, all_fields)
        return 0

    field_names = cmd_general.parse_field_string(log,
                                                 field_string,
                                                 quick_fields,
                                                 table_fields,
                                                 all_fields,
                                                 print_status=status,
                                                 print_table=print_table)
    if field_names is None:
        log.cl_error("invalid field string [%s] for agent", field_string)
        return -1

    agent_status_list = []
    for agent in agents:
        agent_status = BarreleAgentStatusCache(barreleye_instance, agent)
        agent_status_list.append(agent_status)

    if (len(agent_status_list) > 0 and
            not agent_status_list[0].basc_can_skip_init_fields(field_names)):
        args_array = []
        thread_ids = []
        for agent_status in agent_status_list:
            args = (agent_status, field_names)
            args_array.append(args)
            agent = agent_status.basc_agent
            hostname = agent.bea_host.sh_hostname
            thread_id = "agent_status_%s" % hostname
            thread_ids.append(thread_id)

        parallel_execute = parallel.ParallelExecute(
            log,
            barreleye_instance.bei_workspace,
            "agent_status",
            agent_status_init,
            args_array,
            thread_ids=thread_ids,
            parallelism=10)
        ret = parallel_execute.pe_run()
        if ret:
            log.cl_error("failed to init fields %s for agents", field_names)
            return -1

    rc = cmd_general.print_list(log,
                                agent_status_list,
                                quick_fields,
                                slow_fields,
                                none_table_fields,
                                agent_status_field,
                                print_table=print_table,
                                print_status=status,
                                field_string=field_string)
    return rc