Example #1
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {"-M": process_message, "-C": check_nonprocess}
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-y"]
    opt_xor_dict = {"-M": ["-C"], "-C": ["-M"]}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array, func_dict)
Example #2
0
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message):
        if gen_libs.root_run():
            if not arg_parser.arg_require(args_array, opt_req_list) \
               and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
                run_program(args_array)

        else:
            print("Error:  Must run program as root.")
Example #3
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    file_chk_list = ["-i"]
    opt_multi_list = ["-t", "-s"]
    opt_req_list = ["-s", "-t"]
    opt_val_list = ["-s", "-t", "-f", "-i"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list):
        run_program(args_array)
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_or_dict_list -> contains list of options that are OR and required.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-p"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-A": ["-C", "-S", "-E", "-T", "-O"], "-B": rpt_mst_log,
                 "-D": rpt_slv_log, "-C": chk_mst_log, "-S": chk_slv_thr,
                 "-E": chk_slv_err, "-T": chk_slv_time, "-O": chk_slv_other}
    opt_con_req_list = {"-b": ["-m"], "-u": ["-t"], "-A": ["-s"], "-B": ["-c"],
                        "-C": ["-c", "-s"], "-D": ["-s"], "-E": ["-s"],
                        "-O": ["-s"], "-T": ["-c", "-s"]}
    opt_def_dict = {"-b": "sysmon:mysql_rep_lag"}
    opt_multi_list = ["-u", "-t"]
    opt_or_dict_list = {"-c": ["-s"]}
    opt_req_list = ["-d"]
    opt_val_list = ["-d", "-c", "-p", "-s", "-o", "-b", "-m", "-u", "-t", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list,
                                       opt_def_dict, multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_req_or_lst(args_array, opt_or_dict_list) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_rep_admin with id of: %s"
                  % (args_array.get("-y", "")))
Example #5
0
def main(**kwargs):
    """Function:  main

    Description:  Initializes program-wide variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) sys.argv -> Arguments from the command line.
        (input) **kwargs:
            argv_list -> List of arguments from another program.

    """

    cmdline = gen_libs.get_inst(sys)
    cmdline.argv = list(kwargs.get("argv_list", cmdline.argv))
    dir_chk_list = ["-d"]
    func_dict = {"-M": monitor_queue}
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array, func_dict)
Example #6
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        xor_noreq_list -> contains options that are XOR, but are not required.
        ord_prec_array -> holds options in order of precedence to be executed.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-l", "-o"]
    func_dict = {
        "-F": flush_log_bkp,
        "-K": missing_log,
        "-M": bkp_log_miss,
        "-A": bkp_log_all,
        "-S": purge_log_day,
        "-R": purge_log_name
    }
    opt_con_req_list = {
        "-F": ["-o", "-l"],
        "-M": ["-o", "-l"],
        "-A": ["-o", "-l"],
        "-K": ["-o"]
    }
    xor_noreq_list = {"-S": "-R", "-M": "-A"}
    ord_prec_list = ["-F", "-K", "-M", "-A", "-S", "-R"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-l", "-o", "-R", "-S", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_noreq_xor(args_array, xor_noreq_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict, ord_prec_list)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_binlog with id of: %s" %
                  (args_array.get("-y", "")))
