Example #1
0
def main():
    print("In main()...")
    
    """****************************************************************************************************************"""
    
        
        
    """ Collecting arguments into variables based on the format:
        db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)]
        start
        """
    #print("Collecting arguments into variables...")
    if length_of_args == 4:
        target_env = sys.argv[3]
    elif length_of_args==3:
        target_env = " "    
    else:
        sys.exit("Arguments format mismatch.  Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)].")
        #sys.exit("Arguments mismatch.  Exiting!")
        #sys.exit(-1)
    print("Received target_env: %s"%target_env)
    #print "target_env: ", target_env
    
    db_operation = sys.argv[1]
    print("Received db_operation: %s"%db_operation)
    #print"db_operation: ", db_operation
    
    db_service = sys.argv[2]
    print("Received db_service: %s"%db_service)
    #print"db_service: ",db_service
    
    """Collecting arguments into variables...stop"""
    """****************************************************************************************************************"""
    """ Validate certificate location...start"""
    
    #print("Calling \"validate_cert_loc()\"...")
    #AWS_MYSQL_CERT = validate_cert_loc()
    
    """ Validate certificate location...start"""
    """****************************************************************************************************************"""
    """ calling validate_args()...start"""
    
    #print("Calling \"validate_args()\"...")
    validate_args(db_operation, db_service, target_env)
    print("Validate args successful. Back in main()...")
    
    """ calling validate_args()...stop"""
    """****************************************************************************************************************"""
    """ calling set_env()...start"""
    
    #print("Calling \"set_env()\"...")
    (source_env, target_env)=set_env(db_operation, target_env)
    print("set_env successful. Back in main()... Received:: source_env: %s, target_env: %s. "%(source_env, target_env))
    
    """ calling set_env()...stop"""
    """****************************************************************************************************************"""
    """ calling validate_cert_loc()...start"""
    
    if ("aws.3top.com" in source_env) or ("aws.3top.com" in target_env):
        #print("Calling \"validate_cert_loc()\"...")
        AWS_MYSQL_CERT = validate_cert_loc()
        print("validate_cert_loc() successful. Back in main()... ")
    
    """ calling validate_cert_loc()...stop"""
    """****************************************************************************************************************"""
    """ calling set_host()...start"""
    
    #print("Calling \"set_host()\"...")
    if db_service == 'mysql':
        (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
        print("set_host successful. Back in main()... Received:: mysql_source_host: %s, mysql_target_host: %s."%(mysql_source_host, mysql_target_host))
    elif db_service == 'mongodb':
        (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
        print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host))
    elif db_service == 'all':
        (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
        (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
        print("set_host successful. Back in main()... Received:: mysql_source_host: %s, mysql_target_host: %s."%(mysql_source_host, mysql_target_host))
        print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host))
        
    """ calling set_host()...stop"""
    """****************************************************************************************************************"""
    
    
    """****************************************************************************************************************""" 
    """ Validate DB Accounts... start"""
    """ Validate Source Accounts... start"""
    #print("Validating source host..."),
    if db_service == 'mongodb':
        #print("Calling \"validate_mongodb_source_accounts\"...")
        validate_mongodb_source_accounts(mongodb_source_host)
    elif db_service == 'mysql':
        validate_mysql_source(AWS_MYSQL_CERT, mysql_source_host)
    elif db_service == 'all':
        validate_mongodb_source_accounts(mongodb_source_host)
        validate_mysql_source(AWS_MYSQL_CERT, mysql_source_host)
           
    """ Validate Source Accounts... stop"""
    """ Validate Target Accounts... start"""
    #print("Validating target host..."),
    if db_service == 'mongodb':
        #print("Calling \"validate_mongodb_target_accounts\"...")
        validate_mongodb_target_accounts(mongodb_target_host)
    elif db_service == 'mysql':
        if "nyc.3top.com" in mysql_target_host:
            validate_mysql_nyc_accounts(mysql_target_host)
        elif "aws.3top.com" in mysql_target_host:
            validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host)
    elif db_service == 'all':
        validate_mongodb_target_accounts(mongodb_target_host)
        if "nyc.3top.com" in mysql_target_host:
            validate_mysql_nyc_accounts(mysql_target_host)
        elif "aws.3top.com" in mysql_target_host:
            validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host)
          
    """ Validate Target Accounts... stop"""
    """ Validate DB Accounts... stop"""    
    """****************************************************************************************************************"""
    """********************************************************************************************************************"""
    """ Find current working directory path: python_root...start"""
    
    global python_root
    #print "Finding real path (working directory)...",
    python_root = os.path.dirname(os.path.realpath(__file__)) + "/"
    #print"python_root:",python_root,
    #print "found."
    
    """ Find current working directory path: python_root...stop"""
    """********************************************************************************************************************"""
    """ Create a timestamp directory to store log files...start"""
    
    print "Creating timestamp directory...",
    from ttLib.ttSys import dirCreateTimestamp
    _aws_swap_dir = PATH_ROOT + dict_ttSettings["PATH_LOG"] + "/swap"
    #print"_aws_swap_dir:", _aws_swap_dir
    #print "Creating timestamp directory...",
    global swapTimeStampDirPath
    swapTimeStampDirPath = dirCreateTimestamp(_aws_swap_dir)
    #print "swapTimeStampDirPath: ",swapTimeStampDirPath
    
    """ Create a timestamp directory to store log files...stop"""
    """********************************************************************************************************************"""
    """ Implement Logging...start"""
    
    print "Setting up logging...",
    import logging
    from ttLib.logger import get_handlers 
    log_handler_name='db_util'
    my_logger = logging.getLogger(log_handler_name)
    for h in my_logger.handlers:
        my_logger.removeHandler(h)
    log_file_name='db_util.log'
    log_file_abs_path = swapTimeStampDirPath + "/" + log_file_name
    #print"log_file_abs_path: ",log_file_abs_path
    for h in get_handlers(log_handler_name, log_file_abs_path):
        my_logger.addHandler(h)
    my_logger.setLevel(logging.DEBUG)
    #print "complete." 
    #print "\nLog and backup location: %s"%swapTimeStampDirPath
    my_logger.info("Logging configured successfully!")
    
    """ Implement Logging...stop"""
    """********************************************************************************************************************""" 
    """ Executing db_operation"""
    
    if db_service== "mongodb":
        print "Executing mongo_operations..."
        mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
    elif db_service == 'mysql':
        print "Executing mysql_operations..."
        mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
    elif db_service == 'all':
        print "Executing mongo_operations..."
        mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
        print "Executing mysql_operations..."
        mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
    
    """main() Module definition... start"""
    """main() Module definition... stop"""
    
    my_logger.info("Program execution complete. Exiting!")
    print "Program execution complete. Exiting!\nLogfile location: %s" %log_file_abs_path
