예제 #1
0
def usage(command):
    """
    Print usage string
    """
    utils.eprint(
        """Usage: %s [--config|-c <config>] [--logdir|-d <logdir>] [--help|-h] <command> [arg...]
  config: configuration file path
  logdir: the dir path to save logs
  config: config file path
  command: one of the following commands:
    locate <service> [hostname]
    start <service>
    stop <service>
  hostname: the hostname the service runs
  service: the name of the service, e.g. fsname-OST000a, or MGS ID in clownfish.conf, e.g. lustre_mgs
Examples:
  %s locate lustre_mgs hostname=server1
  %s locate lustre0-OST000a hostname=server2
  %s locate lustre0-MDT000a hostname=server3
  %s locate lustre0-OST000a
  %s start lustre0-OST000a
  %s start lustre_mgs
  %s stop lustre0-OST000a
  %s stop lustre_mgs""" % (command, command, command, command, command,
                           command, command, command, command))
예제 #2
0
def usage():
    """
    Print usage string
    """
    utils.eprint("Usage: %s [--config|-c <config>] [--logdir|-d <logdir>] [--help|-h]\n"
                 "        logdir: the dir path to save logs\n"
                 "        config: config file path"
                 % sys.argv[0])
예제 #3
0
파일: lond.py 프로젝트: DDNStorage/lond
def simple_usage():
    """
    Print simple usage string
    """
    utils.eprint(
        "  commands:\n"
        "    fetch     fetch dirs from global Lustre to local Lustre\n"
        "    stat      show the lond status of dirs or files\n"
        "    sync      sync dirs from local Lustre to global Lustre\n"
        "    unlock    unlock global Lustre dirs or files\n")
예제 #4
0
def usage(usage_func):
    """
    Print usage string
    """
    if usage_func is None:
        utils.eprint(
            "Usage: %s [--config|-c <config>] [--logdir|-d <logdir>] [--help|-h]\n"
            "    logdir: the dir path to save logs\n"
            "    config: config file path" % sys.argv[0])
    else:
        usage_func(sys.argv[0])
예제 #5
0
파일: lond.py 프로젝트: DDNStorage/lond
def usage():
    """
    Print usage string
    """
    utils.eprint("Usage: %s [options]\n"
                 "or     %s <command> -h|--help\n"
                 "or     %s <command> [args...]\n"
                 "  options:\n"
                 "    -h|--help   print this help" %
                 (sys.argv[0], sys.argv[0], sys.argv[0]))
    simple_usage()
예제 #6
0
파일: lond.py 프로젝트: DDNStorage/lond
def lond_command_help(interact, log, args):
    # pylint: disable=unused-argument
    """
    Print the help string
    """
    if len(args) <= 1:
        simple_usage()
        utils.eprint("\n    h         print this help\n"
                     "    h <cmd>   print help of command <cmd>\n"
                     "    <cmd> -h  print help of command <cmd>\n"
                     "\n"
                     "    q         quit")
        return 0
    cmd_line = "%s -h" % args[1]
    return interact.li_command(log, cmd_line)
예제 #7
0
def usage():
    """
    Print the usage of the command
    """
    command = sys.argv[0]
    utils.eprint("Usage: %s <server>\n"
                 "    server: the server address\n"
                 "\n"
                 "examples:\n"
                 "%s    --> use http://localhost:1234 as the server address\n"
                 "%s -s localhost\n"
                 "%s -s localhost\n"
                 "%s -s http://localhost:1234\n"
                 "%s -s http://10.0.0.10:1234"
                 % (command, command, command, command, command, command))
예제 #8
0
파일: lod.py 프로젝트: DDNStorage/lond
 def show(self):
     """
     Show details only if dryrun
     """
     if self.ls_stage_source is not None:
         utils.eprint("Source: %s" % self.ls_stage_source)
     elif self.ls_stage_sourcelist is not None:
         utils.eprint("Sourcelist: %s" % self.ls_stage_sourcelist)
     utils.eprint("Destination: %s" % self.ls_stage_dest)
예제 #9
0
def usage():
    """
    Print usage string
    """
    utils.eprint("Usage: %s influx_server influx_databse query_string" %
                 sys.argv[0])