Example #7
0
def main():
    """Function:  main

    Description:  Initializes program-wide variables, processes command line
        arguments, sets up pidfile, and contols the running of the daemon.

    Variables:
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) sys.argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    opt_val_list = ["-a", "-c", "-d"]
    opt_req_list = ["-a", "-c", "-d"]
    proc_name = "daemon_rmq_2_sy"

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)
    f_name = "rmq2sysmon_daemon_" + args_array.get("-c", "") + ".pid"
    pid_file = os.path.join(gen_libs.get_base_dir(__file__), "tmp", f_name)
    daemon = Rmq2SysmonDaemon(pid_file, argv_list=cmdline.argv)

    if not arg_parser.arg_require(args_array, opt_req_list):

        if args_array["-a"] == "start":

            if os.path.isfile(pid_file) and is_active(pid_file, proc_name):

                print("Warning:  Pidfile %s exists and process is running." %
                      (pid_file))

            elif os.path.isfile(pid_file):
                os.remove(pid_file)
                daemon.start()

            else:
                daemon.start()

        elif args_array["-a"] == "stop":
            daemon.stop()

        elif args_array["-a"] == "restart":
            daemon.restart()

        else:
            print("Unknown command")
            sys.exit(2)

        sys.exit(0)

    else:
        print("Usage: %s -a start|stop|restart -c module -d directory/config \
{rmq_2_sysmon options}" % cmdline.argv[0])
        sys.exit(2)
Example #8
0
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        func_dict -> dictionary list for the function calls or other options.
        opt_arg_list-> contains list of optional arguments for command line.
        opt_arg_rep -> contains list of replaceable arguments for command line.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains options which are XOR with its values.
        xor_noreq_list -> contains options that are XOR, but are not required.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    dir_chk_list = ["-d", "-p"]
    file_chk_list = ["-f"]
    func_dict = {"-I": insert_doc, "-D": delete_docs, "-T": truncate_coll}
    opt_arg_list = {"-a": "--authenticationDatabase=", "-b": "--db=",
                    "-t": "--collection="}
    opt_arg_rep = {"-f": "--file="}
    opt_con_req_list = {"-k1": ["-l1"]}
    opt_multi_list = ["-f", "-l1", "-l2", "-l3", "-l4", "-l5"]
    opt_req_list = ["-b", "-c", "-d", "-t"]
    opt_val_list = ["-a", "-b", "-c", "-d", "-f", "-k1", "-l1", "-p", "-t",
                    "-k2", "-l2", "-k3", "-l3", "-k4", "-l4", "-k5", "-l5"]
    opt_xor_dict = {"-D": ["-I", "-T"], "-I": ["-D", "-T"], "-T": ["-D", "-I"]}
    xor_noreq_list = {"-k1": "-f"}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(sys.argv, opt_val_list,
                                       multi_val=opt_multi_list)

    # Remove dupe files.
    if "-f" in args_array:
        args_array["-f"] = gen_libs.rm_dup_list(args_array["-f"])

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and arg_parser.arg_noreq_xor(args_array, xor_noreq_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list):
        run_program(args_array, func_dict, opt_arg=opt_arg_list,
                    opt_rep=opt_arg_rep)
Example #9
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        ign_db_tbl -> contains list of databases and tables to be ignored.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_req_xor_list -> contains a list of options that are required XOR.
        opt_val_list -> contains options which require values.
        sys_ign_db -> contains a list of system databases to be ignored.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    ign_db_tbl = {
        "mysql": [
            "innodb_index_stats", "innodb_table_stats", "slave_master_info",
            "slave_relay_log_info", "slave_worker_info"
        ]
    }
    opt_con_req_list = {"-t": ["-B"], "-s": ["-e"], "-u": ["-e"]}
    opt_multi_list = ["-B", "-e", "-s", "-t"]
    opt_req_list = ["-r", "-c", "-d"]
    opt_req_xor_list = {"-A": "-B"}
    opt_val_list = ["-r", "-c", "-d", "-e", "-s", "-y"]
    sys_ign_db = ["performance_schema", "information_schema"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_req_xor(args_array, opt_req_xor_list) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, sys_ign_db, ign_db_tbl=ign_db_tbl)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_rep_cmp with id of: %s" %
                  (args_array.get("-y", "")))
Example #10
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        opt_con_req_dict -> contains options requiring other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_val_list -> contains options which require values.
        opt_valid_val -> contains options with their valid values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    file_chk_list = ["-f", "-i", "-m", "-F"]
    file_crt_list = ["-m"]
    opt_con_req_dict = {"-c": ["-m"], "-s": ["-t"]}
    opt_multi_list = ["-f", "-s", "-t", "-S"]
    opt_val_list = ["-i", "-m", "-o", "-s", "-t", "-y", "-F", "-S", "-k", "-g"]
    opt_valid_val = {"-k": ["and", "or"], "-g": ["a", "w"]}
    cmdline = gen_libs.get_inst(sys)

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    # Set default search logic.
    if "-S" in args_array.keys() and "-k" not in args_array.keys():
        args_array["-k"] = "or"

    # Set default write file mode.
    if "-g" not in args_array.keys():
        args_array["-g"] = "w"

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_cond_req_or(args_array, opt_con_req_dict) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list) \
       and arg_parser.arg_valid_val(args_array, opt_valid_val):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for check_log with id of: %s" %
                  (args_array.get("-y", "")))
Example #11
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_arg_list -> contains arguments to add to command line by default.
        opt_con_req_list -> contains the options that require other options.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_valid_val -> contains list of types of values to be validated.
        opt_xor_dict -> contains options which are XOR with its values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-p"]
    func_dict = {"-L": fetch_log_pos, "-D": fetch_log_entries, "-R": load_log}
    opt_arg_list = ["--force-read", "--read-from-remote-server"]
    opt_con_req_list = {"-R": ["-e"]}
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-e", "-d", "-f", "-g", "-p", "-s", "-t", "-y"]
    opt_valid_val = {
        "-s": gen_libs.validate_date,
        "-t": gen_libs.validate_date
    }
    opt_xor_dict = {"-L": ["-D", "-R"], "-D": ["-L", "-R"], "-R": ["-D", "-L"]}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and arg_parser.arg_validate(args_array, opt_valid_val) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict, opt_arg_list)
            del prog_lock

        except gen_class.SingleInstanceException:
            print(
                "WARNING:  lock in place for mysql_log_admin with id of: %s" %
                (args_array.get("-y", "")))
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {
        "-B": show_best_slave,
        "-D": show_slave_delays,
        "-F": promote_best_slave,
        "-G": promote_designated_slave
    }
    opt_req_list = ["-d", "-s"]
    opt_val_list = ["-d", "-s", "-G", "-y"]
    opt_xor_dict = {
        "-B": ["-D", "-F", "-G"],
        "-D": ["-B", "-F", "-G"],
        "-F": ["-B", "-D", "-G"],
        "-G": ["-B", "-D", "-F"]
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del prog_lock

        except gen_class.SingleInstanceException:
            print(
                "WARNING:  Lock in place for mysql_rep_failover with id: %s" %
                (args_array.get("-y", "")))
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_dict -> contains options requiring other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains options that are required for the program.
        opt_val -> List of options that allow 0 or 1 value for option.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {
        "-C": create_repo,
        "-D": initate_dump,
        "-L": list_dumps,
        "-R": list_repos
    }
    opt_con_req_dict = {"-C": ["-l"], "-i": ["-D"]}
    opt_multi_list = ["-i"]
    opt_req_list = ["-c", "-d"]
    opt_val = ["-D", "-L"]
    opt_val_list = ["-c", "-d", "-i", "-l", "-C"]
    opt_xor_dict = {
        "-C": ["-D", "-L", "-R"],
        "-D": ["-C", "-L", "-R"],
        "-L": ["-C", "-D", "-R"],
        "-R": ["-C", "-D", "-L"]
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_val=opt_val,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and arg_parser.arg_cond_req_or(args_array, opt_con_req_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array, func_dict)
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_def_dict -> contains options with their default values.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-L": list_ins_pkg, "-U": list_upd_pkg, "-R": list_repo}
    opt_def_dict = {"-i": "sysmon:server_pkgs"}
    opt_con_req_list = {"-i": ["-c", "-d"], "-s": ["-e"], "-u": ["-e"]}
    opt_multi_list = ["-e", "-s"]
    opt_val_list = ["-c", "-d", "-i", "-o", "-e", "-s", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  Lock in place for package_admin with id of: %s" %
                  (args_array.get("-y", "")))
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {
        "-L": chk_rep_lag,
        "-M": fetch_members,
        "-S": chk_rep_stat,
        "-P": fetch_priority,
        "-T": prt_rep_stat,
        "-N": node_chk
    }
    opt_con_req_list = {"-i": ["-m"], "-s": ["-e"]}
    opt_def_dict = {"-j": False, "-i": "sysmon:mongo_rep_lag"}
    opt_multi_list = ["-e", "-s"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-i", "-m", "-o", "-e", "-s"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):
        run_program(args_array, func_dict)
Example #16
0
def main(**kwargs):

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.
        (input) **kwargs:
            argv_list -> List of arguments from a wrapper program.

    """

    cmdline = gen_libs.get_inst(sys)
    cmdline.argv = kwargs.get("argv_list", cmdline.argv)
    dir_chk_list = ["-d", "-p"]
    func_dict = {"-M": merge}
    opt_req_list = ["-c", "-d", "-p", "-r"]
    opt_val_list = ["-c", "-d", "-p", "-r"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message):

        # Set Repo Name if not passed
        if "-r" not in args_array.keys() and "-p" in args_array.keys():
            args_array["-r"] = os.path.basename(args_array["-p"])

        if not arg_parser.arg_require(args_array, opt_req_list) \
           and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

            try:
                prog_lock = gen_class.ProgramLock(cmdline.argv,
                                                  args_array.get("-r", ""))
                run_program(args_array, func_dict)
                del prog_lock

            except gen_class.SingleInstanceException:
                print("WARNING:  lock in place for merge with id of: %s"
                      % (args_array.get("-r", "")))
