示例#1
0
    def update(self, add_version=False, add_major=False, add_minor=False,
               new_extra=None):
        """
        Update the revision.

        The current directory should be git repository of Coral.

        :param add_version: Increase the version number. Default: False.
        :param add_major: Increase the major number. Default: False.
        :param add_minor: Increase the minor number. Default: True.
        :param new_extra: Change extra part of reviesion. Default: None. To
            remove the existing extra field, specify --new-extra "".
        :param update_license_key: Update the license key. If it is desired
            to the licenses of old versions, please specify this option.
        """
        # pylint: disable=no-self-use
        source_dir = os.getcwd()
        log, workspace = cmd_general.init_env_noconfig(source_dir,
                                                       self._cvc_log_to_file,
                                                       True)
        cmd_general.check_argument_bool(log, "add_version", add_version)
        cmd_general.check_argument_bool(log, "add_major", add_major)
        cmd_general.check_argument_bool(log, "add_minor", add_minor)
        if new_extra is not None:
            new_extra = cmd_general.check_argument_str(log, "new_extra",
                                                       new_extra)
            if "-" in new_extra:
                log.cl_error("character [-] is not allowed in extra field [%s]",
                             new_extra)
                cmd_general.cmd_exit(log, -1)
        rc = _update_version(log, workspace, source_dir,
                             add_version=add_version,
                             add_major=add_major, add_minor=add_minor,
                             new_extra=new_extra)
        cmd_general.cmd_exit(log, rc)
示例#2
0
 def urls(self):
     """
     Print the URLs to download dependency packages.
     """
     # pylint: disable=no-self-use
     log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True)
     for package, url in PACAKGE_URL_DICT.items():
         log.cl_stdout("%s: %s", package, url)
     cmd_general.cmd_exit(log, 0)
示例#3
0
 def check(self):
     """
     check whether the documents.
     """
     # pylint: disable=no-self-use
     log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True)
     doc_dir = os.getcwd() + "/doc"
     rc = check_doc(log, doc_dir)
     cmd_general.cmd_exit(log, rc)
示例#4
0
 def host(self):
     """
     Print the hostname of the Barreleye server.
     """
     log, barreleye_instance = init_env(self._bsc_config_fpath,
                                        self._bsc_logdir,
                                        self._bsc_log_to_file)
     server = barreleye_instance.bei_barreleye_server
     log.cl_stdout(server.bes_server_host.sh_hostname)
     cmd_general.cmd_exit(log, 0)
示例#5
0
 def ls(self, status=False):
     """
     List all Barreleye agents.
     :param status: print the status of agents, default: False.
     """
     log, barreleye_instance = init_env(self._bac_config_fpath,
                                        self._bac_logdir,
                                        self._bac_log_to_file)
     cmd_general.check_argument_bool(log, "status", status)
     agents = list(barreleye_instance.bei_agent_dict.values())
     ret = print_agents(log, barreleye_instance, agents, status=status)
     cmd_general.cmd_exit(log, ret)
示例#6
0
def barrele_version(barrele_command):
    """
    Print Barreleye version on local host and exit.
    """
    # pylint: disable=unused-argument,protected-access
    logdir = barrele_command._bec_logdir
    log_to_file = barrele_command._bec_log_to_file
    logdir_is_default = (logdir == barrele_constant.BARRELE_LOG_DIR)
    log, _ = cmd_general.init_env_noconfig(logdir, log_to_file,
                                           logdir_is_default)
    log.cl_stdout(version.CORAL_VERSION)
    cmd_general.cmd_exit(log, 0)
示例#7
0
def init_env(config_fpath, logdir, log_to_file, iso):
    """
    Init log and instance for commands that needs it
    """
    log_dir_is_default = (logdir == barrele_constant.BARRELE_LOG_DIR)
    log, workspace, barrele_config = cmd_general.init_env(
        config_fpath, logdir, log_to_file, log_dir_is_default)
    barreleye_instance = barrele_instance.barrele_init_instance(
        log, workspace, barrele_config, config_fpath, log_to_file,
        log_dir_is_default, iso)
    if barreleye_instance is None:
        log.cl_error("failed to init Barreleye instance")
        cmd_general.cmd_exit(log, 1)
    return log, barreleye_instance
示例#8
0
    def show(self):
        """
        Print version to stdout.

        All '-' will be replaced to "_" to make RPM naming happy.
        """
        # pylint: disable=no-self-use
        log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True)
        source_dir = os.getcwd()
        version_string = coral_get_version_string(log, source_dir)
        if version_string is None:
            cmd_general.cmd_exit(log, -1)
        sys.stdout.write(coral_uniformed_version(version_string))
        cmd_general.cmd_exit(log, 0)