예제 #10
0
def main(default_config_fpath,
         default_log_parent,
         main_func,
         usage_func=None,
         parse_func=None,
         console_level=logging.INFO,
         lock=True):
    """
    The main function of a command
    """
    # pylint: disable=too-many-locals,too-many-branches,too-many-statements
    # pylint: disable=too-many-arguments
    reload(sys)
    sys.setdefaultencoding("utf-8")

    if parse_func is None:
        options, args = getopt.getopt(sys.argv[1:], "c:i:h",
                                      ["config=", "help", "logdir="])

        config_fpath = None
        workspace = None
        private = None
        for opt, arg in options:
            if opt == '-c' or opt == "--config" or opt == "-config":
                config_fpath = arg
            elif opt == '-l' or opt == "--logdir" or opt == "-logdir":
                workspace = arg
            elif opt == '-h' or opt == "--help" or opt == "-help":
                usage(usage_func)
                sys.exit(0)
            else:
                usage(usage_func)
                sys.exit(1)

        if len(args) != 0:
            usage(usage_func)
            sys.exit(1)
    else:
        workspace, config_fpath, private = parse_func()

    if workspace is None:
        identity = time_util.local_strftime(time_util.utcnow(),
                                            "%Y-%m-%d-%H_%M_%S")
        workspace = default_log_parent + "/" + identity
    if config_fpath is None:
        config_fpath = default_config_fpath

    command = "mkdir -p %s" % workspace
    retval = utils.run(command)
    if retval.cr_exit_status != 0:
        utils.eprint("failed to run command [%s], "
                     "ret = [%d], stdout = [%s], stderr = [%s]" %
                     (command, retval.cr_exit_status, retval.cr_stdout,
                      retval.cr_stderr))
        sys.exit(-1)

    log = clog.get_log(resultsdir=workspace,
                       exclusive=False,
                       console_level=console_level)
    log.cl_info("starting to run [%s] using config [%s], "
                "please check [%s] for more log" %
                (main_func.__name__, config_fpath, workspace))

    if not os.path.exists(config_fpath):
        log.cl_error("config [%s] doesn't exist, using empty config",
                     config_fpath)
        ret = main_func(log, workspace, None)
        sys.exit(ret)
    elif not os.path.isfile(config_fpath):
        log.cl_error("config [%s] is not a file", config_fpath)
        sys.exit(-1)

    config_fname = os.path.basename(config_fpath)
    save_fpath = workspace + "/" + config_fname
    log.cl_debug("copying config file from [%s] to [%s]", config_fpath,
                 save_fpath)
    if config_fpath != save_fpath:
        shutil.copyfile(config_fpath, save_fpath)

    if lock:
        lock_file = config_fpath + ".lock"
        lock = filelock.FileLock(lock_file)
        try:
            with lock.acquire(timeout=0):
                try:
                    if parse_func is None:
                        ret = main_func(log, workspace, config_fpath)
                    else:
                        ret = main_func(log, workspace, config_fpath, private)
                except:
                    ret = -1
                    log.cl_error("exception: %s", traceback.format_exc())
                lock.release()
        except filelock.Timeout:
            ret = -1
            log.cl_error(
                "someone else is holding lock of file [%s], aborting "
                "to prevent conflicts", lock_file)
    else:
        try:
            if parse_func is None:
                ret = main_func(log, workspace, config_fpath)
            else:
                ret = main_func(log, workspace, config_fpath, private)
        except:
            ret = -1
            log.cl_error("exception: %s", traceback.format_exc())
    sys.exit(ret)
예제 #11
0
def usage():
    """
    Print usage string
    """
    utils.eprint("Usage: %s [-P port] host [command]" % sys.argv[0])
    utils.eprint("Examples:")
    utils.eprint("%s localhost" % sys.argv[0])
    utils.eprint("%s -P %s localhost" %
                 (sys.argv[0], constants.CLOWNFISH_DEFAULT_SERVER_PORT))
    utils.eprint("%s -P %s 192.168.1.2" %
                 (sys.argv[0], constants.CLOWNFISH_DEFAULT_SERVER_PORT))
    utils.eprint("%s -P %s 192.168.1.2 h" %
                 (sys.argv[0], constants.CLOWNFISH_DEFAULT_SERVER_PORT))
    utils.eprint("%s 192.168.1.2:%s service move server1" %
                 (sys.argv[0], constants.CLOWNFISH_DEFAULT_SERVER_PORT))