Example #17
0
def main():
    """Function:  main

    Description:  Control the blackbox testing of elastic_db_dump.py program.

    Variables:
        opt_val_list -> contains options which require values.
        base_dir -> Relative directory path to blackbox testing directory.
        test_path -> Current directory path concatencated with base_dir.
        config_path -> Directory path to blackbox config directory.

    Arguments:

    """

    prt_success = "\n\tTest Successful"
    prt_failure = "\n\tTest Failure"
    cmdline = gen_libs.get_inst(sys)
    opt_val_list = ["-c", "-d", "-n", "-C", "-R", "-S", "-T"]
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)
    cfg = load_cfg(args_array)

    if "-C" in args_array:
        els = create_es_instance(cfg, elastic_class.ElasticSearchDump,
                                 args_array["-C"])
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-C"])

        if chk_create_repo(elr, args_array["-C"]):
            print(prt_success)

        else:
            print(prt_failure)

        _ = remove_repo(elr, args_array["-C"], els.dump_loc)

    elif "-R" in args_array:
        els = create_es_instance(cfg, elastic_class.ElasticSearchDump,
                                 args_array["-R"])
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-R"])
        _ = remove_repo(elr, args_array["-R"], els.dump_loc)

    elif "-T" in args_array:
        els = create_es_instance(cfg, elastic_class.ElasticSearchDump,
                                 args_array["-T"])
        els.dump_name = args_array["-n"]
        els.dump_db()

    elif "-S" in args_array:
        els = create_es_instance(cfg, elastic_class.ElasticSearchDump,
                                 args_array["-r"])

        if args_array["-S"] in els.dump_list:
            print(prt_failure)

        else:
            print(prt_success)

    elif "-D" in args_array:
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-D"])

        if args_array["-D"] in elr.repo_dict:
            print(prt_failure)

        else:
            print(prt_success)
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains dict with key that is xor with it's values.
        slv_key -> contains dict with keys to be converted to data types.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {"-M": move_slave, "-R": move_slave, "-S": move_slave_up}
    opt_con_req_list = {
        "-M": ["-m", "-n"],
        "-R": ["-m", "-n"],
        "-S": ["-m", "-n"]
    }
    opt_req_list = ["-c", "-d", "-s"]
    opt_val_list = ["-c", "-d", "-m", "-n", "-s", "-y"]
    opt_xor_dict = {"-M": ["-R", "-S"], "-R": ["-M", "-S"], "-S": ["-M", "-R"]}
    slv_key = {
        "sid": "int",
        "port": "int",
        "cfg_file": "None",
        "ssl_client_ca": "None",
        "ssl_ca_path": "None",
        "ssl_client_key": "None",
        "ssl_client_cert": "None",
        "ssl_client_flag": "int",
        "ssl_disabled": "bool",
        "ssl_verify_id": "bool",
        "ssl_verify_cert": "bool"
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict, slv_key=slv_key)
            del proglock

        except gen_class.SingleInstanceException:
            print(
                "WARNING:  lock in place for mysql_rep_change with id of: %s" %
                (args_array.get("-y", "")))