Example #2
0
try:
    confirm_loglevel = raw_input(
        "\nCurrent loglevel is %s. Press [c/ C] to continue. To change the loglevel to 'DEBUG' enter [debug/ DEBUG]: "
        % loglevel)
    if confirm_loglevel.upper() == 'C':
        loglevel = "INFO"
    elif confirm_loglevel.upper() == "DEBUG":
        loglevel = "DEBUG"
    else:
        sys.exit("Incorrect entry received: %s. Exiting!" % confirm_loglevel)
except:
    sys.exit("Unexpected error encountered. Exiting!")
print "Received loglevel: %s" % loglevel

loglevel = getattr(logging, loglevel.upper())
for h in get_handlers(log_handler_name, log_file_abs_path):
    my_logger.addHandler(h)
my_logger.setLevel(loglevel)
my_logger.debug("Logger created successfully. Continuing...")
my_logger.debug("dict_ttSettings: " % dict_ttSettings)
print("Logging configured successfully!")
my_logger.info("Logging configured successfully. Initiating logging...")

try:
    from ttLib.ttAWS import env_ttSettings
except:
    my_logger.error(
        "\'from ttLib.ttAWS import env_ttSettings\'...failed. Exiting!")
    sys.exit("\'from ttLib.ttAWS import env_ttSettings\' failed. Exiting!")