예제 #12
0
def usage():
    """
    Print usage string
    """
    utils.eprint("Usage: %s config_file" %
                 sys.argv[0])
예제 #13
0
파일: lod.py 프로젝트: DDNStorage/lond
def usage():
    """
    Print usage string
    """
    utils.eprint("""Usage: lod [-h/--help]
 [-d/--dry-run] -n/--node c01,c[02-04] [--mds c01] [--oss c[02-04]]
 --mdtdevs /dev/sda --ostdevs /dev/sdb --fsname mylod --mountpoint /mnt/lod
  start/stop/initialize""")
    utils.eprint("	-d/--dry-run :*dry* run, don't do real job")
    utils.eprint("	-n/--node :, run lod with specified node list, also means the clients")
    utils.eprint("	-T/--mds :MDS")
    utils.eprint("	-O/--oss :OSS")
    utils.eprint("	-I/--index :instance index")
    utils.eprint("	-m/--mdtdevs :mdt device")
    utils.eprint("	-o/--ostdevs :ost device")
    utils.eprint("	-f/--fsname :lustre instance fsname")
    utils.eprint("	-i/--inet :networks interface, e.g. tcp0, o2ib01")
    utils.eprint("	-p/--mountpoint :mountpoint on client")
    utils.eprint("	-h/--help :show usage\n")
    utils.eprint("""for stage_in/stage_out""")
    utils.eprint("lod --source=/foo/foo1 --destination /foo2/ stage_in")
    utils.eprint("lod --sourcelist=/foo/foo1_list --source=/foo_dir --destination /foo2/ stage_out")
예제 #14
0
파일: lod.py 프로젝트: DDNStorage/lond
    def show_topology(self):
        """
        Show lod topology
        Operator: start
        MDS: mds0 mds1 ... mdsX
                mgs: /dev/vdx	---> mds0
                mdt0: /dev/vda	---> mds0
                mdt1: /dev/vdb	---> mds1
        OSS: oss0 oss1 ...ossX
                ost0: /dev/vdx	---> oss0
                ost1: /dev/vdx	---> oss1
                ost2: /dev/vdx	---> oss2
        CLIENTS:
            client01	/mnt/lod
            client02	/mnt/lod
        FSNAME: fsname
        NET: tcp
        MOUNTPOINT: /mnt/lod
        """
        utils.eprint("Operator: %s" % OPERATOR)
        utils.eprint("MDS: %s" % [mds_node.ln_hostname for mds_node in self.lod_mds_nodes])
        for mds_node in self.lod_mds_nodes:
            if mds_node.lm_index == 0:
                utils.eprint("	%10s: %s	---> %s" %
                             ("mgs", mds_node.lm_mgt, mds_node.ln_hostname))
            mdt_name = "mdt%d" % mds_node.lm_index
            utils.eprint("	%10s: %s	---> %s" %
                         (mdt_name, mds_node.lm_mdt, mds_node.ln_hostname))

        utils.eprint("OSS: %s" % [oss_node.ln_hostname for oss_node in self.lod_oss_nodes])
        for oss_node in self.lod_oss_nodes:
            utils.eprint("	%10s: %s	---> %s" %
                         ("ost%d" % oss_node.lo_index,
                          oss_node.lo_ost, oss_node.ln_hostname))

        utils.eprint("Clients:")
        for client_node in self.lod_client_nodes:
            utils.eprint("	%s	%s" % (client_node.ln_hostname, client_node.ln_mountpoint))

        utils.eprint("Fsname: %s" % self.lod_client_nodes[0].ln_fsname)
        utils.eprint("Net: %s" % self.lod_client_nodes[0].ln_net)
        utils.eprint("Mountpoint: %s" % self.lod_client_nodes[0].ln_mountpoint)