Example #19
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        check_call -> contains '-C' option values and associated
            ElasticSearchStatus class method names.
        dir_chk_list -> contains options which will be directories.
        func_dict -> dictionary list for the function calls or other options.
        opt_def_dict -> contains options with their default values.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains options that are required for the program.
        opt_val -> List of options that allow 0 or 1 value for option.
        opt_val_list -> contains options which require values.
        status_call -> contains '-D' option values and associated
            ElasticSearchStatus class method names.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    func_dict = {
        "-F": failed_dumps,
        "-L": list_dumps,
        "-M": list_master,
        "-R": list_repos,
        "-N": list_nodes,
        "-D": get_status,
        "-C": check_status
    }
    opt_def_dict = {"-D": [], "-C": []}
    opt_multi_list = ["-D", "-C"]
    opt_req_list = ["-c", "-d"]
    opt_val = ["-F", "-L"]
    opt_val_list = ["-c", "-d", "-m", "-u", "-p"]
    status_call = {
        "node": "get_node_status",
        "server": "get_svr_status",
        "memory": "get_mem_status",
        "shard": "get_shrd_status",
        "general": "get_gen_status",
        "disk": "get_disk_status"
    }
    check_call = {
        "node": "chk_nodes",
        "server": "chk_server",
        "memory": "chk_mem",
        "shard": "chk_shards",
        "general": "chk_status",
        "disk": "chk_disk"
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       opt_val=opt_val,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):
        run_program(args_array,
                    func_dict,
                    status_call=status_call,
                    check_call=check_call)
