def run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Create a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dictionary list of functions and options. (input) **kwargs: status_call -> Contains class method names for the '-D' option. check_call -> Contains class method names for the '-C' option. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) func_dict = dict(func_dict) cfg = gen_libs.load_module(args_array["-c"], args_array["-d"]) try: prog_lock = gen_class.ProgramLock(cmdline.argv, cfg.host) # Intersect args_array & func_dict to find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): els = elastic_class.ElasticSearchStatus(cfg.host, cfg.port, **kwargs) func_dict[opt](els, args_array=args_array, cfg=cfg, **kwargs) del prog_lock except gen_class.SingleInstanceException: print("Warning: elastic_db_admin lock in place for: %s" % (cfg.host))
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", "")))
def run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Create a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dictionary list of functions and options. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) func_dict = dict(func_dict) cfg = gen_libs.load_module(args_array["-c"], args_array["-d"]) hostname = socket.gethostname().strip().split(".")[0] try: prog_lock = gen_class.ProgramLock(cmdline.argv, hostname) # Find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): els = elastic_class.ElasticSearchRepo(cfg.host, cfg.port, repo=args_array.get("-L")) func_dict[opt](els, args_array=args_array, **kwargs) del prog_lock except gen_class.SingleInstanceException: print("WARNING: elastic_db_repo lock in place for: %s" % (hostname))
def run_program(args_array, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Create a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dictionary of command line options and values. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) cfg = gen_libs.load_module(args_array["-c"], args_array["-d"]) server = gen_class.System() server.set_host_name() try: prog_lock = gen_class.ProgramLock(cmdline.argv, server.host_name) proc_data = get_svr_info(server) proc_data.update(get_svr_mem()) proc_data["processes"] = get_proc_mem(cfg.memory_threshold) post_process(proc_data, args_array, cfg) del prog_lock except gen_class.SingleInstanceException: print("WARNING: server_usage lock in place for: %s" % (server.host_name))
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", "")))
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", "")))
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", "")))
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 run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Set a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dict of function calls and associated options. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) func_dict = dict(func_dict) cfg = gen_libs.load_module(args_array["-c"], args_array["-d"]) cfg.mongo = gen_libs.load_module(cfg.mongo_cfg, args_array["-d"]) cfg, status_flag, err_msg = validate_create_settings(cfg) if status_flag: log = gen_class.Logger(cfg.log_file, cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") str_val = "=" * 80 log.log_info("%s:%s Initialized" % (cfg.host, cfg.exchange_name)) log.log_info("%s" % (str_val)) log.log_info("Exchange Name: %s" % (cfg.exchange_name)) log.log_info("Queue Configuration:") for queue in cfg.queue_list: log.log_info("\tQueue Name: %s, Routing Key: %s" % (queue["queue"], queue["routing_key"])) log.log_info("To Email: %s" % (cfg.to_line)) log.log_info("%s" % (str_val)) try: flavor_id = cfg.exchange_name prog_lock = gen_class.ProgramLock(cmdline.argv, flavor_id) # Intersect args_array & func_dict to find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): func_dict[opt](cfg, log, **kwargs) del prog_lock except gen_class.SingleInstanceException: log.log_warn("rmq_metadata lock in place for: %s" % (flavor_id)) log.log_close() else: print("Error: Problem in configuration file or directory setup.") print(err_msg)
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. 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 run_program(args_array, func_dict, **kwargs): """Function: run_program Description: Creates class instance and controls flow of the program. Create a program lock to prevent other instantiations from running. Arguments: (input) args_array -> Dict of command line options and values. (input) func_dict -> Dictionary list of functions and options. """ cmdline = gen_libs.get_inst(sys) args_array = dict(args_array) func_dict = dict(func_dict) cfg, status_flag, err_msgs = load_cfg(args_array["-c"], args_array["-d"]) if status_flag: log = gen_class.Logger(cfg.log_file, cfg.log_file, "INFO", "%(asctime)s %(levelname)s %(message)s", "%Y-%m-%dT%H:%M:%SZ") str_val = "=" * 80 log.log_info("%s:%s Initialized" % (cfg.host, cfg.exchange_name)) log.log_info("%s" % (str_val)) log.log_info("Exchange Name: %s" % (cfg.exchange_name)) log.log_info("Exchange Type: %s" % (cfg.exchange_type)) log.log_info("Valid Queues: %s" % (cfg.valid_queues)) log.log_info("Email Archive: %s" % (cfg.email_dir)) log.log_info("%s" % (str_val)) try: flavor_id = args_array.get("-y", cfg.exchange_name) prog_lock = gen_class.ProgramLock(cmdline.argv, flavor_id) # Intersect args_array & func_dict to find which functions to call. for opt in set(args_array.keys()) & set(func_dict.keys()): func_dict[opt](cfg, log, **kwargs) del prog_lock except gen_class.SingleInstanceException: log.log_warn("mail_2_rmq lock in place for: %s" % (flavor_id)) log.log_close() else: print("Error: Problem(s) in configuration file.") for line in err_msgs: print(line)
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", "")))
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. 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", "")))
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", "")))
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", "")))
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", "")))
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", "")))
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", "")))
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", "")))