示例#9
0
def barrele_version(barrele_command):
    """
    Print Barreleye version on local host and exit.
    """
    # pylint: disable=unused-argument,protected-access
    logdir = barrele_command._bec_logdir
    log_to_file = barrele_command._bec_log_to_file
    simple = True
    if simple:
        logdir_is_default = (logdir == barrele_constant.BARRELE_LOG_DIR)
        log, _ = cmd_general.init_env_noconfig(logdir, log_to_file,
                                               logdir_is_default)
        cmd_general.print_field(log, constant.TITLE_CURRENT_RELEASE,
                                version.CORAL_VERSION)
        cmd_general.cmd_exit(log, 0)
示例#10
0
 def status(self):
     """
     Print the status of the Barreleye server.
     """
     log, barreleye_instance = init_env(self._bsc_config_fpath,
                                        self._bsc_logdir,
                                        self._bsc_log_to_file)
     server = barreleye_instance.bei_barreleye_server
     servers = [server]
     ret = print_servers(log,
                         barreleye_instance,
                         servers,
                         status=True,
                         print_table=False)
     cmd_general.cmd_exit(log, ret)
示例#11
0
    def stop(self, host):
        """
        Stop Collectd service on the agent host.
        :param host: the name of the agent host. Could be a list.
        """
        log, barreleye_instance = init_env(self._bac_config_fpath,
                                           self._bac_logdir,
                                           self._bac_log_to_file)
        host = cmd_general.check_argument_str(log, "host", host)

        hostnames = cmd_general.parse_list_string(log, host)
        if hostnames is None:
            log.cl_error("host list [%s] is invalid", host)
            cmd_general.cmd_exit(log, -1)
        ret = barreleye_instance.bei_stop_agents(log, hostnames)
        cmd_general.cmd_exit(log, ret)
示例#12
0
    def install(self, erase_influxdb=False, drop_database=False):
        """
        Install the Barreleye packages in the whole cluster.

        All Barreleye RPMs, configuration files will be cleaned up and
        re-configured.
        :param erase_influxdb: Whether to erase all data and metadata of
        the existing Influxdb.
        :param drop_database: Whether to drop the old Influxdb data. This
        will remove all existing data in "barreleye_database" in Influxdb,
        but will not touch other databases if any.
        """
        log, barreleye_instance = init_env(self._bcc_config_fpath,
                                           self._bcc_logdir,
                                           self._bcc_log_to_file,
                                           self._bcc_iso)
        cmd_general.check_argument_bool(log, "erase_influxdb", erase_influxdb)
        cmd_general.check_argument_bool(log, "drop_database", drop_database)
        rc = barreleye_instance.bei_cluster_install(
            log, erase_influxdb=erase_influxdb, drop_database=drop_database)
        cmd_general.cmd_exit(log, rc)
示例#13
0
 def status(self, host):
     """
     Print the status of a agent host.
     :param host: the name of the agent host.
     """
     log, barreleye_instance = init_env(self._bac_config_fpath,
                                        self._bac_logdir,
                                        self._bac_log_to_file)
     host = cmd_general.check_argument_str(log, "host", host)
     if host not in barreleye_instance.bei_agent_dict:
         log.cl_error("host [%s] is not configured as Barreleye agent",
                      host)
         cmd_general.cmd_exit(log, -1)
     agent = barreleye_instance.bei_agent_dict[host]
     agents = [agent]
     ret = print_agents(log,
                        barreleye_instance,
                        agents,
                        status=True,
                        print_table=False)
     cmd_general.cmd_exit(log, ret)
示例#14
0
    def save(self, path):
        """
        Save the version to dest .py file. This is a command for internal
        build process.

        :param path: the python file to save the version.
        """
        # pylint: disable=no-self-use,unused-argument
        log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True)
        local_host = ssh_host.get_local_host(ssh=False)
        source_dir = os.path.dirname(os.path.dirname(__file__))
        version_string = coral_get_version_string(log, source_dir)
        if version_string is None:
            cmd_general.cmd_exit(log, -1)
        version_string = coral_uniformed_version(version_string)
        version_data = '"""'
        version_data += """
Please DO NOT edit this file directly!
This file is generated by "coral" command.
"""
        version_data += '"""'
        version_data += "\n"
        version_data += "CORAL_VERSION = \"%s\"\n" % (version_string)

        try:
            with open(path, 'w') as version_file:
                version_file.write(version_data)
        except:
            log.cl_error("failed to write version to file [%s] on host [%s]: %s",
                         path, local_host.sh_hostname,
                         traceback.format_exc())
            cmd_general.cmd_exit(log, -1)
        cmd_general.cmd_exit(log, 0)