Example #20
0
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        arg_req_dict -> contains link between config entry and required option.
        dir_chk_list -> contains options which will be directories.
        dir_crt_list -> contain options that require directory to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_arg_list -> contains optional arguments for the command line.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        xor_noreq_list -> contains options that are XOR, but are not required.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    arg_req_dict = {"auth_db": "--authenticationDatabase="}
    dir_chk_list = ["-d", "-o", "-p"]
    dir_crt_list = ["-o"]
    func_dict = {"-A": sync_cp_dump, "-M": mongo_dump}
    opt_arg_list = {"-l": "--oplog", "-z": "--gzip", "-b": "--db=",
                    "-o": "--out=", "-q": "--quiet",
                    "-r": "--dumpDbUsersAndRoles", "-t": "--collection="}
    opt_con_req_list = {"-A": ["-o"], "-r": ["-b"], "-t": ["-b"], "-s": ["-e"]}
    opt_multi_list = ["-e", "-s"]
    opt_req_list = ["-c", "-d", "-o"]
    opt_req_xor_list = {"-A": "-M"}
    opt_val_list = ["-b", "-c", "-d", "-o", "-p", "-t", "-e", "-s", "-y"]
    xor_noreq_list = {"-l": "-b"}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_req_xor(args_array, opt_req_xor_list) \
       and arg_parser.arg_noreq_xor(args_array, xor_noreq_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list,
                                          dir_crt_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict, opt_arg=opt_arg_list,
                        arg_req_dict=arg_req_dict)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  Lock in place for mongo_db_dump with id: %s"
                  % (args_array.get("-y", "")))