my_logger.info("\'from ttLib.ttAWS import env_ttSettings\' successful!")
""" Implement Logging...stop"""
Example #3
0
log_file = dir_backup + '/dnsOps.log'
loglevel = dict_ttSettings["log_level"]
try:
    confirm_loglevel = raw_input("\nCurrent loglevel is %s. Press [c/ C] to continue. To change the loglevel to 'DEBUG' enter [debug/ DEBUG]: "%loglevel)
    if confirm_loglevel.upper() == 'C':
        loglevel = "INFO"
    elif confirm_loglevel.upper() == "DEBUG":
        loglevel = "DEBUG"
    else:
        sys.exit("Incorrect entry received: %s. Exiting!"%confirm_loglevel)
except:
    sys.exit("Unexpected error encountered. Exiting!")
print"Received loglevel: %s"%loglevel
    
loglevel = getattr(logging, loglevel.upper())
for h in logger.get_handlers('dnsOps', log_file):
    my_logger.addHandler(h)
my_logger.setLevel(loglevel)
print"Logger created successfully. Continuing..."
my_logger.debug("Logger created successfully. Continuing...")
my_logger.debug("dict_ttSettings: "%dict_ttSettings)
global swapTimeStampDirPath
import ttLib.ttAWS as ttAWS
import ttLib.ttWin as ttWin