示例#15
0
def barrele_lustre_versions(barrele_command):
    """
    Print Lustres versions supported by Barreleye.

    The Lustre version name can be used in "lustre_fallback_version" of
    /etc/coral/barreleye.conf.
    """
    # pylint: disable=unused-argument,protected-access
    logdir = barrele_command._bec_logdir
    log_to_file = barrele_command._bec_log_to_file
    logdir_is_default = (logdir == barrele_constant.BARRELE_LOG_DIR)
    log, _ = cmd_general.init_env_noconfig(logdir, log_to_file,
                                           logdir_is_default)
    lustre_versions = []
    for lversion in lustre_version.LUSTRE_VERSION_DICT.values():
        fname = barrele_collectd.lustre_version_xml_fname(log,
                                                          lversion,
                                                          quiet=True)
        if fname is None:
            continue
        lustre_versions.append(lversion)
    ret = print_lustre_versions(log, lustre_versions)
    cmd_general.cmd_exit(log, ret)
示例#16
0
def build(coral_command,
          cache=constant.CORAL_BUILD_CACHE,
          lustre=None,
          e2fsprogs=None,
          collectd=None,
          enable_zfs=False,
          enable_devel=False,
          disable_plugin=None,
          origin_mirror=False):
    """
    Build the Coral ISO.
    :param debug: Whether to dump debug logs into files, default: False.
    :param cache: The dir that caches build RPMs. Default:
        /var/log/coral/build_cache.
    :param lustre: The dir of Lustre RPMs (usually generated by lbuild).
        Default: /var/log/coral/build_cache/$type/lustre.
    :param e2fsprogs: The dir of E2fsprogs RPMs.
        Default: /var/log/coral/build_cache/$type/e2fsprogs.
    :param collectd: The Collectd source codes.
        Default: https://github.com/LiXi-storage/collectd/releases/$latest.
        A local source dir or .tar.bz2 generated by "make dist" of Collectd
        can be specified if modification to Collectd is needed.
    :param enable_zfs: Whether enable ZFS support. Default: False.
    :param enable_devel: Whether enable development support. Default: False.
    :param disable_plugin: Disable one or more plugins. Default: None.
    :param origin_mirror: Whether use origin Yum mirrors. If not use Tsinghua
        mirror for possible speedup. Default: False.
    """
    # pylint: disable=too-many-arguments,unused-argument,protected-access
    if not isinstance(coral_command._cc_log_to_file, bool):
        print("ERROR: invalid debug option [%s], should be a bool type" %
              (coral_command._cc_log_to_file),
              file=sys.stderr)
        sys.exit(1)

    source_dir = os.getcwd()
    identity = build_common.get_build_path()
    log, workspace = cmd_general.init_env_noconfig(
        source_dir, coral_command._cc_log_to_file, True, identity=identity)

    cache = cmd_general.check_argument_str(log, "cache", cache)
    if lustre is not None:
        lustre = cmd_general.check_argument_str(log, "lustre", lustre)
    if e2fsprogs is not None:
        e2fsprogs = cmd_general.check_argument_str(log, "e2fsprogs", e2fsprogs)
    if collectd is not None:
        collectd = cmd_general.check_argument_str(log, "collectd", collectd)
    cmd_general.check_argument_bool(log, "enable_zfs", enable_zfs)
    cmd_general.check_argument_bool(log, "enable_devel", enable_devel)
    if disable_plugin is not None:
        disable_plugin = cmd_general.check_argument_list_str(
            log, "disable_plugin", disable_plugin)
    cmd_general.check_argument_bool(log, "origin_mirror", origin_mirror)
    rc = coral_build.build(log,
                           source_dir,
                           workspace,
                           cache=cache,
                           lustre_rpms_dir=lustre,
                           e2fsprogs_rpms_dir=e2fsprogs,
                           collectd=collectd,
                           enable_zfs=enable_zfs,
                           enable_devel=enable_devel,
                           disable_plugin=disable_plugin,
                           origin_mirror=origin_mirror)
    cmd_general.cmd_exit(log, rc)