Example #21
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_def_dict -> contains options with their default values.
        opt_con_req_list -> contains the options that require other options.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains options that are required for the program.
        opt_val_list -> contains options which require values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-S": mysql_stat}
    opt_def_dict = {"-i": "sysmon:mysql_perf", "-n": "1", "-b": "1"}
    opt_con_req_list = {"-i": ["-m", "-j"], "-s": ["-t"], "-u": ["-t"]}
    opt_multi_list = ["-s", "-t"]
    opt_req_list = ["-c", "-d", "-b", "-n"]
    opt_val_list = ["-c", "-d", "-b", "-i", "-m", "-n", "-o", "-s", "-t", "-y"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       multi_val=opt_multi_list)

    # Add required default options and values to argument dictionary.
    args_array = arg_parser.arg_add_def(args_array, opt_def_dict, opt_req_list)

    if not gen_libs.is_pos_int(int(args_array["-b"])):
        args_array["-b"] = "1"

    if not gen_libs.is_pos_int(int(args_array["-n"])):
        args_array["-n"] = "1"

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_perf with id of: %s" %
                  (args_array.get("-y", "")))
Example #22
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        dir_crt_list -> contain options that require directory to be created.
        opt_arg_list -> contains arguments to add to command line by default.
        opt_con_req_dict -> contains options requiring other options.
        opt_dump_list -> contains optional arguments to mysqldump.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains options which are XOR with its values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-o", "-d", "-p"]
    dir_crt_list = ["-o"]

    # --ignore-table=mysql.event -> Skips dumping the event table.
    opt_arg_list = ["--ignore-table=mysql.event"]
    opt_con_req_dict = {
        "-t": ["-e"],
        "-A": ["-o"],
        "-B": ["-o"],
        "-D": ["-o"],
        "-u": ["-e"]
    }
    opt_dump_list = {
        "-s": "--single-transaction",
        "-D": ["--all-databases", "--triggers", "--routines", "--events"],
        "-r": "--set-gtid-purged=OFF"
    }
    opt_multi_list = ["-B", "-e", "-t"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-B", "-c", "-d", "-o", "-p", "-y", "-e", "-t"]
    opt_xor_dict = {"-A": ["-B", "-D"], "-B": ["-A", "-D"], "-D": ["-A", "-B"]}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list,
                                          dir_crt_list) \
       and arg_parser.arg_cond_req_or(args_array, opt_con_req_dict):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, opt_arg_list, opt_dump_list)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  Lock in place for mysql_db_dump with id: %s" %
                  (args_array.get("-y", "")))
Example #23
0
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_arg_list -> contains optional arguments for the command line.
        opt_con_req_dict -> contains options requiring one or more options.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_valid_val -> contains a list of valid values for options.
        opt_xor_dict -> contains dict with key that is xor with it's values.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-n"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-C": defrag, "-D": dbcc, "-R": repair_db, "-M": status,
                 "-L": rotate, "-G": get_log}
    opt_con_req_dict = {"-j": ["-M", "-G"]}
    opt_con_req_list = {"-i": ["-m"], "-n": ["-L"], "-l": ["-G"], "-f": ["-D"],
                        "-s": ["-e"]}
    opt_def_dict = {"-C": [], "-D": [], "-R": [], "-G": "global",
                    "-i": "sysmon:mongo_db_status"}
    opt_multi_list = ["-C", "-D", "-R", "-t", "-e", "-s"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-t", "-C", "-D", "-R", "-i", "-m", "-o",
                    "-G", "-n", "-e", "-s", "-y"]
    opt_valid_val = {"-G": ["global", "rs", "startupWarnings"]}
    opt_xor_dict = {"-R": ["-C", "-M", "-D"], "-C": ["-D", "-M", "-R"],
                    "-D": ["-C", "-M", "-R"], "-M": ["-C", "-D", "-R", "-G"],
                    "-G": ["-M"], "-j": ["-l"], "-l": ["-j"]}

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list,
                                       opt_def_dict, multi_val=opt_multi_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_valid_val(args_array, opt_valid_val) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and arg_parser.arg_cond_req_or(args_array, opt_con_req_dict) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            prog_lock = gen_class.ProgramLock(cmdline.argv,
                                              args_array.get("-y", ""))
            run_program(args_array, func_dict)
            del prog_lock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mongo_db_admin with id of: %s"
                  % (args_array.get("-y", "")))
