def swap_env_find(p_count, p_loc, param_list): if (p_count == 0) and (p_loc == 'NA'): my_logger.debug( "No '-p' found in arguments. Finding active environment") try: s_suffix = findActiveEnv() except: my_logger.error( "Failed in finding active environment. If in maintenance mode use: python dbUtil.py -o swap -d <DB_SERVICE> -p <PROD_ENV>. Exiting!" ) sys.exit( "Failed in finding active environment. If in maintenance mode use: python dbUtil.py -o swap -d <DB_SERVICE> -p <PROD_ENV>. Exiting!" ) elif p_count == 1: s_suffix = param_list[p_loc] my_logger.debug("Received s_suffix: %s" % s_suffix) s_env = s_suffix.split("-")[1] + "." + s_suffix.split( "-")[0] + ".aws.3top.com" if s_env == 'a.prod.aws.3top.com': t_env = "b.prod.aws.3top.com" elif s_env == 'b.prod.aws.3top.com': t_env = "a.prod.aws.3top.com" else: my_logger.error( "Cannot recognize source_environment. Received s_env: %s. Exiting!" % s_env) sys.exit( "Cannot recognize source_environment. Received s_env: %s. Exiting!" % s_env) my_logger.debug("Returning to set_params() with s_env: %s and t_env: %s." % (s_env, t_env)) return (s_env, t_env)
def swap_env_find(p_count, p_loc, param_list): if (p_count == 0) and (p_loc == 'NA'): my_logger.debug("No '-p' found in arguments. Finding active environment") try: s_suffix = findActiveEnv() except: my_logger.error("Failed in finding active environment. If in maintenance mode use: python dbUtil.py -o swap -d <DB_SERVICE> -p <PROD_ENV>. Exiting!") sys.exit("Failed in finding active environment. If in maintenance mode use: python dbUtil.py -o swap -d <DB_SERVICE> -p <PROD_ENV>. Exiting!") elif p_count ==1: s_suffix = param_list[p_loc] my_logger.debug("Received s_suffix: %s"%s_suffix) s_env = s_suffix.split("-")[1] + "." + s_suffix.split("-")[0] + ".aws.3top.com" if s_env == 'a.prod.aws.3top.com': t_env = "b.prod.aws.3top.com" elif s_env == 'b.prod.aws.3top.com': t_env = "a.prod.aws.3top.com" else: my_logger.error("Cannot recognize source_environment. Received s_env: %s. Exiting!"%s_env) sys.exit("Cannot recognize source_environment. Received s_env: %s. Exiting!"%s_env) my_logger.debug("Returning to set_params() with s_env: %s and t_env: %s."%(s_env, t_env)) return (s_env, t_env)
def set_params(param_list): my_logger.debug("Received arguments: %s"%param_list) ttdb_dict = dict() s_count, t_count, o_count, d_count, bdir_count, rdir_count, p_count =\ 0, 0, 0, 0, 0, 0, 0 my_logger.debug("Extracting the parameters from command line arguments...") for i in range(0, len(param_list)-1): if (param_list[i] == "-s"): s_count = s_count + 1 source_loc = i + 1 elif (param_list[i] == "-t"): t_count = t_count + 1 target_loc = i + 1 elif (param_list[i] == "-o"): o_count = o_count + 1 operation_loc = i + 1 elif (param_list[i] == "-d"): d_count = d_count + 1 service_loc = i + 1 elif (param_list[i] == "-bdir"): bdir_count = bdir_count + 1 bdir_loc = i + 1 elif (param_list[i] == "-rdir"): rdir_count = rdir_count + 1 rdir_loc = i + 1 elif (param_list[i] == "-p"): p_count = p_count + 1 p_loc = i + 1 my_logger.debug("Received s_count: %s, t_count: %s, o_count: %s, p_count: %s"%(s_count, t_count, o_count, p_count)) my_logger.debug("Received d_count: %s, bdir_count: %s, rdir_count: %s"%(d_count, bdir_count, rdir_count)) if (s_count> 1) or (t_count > 1) or (o_count > 1 ) or (d_count > 1) or (bdir_count > 1) or (rdir_count > 1) or (p_count > 1): my_logger.error("Multiple flags of same type detected. Exiting!") sys.exit("Multiple flags of same type detected. Exiting!") elif o_count == 0: my_logger.error("No db_operation found. Exiting!") print("No db_operation found. Required format: python dbUtil.py -s <SOURCE_ENV> -t <TARGET_ENV> -o <DB_OPERATION> -d <DB_SERVICE> [optional: -p <PROD_OVERRIDE>] \n or python dbUtil.py -o swap -d <DB_SERVICE> [optional: -p <PROD_ENV>].") sys.exit("Please use correct format and run again. Exiting!") elif d_count == 0: my_logger.error("No db_service found. Exiting!") print("No db_service found. Required format: python dbUtil.py -s <SOURCE_ENV> -t <TARGET_ENV> -o <DB_OPERATION> -d <DB_SERVICE> [optional: -p <PROD_OVERRIDE>] \n or python dbUtil.py -o swap -d <DB_SERVICE> [optional: -p <PROD_ENV>].") sys.exit("Please use correct format and run again. Exiting!") """********************************************************************************************************************************* FIND DB_OPERATION...START *********************************************************************************************************************************""" my_logger.debug("Calling operation_validate(%s, %s, %s)"%(o_count, param_list, operation_loc)) db_operation = db_operation_validate(o_count, param_list, operation_loc) my_logger.debug("operation_validate() call successful! Received db_operation: %s"%db_operation) my_logger.debug("Inserting db_operation into ttdb_dict...") ttdb_dict['db_operation'] = db_operation """********************************************************************************************************************************* FIND DB_OPERATION...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* VALIDATE NUMBER OF ARGUMENTS...START *********************************************************************************************************************************""" my_logger.debug("Calling arg_valid_bool = arg_count_validate(%s, %s)" %(len(param_list), db_operation)) arg_valid_bool = arg_count_validate(len(param_list), db_operation) my_logger.debug("arg_count_validate() call successful. Received arg_valid_bool: %s"%arg_valid_bool) if arg_valid_bool: my_logger.debug("Argument count is valid. Continuing!") else: my_logger.error("Argument count is invalid. Exiting!") sys.exit("Argument count is invalid. Exiting!") """********************************************************************************************************************************* VALIDATE NUMBER OF ARGUMENTS...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND ACTIVE ENVIRONMENT...START *********************************************************************************************************************************""" my_logger.debug("Determining active environment...") if p_count == 0: active_env = findActiveEnv() my_logger.debug("Active (production) environment determined as: %s"%active_env) elif p_count == 1: active_env = param_list[p_loc] my_logger.debug("Active (production) environment determined as: %s"%active_env) else: my_logger.error("Unexpected error encountered in setting active environment. Exiting!") sys.exit("Unexpected error encountered in setting active environment. Exiting!") """********************************************************************************************************************************* FIND ACTIVE ENVIRONMENT...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND OS...START *********************************************************************************************************************************""" my_logger.debug("Determining OS Platform information...") platform_info = platform.platform() my_logger.debug("Received platform_info: %s"%platform_info) if "Windows" in platform_info: os_platform = 'Windows' my_logger.debug("Platform determined as %s"%os_platform) elif "Linux" in platform_info: os_platform = 'Linux' my_logger.debug("Platform determined as %s"%os_platform) else: my_logger.debug("Cannot determine platform. Exiting!") sys.exit("Cannot determine platform. Exiting!") """********************************************************************************************************************************* FIND OS...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND DB_SERVICE...START *********************************************************************************************************************************""" my_logger.debug("Calling db_service_validate(%s, %s, %s, %s)" %(d_count, param_list, service_loc, os_platform)) db_service = db_service_validate(d_count, param_list, service_loc, os_platform) my_logger.debug("Updating ttdb_dict with db_service") ttdb_dict['db_service'] = db_service """********************************************************************************************************************************* FIND DB_SERVICE...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND SOURCE_ENV ...START *********************************************************************************************************************************""" """******************* SOURCE_ENV: COPY *******************""" if db_operation == 'copy': my_logger.debug("Setting source_env for db_operation: %s."%db_operation) if (bdir_count != 0) or (rdir_count != 0): my_logger.error("Directory arguments [bdir/rdir] found. Use format [python dbUtil.py -s <source_env> -t <target_env> -o copy -d <db_service>] for copy operation. Exiting!") sys.exit("Directory arguments [bdir/rdir] found. Use format [python dbUtil.py -s <source_env> -t <target_env> -o copy -d <db_service>] for copy operation. Exiting!") elif not ((bdir_count != 0) or (rdir_count != 0)): if s_count == 0: print("Received no source flag. Setting active (production) environment as source") my_logger.debug("Received no source flag. Setting active (production) environment as source") source_env = active_env.split("-")[1] + "." + active_env.split("-")[0] + ".aws.3top.com" my_logger.debug("source_env: %s"%source_env) elif s_count == 1: my_logger.debug("Source flag found! Extracting source_env from list of arguments.") source_env = param_list[source_loc] my_logger.debug("source_env: %s"%source_env) else: my_logger.error("Unexpected error encountered in determining source_env. Exiting!") sys.exit("Unexpected error encountered in determining source_env. Exiting!") """******************* SOURCE_ENV: VALIDATE *******************""" source_env = env_validate(source_env) my_logger.info("The source_env has been validated!") if t_count == 0: my_logger.debug("Received no target flag! Exiting!") sys.exit("Received no target flag! Exiting!") elif t_count == 1: my_logger.debug("Target flag found! Extracting target_env from list of arguments.") target_env = param_list[target_loc] my_logger.debug("target_env: %s"%target_env) else: my_logger.error("Unexpected error encountered in determining target_env. Exiting!") sys.exit("Unexpected error encountered in determining target_env. Exiting!") my_logger.info("Received target: %s"%target_env) """******************* TARGET_ENV: VALIDATE *******************""" target_env = env_validate(target_env) my_logger.info("The target_env has been validated!") else: my_logger.error("Unexpected error encountered in determining flags/ arguments for copy. Exiting!") sys.exit("Unexpected error encountered in determining flags/ arguments for copy. Exiting!") my_logger.info("Updating ttdb_dict with source: %s"%source_env) ttdb_dict['source_env'] = source_env my_logger.info("Updating ttdb_dict with target: %s"%target_env) ttdb_dict['target_env'] = target_env elif db_operation == 'swap': my_logger.debug("Setting source_env for db_operation: %s."%db_operation) if (s_count != 0) or (t_count != 0) or (bdir_count != 0) or (rdir_count != 0): my_logger.error("Improper format. Use [python dbUtil.py -o swap -d <db_service>] for swap operation. Exiting!") sys.exit("Improper format. Use [python dbUtil.py -o swap -d <db_service>] for swap operation. Exiting!") elif not ((s_count != 0) or (t_count != 0) or (bdir_count != 0) or (rdir_count != 0)): my_logger.debug("Setting active (production) environment as source") source_env = active_env.split("-")[1] + "." + active_env.split("-")[0] + ".aws.3top.com" my_logger.debug("source_env: %s"%source_env) if source_env == 'a.prod.aws.3top.com': target_env = 'b.prod.aws.3top.com' elif source_env == 'b.prod.aws.3top.com': target_env = 'a.prod.aws.3top.com' else: my_logger.error("Cannot recognize source_env. Received: %s. Exiting!"%source_env) sys.exit("Cannot recognize source_env. Received: %s. Exiting!"%source_env) else: my_logger.error("Unexpected error encountered in determining flags/ arguments for swap-. Exiting!") sys.exit("Unexpected error encountered in determining flags/ arguments for swap. Exiting!") my_logger.info("Updating ttdb_dict with source: %s"%source_env) ttdb_dict['source_env'] = source_env my_logger.info("Updating ttdb_dict with target: %s"%target_env) ttdb_dict['target_env'] = target_env elif db_operation == 'backup': my_logger.debug("Setting source_env for db_operation: %s."%db_operation) if ((t_count != 0) or (rdir_count != 0) or (bdir_count == 0)): my_logger.error("Improper format found. Use [python dbUtil.py -s <source_env> -bdir <backup target directory> -o backup -d <db_service>] for backup operation. Exiting!") sys.exit("Improper format found. Use [python dbUtil.py -s <source_env> -bdir <backup target directory> -o backup -d <db_service>] for backup operation. Exiting!") elif not ((t_count != 0) or (rdir_count != 0)): if (s_count == 1): my_logger.debug("Source flag found! Extracting source_env from list of arguments.") source_env = param_list[source_loc] my_logger.debug("source_env: %s"%source_env) elif (s_count == 0): my_logger.debug("Received no source flag. Setting active (production) environment as source") source_env = active_env.split("-")[1] + "." + active_env.split("-")[0] + ".aws.3top.com" my_logger.debug("source_env: %s"%source_env) my_logger.info("Received source: %s"%source_env) """******************* SOURCE_ENV: VALIDATE *******************""" source_env = env_validate(source_env) my_logger.info("The source_env has been validated!") if bdir_count == 1: bdir = param_list[bdir_loc] my_logger.debug("Backup dir found as : %s"%bdir) if bdir == '.': pathname = os.getcwd() bdir = os.path.abspath(pathname) my_logger.debug("Backup dir will be: %s"%bdir) if not os.path.isdir(os.path.expanduser(bdir)): my_logger.debug("No backup dir found. Creating %s"%bdir) os.makedirs(bdir) my_logger.debug("%s created successfully!"%bdir) else: my_logger.error("Unexpected error encountered in determining source_env. Exiting!") sys.exit("Unexpected error encountered in determining source_env. Exiting!") else: my_logger.error("Unexpected error encountered in determining flags/ arguments for backup. Exiting!") sys.exit("Unexpected error encountered in determining flags/ arguments for backup. Exiting!") my_logger.info("Updating ttdb_dict with source: %s"%source_env) ttdb_dict['source_env'] = source_env my_logger.info("Updating ttdb_dict with target_dir: %s"%bdir) ttdb_dict['target_dir'] = bdir elif db_operation == 'restore': my_logger.debug("Setting source_env for db_operation: %s."%db_operation) if (s_count != 0) or (bdir_count != 0) or (rdir_count == 0): my_logger.error("Improper format found. Use [python dbUtil.py -rdir <restore source directory> -t <target_env> -o restore -d <db_service>] for restore operation. Exiting!") sys.exit("Improper format found. Use [python dbUtil.py -rdir <restore source directory> -t <target_env> -o restore -d <db_service>] for restore operation. Exiting!") elif not ((s_count != 0) or (bdir_count != 0)): if (t_count == 1): my_logger.debug("Target flag found! Extracting target_env from list of arguments.") target_env = param_list[target_loc] my_logger.debug("target_env: %s"%target_env) elif (t_count == 0): my_logger.error("No target flag found. Exiting!") sys.exit("No target flag found. Exiting!") my_logger.info("Received target: %s"%target_env) """******************* TARGET_ENV: VALIDATE *******************""" target_env = env_validate(target_env) my_logger.info("The target_env has been validated!") if (rdir_count == 1): rdir = param_list[rdir_loc] my_logger.debug("Restore dir found as : %s"%rdir) if rdir == '.': pathname = os.getcwd() rdir = os.path.abspath(pathname) my_logger.debug("Restore source dir will be: %s"%rdir) if not os.path.isdir(os.path.expanduser(rdir)): my_logger.error("No restore dir: %s found. Exiting!"%rdir) sys.exit("No restore dir: %s found. Exiting!"%rdir) else: my_logger.error("Unexpected error encountered in determining target_env. Exiting!") sys.exit("Unexpected error encountered in determining target_env. Exiting!") else: my_logger.error("Unexpected error encountered in determining flags/ arguments for restore. Exiting!") sys.exit("Unexpected error encountered in determining flags/ arguments for restore. Exiting!") my_logger.info("Updating ttdb_dict with source_dir: %s"%rdir) ttdb_dict['source_dir'] = rdir my_logger.info("Updating ttdb_dict with target: %s"%target_env) ttdb_dict['target_env'] = target_env my_logger.info("Returning to main() with ttdb_dict: %s"%ttdb_dict) return(ttdb_dict) """*********************************************************************************************************************************
def set_params(param_list): my_logger.debug("Received arguments: %s" % param_list) ttdb_dict = dict() s_count, t_count, o_count, d_count, bdir_count, rdir_count, p_count =\ 0, 0, 0, 0, 0, 0, 0 my_logger.debug("Extracting the parameters from command line arguments...") for i in range(0, len(param_list) - 1): if (param_list[i] == "-s"): s_count = s_count + 1 source_loc = i + 1 elif (param_list[i] == "-t"): t_count = t_count + 1 target_loc = i + 1 elif (param_list[i] == "-o"): o_count = o_count + 1 operation_loc = i + 1 elif (param_list[i] == "-d"): d_count = d_count + 1 service_loc = i + 1 elif (param_list[i] == "-bdir"): bdir_count = bdir_count + 1 bdir_loc = i + 1 elif (param_list[i] == "-rdir"): rdir_count = rdir_count + 1 rdir_loc = i + 1 elif (param_list[i] == "-p"): p_count = p_count + 1 p_loc = i + 1 my_logger.debug( "Received s_count: %s, t_count: %s, o_count: %s, p_count: %s" % (s_count, t_count, o_count, p_count)) my_logger.debug("Received d_count: %s, bdir_count: %s, rdir_count: %s" % (d_count, bdir_count, rdir_count)) if (s_count > 1) or (t_count > 1) or (o_count > 1) or (d_count > 1) or ( bdir_count > 1) or (rdir_count > 1) or (p_count > 1): my_logger.error("Multiple flags of same type detected. Exiting!") sys.exit("Multiple flags of same type detected. Exiting!") elif o_count == 0: my_logger.error("No db_operation found. Exiting!") print( "No db_operation found. Required format: python dbUtil.py -s <SOURCE_ENV> -t <TARGET_ENV> -o <DB_OPERATION> -d <DB_SERVICE> [optional: -p <PROD_OVERRIDE>] \n or python dbUtil.py -o swap -d <DB_SERVICE> [optional: -p <PROD_ENV>]." ) sys.exit("Please use correct format and run again. Exiting!") elif d_count == 0: my_logger.error("No db_service found. Exiting!") print( "No db_service found. Required format: python dbUtil.py -s <SOURCE_ENV> -t <TARGET_ENV> -o <DB_OPERATION> -d <DB_SERVICE> [optional: -p <PROD_OVERRIDE>] \n or python dbUtil.py -o swap -d <DB_SERVICE> [optional: -p <PROD_ENV>]." ) sys.exit("Please use correct format and run again. Exiting!") """********************************************************************************************************************************* FIND DB_OPERATION...START *********************************************************************************************************************************""" my_logger.debug("Calling operation_validate(%s, %s, %s)" % (o_count, param_list, operation_loc)) db_operation = db_operation_validate(o_count, param_list, operation_loc) my_logger.debug( "operation_validate() call successful! Received db_operation: %s" % db_operation) my_logger.debug("Inserting db_operation into ttdb_dict...") ttdb_dict['db_operation'] = db_operation """********************************************************************************************************************************* FIND DB_OPERATION...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* VALIDATE NUMBER OF ARGUMENTS...START *********************************************************************************************************************************""" my_logger.debug("Calling arg_valid_bool = arg_count_validate(%s, %s)" % (len(param_list), db_operation)) arg_valid_bool = arg_count_validate(len(param_list), db_operation) my_logger.debug( "arg_count_validate() call successful. Received arg_valid_bool: %s" % arg_valid_bool) if arg_valid_bool: my_logger.debug("Argument count is valid. Continuing!") else: my_logger.error("Argument count is invalid. Exiting!") sys.exit("Argument count is invalid. Exiting!") """********************************************************************************************************************************* VALIDATE NUMBER OF ARGUMENTS...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND ACTIVE ENVIRONMENT...START *********************************************************************************************************************************""" my_logger.debug("Determining active environment...") if p_count == 0: active_env = findActiveEnv() my_logger.debug("Active (production) environment determined as: %s" % active_env) elif p_count == 1: active_env = param_list[p_loc] my_logger.debug("Active (production) environment determined as: %s" % active_env) else: my_logger.error( "Unexpected error encountered in setting active environment. Exiting!" ) sys.exit( "Unexpected error encountered in setting active environment. Exiting!" ) """********************************************************************************************************************************* FIND ACTIVE ENVIRONMENT...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND OS...START *********************************************************************************************************************************""" my_logger.debug("Determining OS Platform information...") platform_info = platform.platform() my_logger.debug("Received platform_info: %s" % platform_info) if "Windows" in platform_info: os_platform = 'Windows' my_logger.debug("Platform determined as %s" % os_platform) elif "Linux" in platform_info: os_platform = 'Linux' my_logger.debug("Platform determined as %s" % os_platform) else: my_logger.debug("Cannot determine platform. Exiting!") sys.exit("Cannot determine platform. Exiting!") """********************************************************************************************************************************* FIND OS...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND DB_SERVICE...START *********************************************************************************************************************************""" my_logger.debug("Calling db_service_validate(%s, %s, %s, %s)" % (d_count, param_list, service_loc, os_platform)) db_service = db_service_validate(d_count, param_list, service_loc, os_platform) my_logger.debug("Updating ttdb_dict with db_service") ttdb_dict['db_service'] = db_service """********************************************************************************************************************************* FIND DB_SERVICE...STOP *********************************************************************************************************************************""" """********************************************************************************************************************************* FIND SOURCE_ENV ...START *********************************************************************************************************************************""" """******************* SOURCE_ENV: COPY *******************""" if db_operation == 'copy': my_logger.debug("Setting source_env for db_operation: %s." % db_operation) if (bdir_count != 0) or (rdir_count != 0): my_logger.error( "Directory arguments [bdir/rdir] found. Use format [python dbUtil.py -s <source_env> -t <target_env> -o copy -d <db_service>] for copy operation. Exiting!" ) sys.exit( "Directory arguments [bdir/rdir] found. Use format [python dbUtil.py -s <source_env> -t <target_env> -o copy -d <db_service>] for copy operation. Exiting!" ) elif not ((bdir_count != 0) or (rdir_count != 0)): if s_count == 0: print( "Received no source flag. Setting active (production) environment as source" ) my_logger.debug( "Received no source flag. Setting active (production) environment as source" ) source_env = active_env.split("-")[1] + "." + active_env.split( "-")[0] + ".aws.3top.com" my_logger.debug("source_env: %s" % source_env) elif s_count == 1: my_logger.debug( "Source flag found! Extracting source_env from list of arguments." ) source_env = param_list[source_loc] my_logger.debug("source_env: %s" % source_env) else: my_logger.error( "Unexpected error encountered in determining source_env. Exiting!" ) sys.exit( "Unexpected error encountered in determining source_env. Exiting!" ) """******************* SOURCE_ENV: VALIDATE *******************""" source_env = env_validate(source_env) my_logger.info("The source_env has been validated!") if t_count == 0: my_logger.debug("Received no target flag! Exiting!") sys.exit("Received no target flag! Exiting!") elif t_count == 1: my_logger.debug( "Target flag found! Extracting target_env from list of arguments." ) target_env = param_list[target_loc] my_logger.debug("target_env: %s" % target_env) else: my_logger.error( "Unexpected error encountered in determining target_env. Exiting!" ) sys.exit( "Unexpected error encountered in determining target_env. Exiting!" ) my_logger.info("Received target: %s" % target_env) """******************* TARGET_ENV: VALIDATE *******************""" target_env = env_validate(target_env) my_logger.info("The target_env has been validated!") else: my_logger.error( "Unexpected error encountered in determining flags/ arguments for copy. Exiting!" ) sys.exit( "Unexpected error encountered in determining flags/ arguments for copy. Exiting!" ) my_logger.info("Updating ttdb_dict with source: %s" % source_env) ttdb_dict['source_env'] = source_env my_logger.info("Updating ttdb_dict with target: %s" % target_env) ttdb_dict['target_env'] = target_env elif db_operation == 'swap': my_logger.debug("Setting source_env for db_operation: %s." % db_operation) if (s_count != 0) or (t_count != 0) or (bdir_count != 0) or (rdir_count != 0): my_logger.error( "Improper format. Use [python dbUtil.py -o swap -d <db_service>] for swap operation. Exiting!" ) sys.exit( "Improper format. Use [python dbUtil.py -o swap -d <db_service>] for swap operation. Exiting!" ) elif not ((s_count != 0) or (t_count != 0) or (bdir_count != 0) or (rdir_count != 0)): my_logger.debug( "Setting active (production) environment as source") source_env = active_env.split("-")[1] + "." + active_env.split( "-")[0] + ".aws.3top.com" my_logger.debug("source_env: %s" % source_env) if source_env == 'a.prod.aws.3top.com': target_env = 'b.prod.aws.3top.com' elif source_env == 'b.prod.aws.3top.com': target_env = 'a.prod.aws.3top.com' else: my_logger.error( "Cannot recognize source_env. Received: %s. Exiting!" % source_env) sys.exit( "Cannot recognize source_env. Received: %s. Exiting!" % source_env) else: my_logger.error( "Unexpected error encountered in determining flags/ arguments for swap-. Exiting!" ) sys.exit( "Unexpected error encountered in determining flags/ arguments for swap. Exiting!" ) my_logger.info("Updating ttdb_dict with source: %s" % source_env) ttdb_dict['source_env'] = source_env my_logger.info("Updating ttdb_dict with target: %s" % target_env) ttdb_dict['target_env'] = target_env elif db_operation == 'backup': my_logger.debug("Setting source_env for db_operation: %s." % db_operation) if ((t_count != 0) or (rdir_count != 0) or (bdir_count == 0)): my_logger.error( "Improper format found. Use [python dbUtil.py -s <source_env> -bdir <backup target directory> -o backup -d <db_service>] for backup operation. Exiting!" ) sys.exit( "Improper format found. Use [python dbUtil.py -s <source_env> -bdir <backup target directory> -o backup -d <db_service>] for backup operation. Exiting!" ) elif not ((t_count != 0) or (rdir_count != 0)): if (s_count == 1): my_logger.debug( "Source flag found! Extracting source_env from list of arguments." ) source_env = param_list[source_loc] my_logger.debug("source_env: %s" % source_env) elif (s_count == 0): my_logger.debug( "Received no source flag. Setting active (production) environment as source" ) source_env = active_env.split("-")[1] + "." + active_env.split( "-")[0] + ".aws.3top.com" my_logger.debug("source_env: %s" % source_env) my_logger.info("Received source: %s" % source_env) """******************* SOURCE_ENV: VALIDATE *******************""" source_env = env_validate(source_env) my_logger.info("The source_env has been validated!") if bdir_count == 1: bdir = param_list[bdir_loc] my_logger.debug("Backup dir found as : %s" % bdir) if bdir == '.': pathname = os.getcwd() bdir = os.path.abspath(pathname) my_logger.debug("Backup dir will be: %s" % bdir) if not os.path.isdir(os.path.expanduser(bdir)): my_logger.debug("No backup dir found. Creating %s" % bdir) os.makedirs(bdir) my_logger.debug("%s created successfully!" % bdir) else: my_logger.error( "Unexpected error encountered in determining source_env. Exiting!" ) sys.exit( "Unexpected error encountered in determining source_env. Exiting!" ) else: my_logger.error( "Unexpected error encountered in determining flags/ arguments for backup. Exiting!" ) sys.exit( "Unexpected error encountered in determining flags/ arguments for backup. Exiting!" ) my_logger.info("Updating ttdb_dict with source: %s" % source_env) ttdb_dict['source_env'] = source_env my_logger.info("Updating ttdb_dict with target_dir: %s" % bdir) ttdb_dict['target_dir'] = bdir elif db_operation == 'restore': my_logger.debug("Setting source_env for db_operation: %s." % db_operation) if (s_count != 0) or (bdir_count != 0) or (rdir_count == 0): my_logger.error( "Improper format found. Use [python dbUtil.py -rdir <restore source directory> -t <target_env> -o restore -d <db_service>] for restore operation. Exiting!" ) sys.exit( "Improper format found. Use [python dbUtil.py -rdir <restore source directory> -t <target_env> -o restore -d <db_service>] for restore operation. Exiting!" ) elif not ((s_count != 0) or (bdir_count != 0)): if (t_count == 1): my_logger.debug( "Target flag found! Extracting target_env from list of arguments." ) target_env = param_list[target_loc] my_logger.debug("target_env: %s" % target_env) elif (t_count == 0): my_logger.error("No target flag found. Exiting!") sys.exit("No target flag found. Exiting!") my_logger.info("Received target: %s" % target_env) """******************* TARGET_ENV: VALIDATE *******************""" target_env = env_validate(target_env) my_logger.info("The target_env has been validated!") if (rdir_count == 1): rdir = param_list[rdir_loc] my_logger.debug("Restore dir found as : %s" % rdir) if rdir == '.': pathname = os.getcwd() rdir = os.path.abspath(pathname) my_logger.debug("Restore source dir will be: %s" % rdir) if not os.path.isdir(os.path.expanduser(rdir)): my_logger.error("No restore dir: %s found. Exiting!" % rdir) sys.exit("No restore dir: %s found. Exiting!" % rdir) else: my_logger.error( "Unexpected error encountered in determining target_env. Exiting!" ) sys.exit( "Unexpected error encountered in determining target_env. Exiting!" ) else: my_logger.error( "Unexpected error encountered in determining flags/ arguments for restore. Exiting!" ) sys.exit( "Unexpected error encountered in determining flags/ arguments for restore. Exiting!" ) my_logger.info("Updating ttdb_dict with source_dir: %s" % rdir) ttdb_dict['source_dir'] = rdir my_logger.info("Updating ttdb_dict with target: %s" % target_env) ttdb_dict['target_env'] = target_env my_logger.info("Returning to main() with ttdb_dict: %s" % ttdb_dict) return (ttdb_dict) """*********************************************************************************************************************************