host_winsys = dict_ttSettings["service"]["winsys"]["hostname"]
host_winsys_username = dict_ttSettings["service"]["winsys"]["username"]
host_winsys_password = dict_ttSettings["service"]["winsys"]["password"]
host_windns = dict_ttSettings["service"]["dns"]["hostname"]
REGION_NAME = dict_ttSettings["aws"]["REGION_NAME"]
zone_AWS_long = dict_ttSettings["zone_AWS_long"]
Example #4
0
def main():
    print("In main()...")
    
    """****************************************************************************************************************"""
    length_of_args=len(sys.argv)
    if length_of_args==0:
        print "No arguments found. Use the format: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)]"
        sys.exit("Exiting!")
        
        
    """ Collecting arguments into variables based on the format:
        db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)]
        start
        """
    print("Collecting arguments into variables...")
    if length_of_args == 4:
        target_env = sys.argv[3]
    elif length_of_args==3:
        target_env = " "    
    else:
        print("Arguments mismatch. Exiting!")
        sys.exit(-1)
    print("Received target_env: %s"%target_env)
    #print "target_env: ", target_env
    
    db_operation = sys.argv[1]
    print("Received db_operation: %s"%db_operation)
    #print"db_operation: ", db_operation
    
    db_service = sys.argv[2]
    print("Received db_service: %s"%db_service)
    #print"db_service: ",db_service
    
    """Collecting arguments into variables...stop"""
    """****************************************************************************************************************"""
    """****************************************************************************************************************"""
    """ Validate certificate location...start"""
    
    #print("Calling \"validate_cert_loc()\"...")
    #AWS_MYSQL_CERT = validate_cert_loc()
    
    """ Validate certificate location...start"""
    """****************************************************************************************************************"""
    """****************************************************************************************************************"""
    """ calling validate_args()...start"""
    
    print("Calling \"validate_args()\"...")
    validate_args(db_operation, db_service, target_env)
    print("Validate args successful. Back in main()...")
    
    """ calling validate_args()...stop"""
    """****************************************************************************************************************"""
    
    """****************************************************************************************************************"""
    """ calling set_env()...start"""
    
    print("Calling \"set_env()\"...")
    (source_env, target_env)=set_env(db_operation, target_env)
    print("set_env successful. Back in main()... Received:: source_env: %s, target_env: %s. "%(source_env, target_env))
    
    """ calling set_env()...stop"""
    """****************************************************************************************************************"""
    
    """****************************************************************************************************************"""
    """ calling validate_cert_loc()...start"""
    
    if ("aws.3top.com" in source_env) or ("aws.3top.com" in target_env):
        print("Calling \"validate_cert_loc()\"...")
        AWS_MYSQL_CERT = validate_cert_loc()
        print("validate_cert_loc() successful. Back in main()... ")
    
    """ calling validate_cert_loc()...stop"""
    """****************************************************************************************************************"""
    
    """****************************************************************************************************************"""
    """ calling set_host()...start"""
    print("Calling \"set_host()\"...")
    if db_service == 'mysql':
        (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
    elif db_service == 'mongodb':
        (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
    elif db_service == 'all':
        (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
        (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
        
    print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host))
    """ calling set_host()...stop"""
    """****************************************************************************************************************"""
    
    
    """****************************************************************************************************************""" 
    """ Validate DB Accounts... start"""
    """ Validate Source Accounts... start"""
    print("Validating source host..."),
    if db_service == 'mongodb':
        print("Calling \"validate_mongodb_source_accounts\"...")
        validate_mongodb_source_accounts(mongodb_source_host)
    elif db_service == 'mysql':
        validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_source_host)
    elif db_service == 'all':
        validate_mongodb_source_accounts(mongodb_source_host)
        validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_source_host)
           
    """ Validate Source Accounts... stop"""
    """ Validate Target Accounts... start"""
    print("Validating target host..."),
    if db_service == 'mongodb':
        print("Calling \"validate_mongodb_target_accounts\"...")
        validate_mongodb_target_accounts(mongodb_target_host)
    elif db_service == 'mysql':
        if "nyc.3top.com" in mysql_target_host:
            validate_mysql_nyc_accounts(mysql_target_host)
        elif "aws.3top.com" in mysql_target_host:
            validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host)
    elif db_service == 'all':
        validate_mongodb_target_accounts(mongodb_target_host)
        if "nyc.3top.com" in mysql_target_host:
            validate_mysql_nyc_accounts(mysql_target_host)
        elif "aws.3top.com" in mysql_target_host:
            validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host)
          
    """ Validate Target Accounts... stop"""
    """ Validate DB Accounts... stop"""    
    """****************************************************************************************************************"""
    """********************************************************************************************************************"""
    """ Find current working directory path: python_root...start"""
    
    global python_root
    print "Finding real path (working directory)...",
    python_root = os.path.dirname(os.path.realpath(__file__)) + "/"
    #print"python_root:",python_root,
    print "found."
    
    """ Find current working directory path: python_root...stop"""
    """********************************************************************************************************************"""
    """ Create a timestamp directory to store log files...start"""
    
    print "Creating timestamp directory...",
    from ttLib.ttSys import dirCreateTimestamp
    _aws_swap_dir = PATH_ROOT + dict_ttSettings["PATH_LOG"] + "/swap"
    #print"_aws_swap_dir:", _aws_swap_dir
    print "Creating timestamp directory...",
    global swapTimeStampDirPath
    swapTimeStampDirPath = dirCreateTimestamp(_aws_swap_dir)
    #print "swapTimeStampDirPath: ",swapTimeStampDirPath
    
    """ Create a timestamp directory to store log files...stop"""
    """********************************************************************************************************************"""
    """ Implement Logging...start"""
    
    print "Setting up logging...",
    import logging
    from ttLib.logger import get_handlers 
    log_handler_name='db_util'
    my_logger = logging.getLogger(log_handler_name)
    for h in my_logger.handlers:
        my_logger.removeHandler(h)
    log_file_name='db_util.log'
    log_file_abs_path = swapTimeStampDirPath + "/" + log_file_name
    #print"log_file_abs_path: ",log_file_abs_path
    for h in get_handlers(log_handler_name, log_file_abs_path):
        my_logger.addHandler(h)
    my_logger.setLevel(logging.DEBUG)
    print "complete." 
    #print "\nLog and backup location: %s"%swapTimeStampDirPath
    my_logger.info("Logging configured successfully!")
    
    """ Implement Logging...stop"""
    """********************************************************************************************************************""" 
    """ Executing db_operation"""
    
    if db_service== "mongodb":
        mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger)
        my_logger.info("MongoDB operations completed successfully")
    elif db_service == 'mysql':
        mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger)
        my_logger.info("MySQL operations completed successfully")
    elif db_service == 'all':
        mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger)
        my_logger.info("MongoDB operations completed successfully")
        mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger)
        my_logger.info("MySQL operations completed successfully")
    
    """main() Module definition... start"""
    """main() Module definition... stop"""
    
    my_logger.info("Program execution complete. Exiting!")
    print "Program execution complete. Exiting!\nLogfile location: %s" %swapTimeStampDirPath