Example #24
0
def main():

    """Function:  main

    Description:  Control the blackbox testing of elastic_db_dump.py program.

    Variables:
        opt_val_list -> contains options which require values.

    Arguments:

    """

    prt_good = "\n\tTest Successful"
    prt_fail = "\n\tTest Failure"

    cmdline = gen_libs.get_inst(sys)
    opt_val_list = ["-c", "-d", "-C", "-R", "-D", "-P"]
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)
    cfg = load_cfg(args_array)

    if "-C" in args_array:
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-C"])

        if chk_create_repo(elr, args_array["-C"]):
            print(prt_good)

        else:
            print(prt_fail)

        _ = remove_repo(elr, args_array["-C"], args_array["-P"])

    elif "-R" in args_array:
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-R"])
        _ = remove_repo(elr, args_array["-R"], args_array["-P"])

    elif "-i" in args_array and "-D" in args_array:
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-D"])
        dir_path = os.path.join(args_array["-P"], args_array["-D"], "indices")

        # Count number of databases/indices dumped to repository.
        if len([name for name in os.listdir(dir_path)
                if os.path.isdir(os.path.join(dir_path, name))]) == 1:

            print(prt_good)

        else:
            print(prt_fail)

        _ = remove_repo(elr, args_array["-D"], args_array["-P"])

    elif "-D" in args_array:
        els = create_es_instance(cfg, elastic_class.ElasticSearchDump,
                                 args_array["-D"])
        elr = create_es_instance(cfg, elastic_class.ElasticSearchRepo,
                                 args_array["-D"])

        if els.dump_list:
            print(prt_good)

        else:
            print(prt_fail)

        _ = remove_repo(elr, args_array["-D"], args_array["-P"])

    elif "-I" in args_array:
        els = create_es_instance(cfg, elastic_class.ElasticSearchDump)

        print(str(
            [x.split() for x in els.els.cat.indices().splitlines()][0][2]))
Example #25
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        opt_arg_list -> contains arguments to add to command line by default.
        opt_con_req_list -> contains the options that require other options.
        opt_dump_list -> contains optional arguments for mysqldump command.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        req_rep_cfg -> contains replication config settings got master/slave.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-p"]
    opt_arg_list = [
        "--single-transaction", "--all-databases", "--triggers", "--routines",
        "--events", "--ignore-table=mysql.event"
    ]
    opt_con_req_list = {"-r": ["-n"]}
    opt_dump_list = {"-r": "--set-gtid-purged=OFF"}
    opt_req_list = ["-c", "-t", "-d"]
    opt_val_list = ["-c", "-t", "-d", "-p", "-y"]
    req_rep_cfg = {
        "master": {
            "log_bin": "ON",
            "sync_binlog": "1",
            "innodb_flush_log_at_trx_commit": "1",
            "innodb_support_xa": "ON",
            "binlog_format": "ROW"
        },
        "slave": {
            "log_bin": "ON",
            "read_only": "ON",
            "log_slave_updates": "ON",
            "sync_master_info": "1",
            "sync_relay_log": "1",
            "sync_relay_log_info": "1"
        }
    }

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array,
                        req_rep_cfg,
                        opt_arg_list,
                        opt_dump_list=opt_dump_list)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_clone with id of: %s" %
                  (args_array.get("-y", "")))
Example #26
0
def main():
    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_arg_list -> contains optional arguments for the command line.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_def_dict2 -> default values for "-S" and "-j" options combination.
        opt_def_dict3 -> default values for "-i" setup.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        req_arg_list -> contains arguments to add to command line by default.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    global AUTH_DB

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d", "-p"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-S": mongo_stat}
    opt_arg_list = {"-j": "--json", "-n": "-n="}
    opt_con_req_list = {"-i": ["-m", "-j"], "-s": ["-t"], "-u": ["-t"]}
    opt_def_dict = {"-i": "sysmon:mongo_perf", "-n": "1", "-b": "1"}
    opt_def_dict2 = {"-n": "1", "-b": "1"}
    opt_def_dict3 = {"-j": True}
    opt_multi_list = ["-s", "-t"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-b", "-i", "-m", "-n", "-o", "-p", "-s", "-t"]
    req_arg_list = [AUTH_DB]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv,
                                       opt_val_list,
                                       opt_def_dict,
                                       multi_val=opt_multi_list)

    # Add default arguments for certain argument combinations.
    if "-i" in args_array.keys() and "-j" not in args_array.keys():
        args_array = arg_parser.arg_add_def(args_array, opt_def_dict3)

    if "-S" in args_array.keys() and "-j" in args_array.keys():
        args_array = arg_parser.arg_add_def(args_array, opt_def_dict2)

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array,
                        func_dict,
                        req_arg=req_arg_list,
                        opt_arg=opt_arg_list)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mongo_perf with id of: %s" %
                  (args_array.get("-y", "")))
def main():

    """Function:  main

    Description:  Initializes program-wide used variables and processes command
        line arguments and values.

    Variables:
        dir_chk_list -> contains options which will be directories.
        file_chk_list -> contains the options which will have files included.
        file_crt_list -> contains options which require files to be created.
        func_dict -> dictionary list for the function calls or other options.
        opt_con_req_list -> contains the options that require other options.
        opt_def_dict -> contains options with their default values.
        opt_multi_list -> contains the options that will have multiple values.
        opt_req_list -> contains the options that are required for the program.
        opt_val_list -> contains options which require values.
        opt_xor_dict -> contains options which are XOR with its values.
        sys_dbs -> contains a list of system databases that will be skipped
            over for some functions.

    Arguments:
        (input) argv -> Arguments from the command line.

    """

    cmdline = gen_libs.get_inst(sys)
    dir_chk_list = ["-d"]
    file_chk_list = ["-o"]
    file_crt_list = ["-o"]
    func_dict = {"-A": analyze, "-C": check, "-D": optimize, "-S": checksum,
                 "-M": status, "-L": listdbs}
    opt_con_req_list = {"-i": ["-m"], "-s": ["-e"], "-u": ["-e"]}
    opt_def_dict = {"-t": None, "-A": [], "-C": [], "-D": [], "-S": [],
                    "-i": "sysmon:mysql_db_status"}
    opt_multi_list = ["-A", "-C", "-D", "-S", "-t", "-e", "-s"]
    opt_req_list = ["-c", "-d"]
    opt_val_list = ["-c", "-d", "-t", "-A", "-C", "-D", "-S", "-i", "-m", "-o",
                    "-e", "-s", "-y"]
    opt_xor_dict = {"-A": ["-C", "-D", "-M", "-S", "-L"],
                    "-C": ["-A", "-D", "-M", "-S", "-L"],
                    "-D": ["-A", "-C", "-M", "-S", "-L"],
                    "-S": ["-A", "-C", "-D", "-M", "-L"],
                    "-M": ["-A", "-C", "-D", "-S", "-L"],
                    "-L": ["-A", "-C", "-D", "-S", "-M"]}
    sys_dbs = ["performance_schema", "information_schema", "mysql", "sys"]

    # Process argument list from command line.
    args_array = arg_parser.arg_parse2(cmdline.argv, opt_val_list,
                                       opt_def_dict, multi_val=opt_multi_list)

    # Set JSON format for certain option settings
    if "-i" in args_array.keys() and "-m" in args_array.keys() \
       and "-j" not in args_array.keys():
        args_array["-j"] = True

    if not gen_libs.help_func(args_array, __version__, help_message) \
       and not arg_parser.arg_require(args_array, opt_req_list) \
       and arg_parser.arg_xor_dict(args_array, opt_xor_dict) \
       and arg_parser.arg_cond_req(args_array, opt_con_req_list) \
       and not arg_parser.arg_dir_chk_crt(args_array, dir_chk_list) \
       and not arg_parser.arg_file_chk(args_array, file_chk_list,
                                       file_crt_list):

        try:
            proglock = gen_class.ProgramLock(cmdline.argv,
                                             args_array.get("-y", ""))
            run_program(args_array, func_dict, sys_dbs=sys_dbs,
                        multi_val=opt_multi_list)
            del proglock

        except gen_class.SingleInstanceException:
            print("WARNING:  lock in place for mysql_db_admin with id of: %s"
                  % (args_array.get("-y", "")))