Example #5
0
except:
    sys.exit("Error Encountered: \"from ttLib.logger import get_handlers\"...failed. Exiting!")

    
log_handler_name='dbUtil'
my_logger = logging.getLogger(log_handler_name)
for h in my_logger.handlers:
    my_logger.removeHandler(h)
log_file_name='mysqlUsers.log'
log_file_abs_path = swapTimeStampDirPath + "/" + log_file_name
#print"log_file_abs_path: ",log_file_abs_path
loglevel = dict_sys_ttSettings["log_level"].upper()
print"Received loglevel: %s"%loglevel

loglevel = getattr(logging, loglevel.upper())
for h in get_handlers(log_handler_name, log_file_abs_path):
    my_logger.addHandler(h)
my_logger.setLevel(loglevel)
my_logger.debug("Logger created successfully. Continuing...")
my_logger.debug("dict_sys_ttSettings: %s"%dict_sys_ttSettings)
print("Logging configured successfully!")
my_logger.info("Logging configured successfully. Initiating logging...")

print "\nLogfile Location: %s\n"%log_file_abs_path
from ttLib.ttAWS import env_ttSettings
from ttLib.ttLx import callSubprocess



def mysql_user_create():
    env_name = raw_input("Enter environment name (e.g., a.dev.aws.3top.com): ")
Example #6
0
try:
    confirm_loglevel = raw_input(
        "\nCurrent loglevel is %s. Press [c/ C] to continue. To change the loglevel to 'DEBUG' enter [debug/ DEBUG]: "
        % loglevel)
    if confirm_loglevel.upper() == 'C':
        loglevel = "INFO"
    elif confirm_loglevel.upper() == "DEBUG":
        loglevel = "DEBUG"
    else:
        sys.exit("Incorrect entry received: %s. Exiting!" % confirm_loglevel)
except:
    sys.exit("Unexpected error encountered. Exiting!")
print "Received loglevel: %s" % loglevel

loglevel = getattr(logging, loglevel.upper())
for h in logger.get_handlers('dnsOps', log_file):
    my_logger.addHandler(h)
my_logger.setLevel(loglevel)
print "Logger created successfully. Continuing..."
my_logger.debug("Logger created successfully. Continuing...")
my_logger.debug("dict_ttSettings: " % dict_ttSettings)
global swapTimeStampDirPath
import ttLib.ttAWS as ttAWS
import ttLib.ttWin as ttWin

host_winsys = dict_ttSettings["service"]["winsys"]["hostname"]
host_winsys_username = dict_ttSettings["service"]["winsys"]["username"]
host_winsys_password = dict_ttSettings["service"]["winsys"]["password"]
host_windns = dict_ttSettings["service"]["dns"]["hostname"]
REGION_NAME = dict_ttSettings["aws"]["REGION_NAME"]
zone_AWS_long = dict_ttSettings["zone_AWS_long"]