Exemple #1
0
def findActiveEnv():
    my_logger.debug("Finding active environment...")
    try:
        my_logger.debug("Evaluating fp_internal_dns....")
        dns_int = ttLx.callSubprocess(_fp_dns_internal_cmd)
        _fp_dns_internal = dns_int.split("\n")[2]
        my_logger.debug("fp_dns_internal: %s" % _fp_dns_internal)
        my_logger.debug("Evaluating fp_external_dns....")
        dns_ext = ttLx.callSubprocess(_fp_dns_external_cmd)
        _fp_dns_external = dns_ext.split("\n")[1]
        my_logger.debug("fp_dns_external: %s" % _fp_dns_external)
        my_logger.debug("Evaluating _fp_live.....")
        live = ttLx.callSubprocess(_fp_live_cmd)
        _fp_live = live.split("\n")[0][3]
        my_logger.debug("fp_live: %s" % _fp_live)
        my_logger.debug("Evaluating _fp_live_dns.....")
        live_dns = ttLx.callSubprocess(_fp_live_dns_cmd)
        _fp_live_dns = live_dns.split("\n")[0]
        my_logger.debug("live_dns: %s" % _fp_live_dns)
    
        """
        ORIGINAL CODE WITH EXTERNAL AND INTERNAL CHECK
        **********************************************
        if _fp_dns_internal != _fp_dns_external:
            my_logger.error("The Internal Active Directory DNS and external AWS Route 53 DNS servers think different environments are live!  Internal DNS says %s and external says %s. EXITING!" %(_fp_dns_internal, _fp_dns_external))
            sys.exit("ERROR: The Internal Active Directory DNS and external AWS Route 53 DNS servers think different environments are live!  Internal DNS says %s and external says %s. EXITING!" %(_fp_dns_internal, _fp_dns_external))
        else:
            if _fp_live != "a" and _fp_live != "b":
                my_logger.error("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
                sys.exit("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
            else:
                if _fp_live == "a":
                    _copy_source_prefix = "prod-a"
                elif _fp_live == "b": 
                    _copy_source_prefix = "prod-b"
        """
        
        """
        NEW CODE W/O EXTERNAL AND INTERNAL CHECK START
        **********************************************
        """
        if _fp_live != "a" and _fp_live != "b":
            my_logger.error("Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
            sys.exit("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
        else:
            if _fp_live == "a":
                _copy_source_prefix = "prod-a"
            elif _fp_live == "b": 
                _copy_source_prefix = "prod-b"
        """
        NEW CODE W/O EXTERNAL AND INTERNAL CHECK STOP
        **********************************************
        """
        
    except:
        my_logger.error("Unexpected Error Encountered. Exiting!")
        sys.exit("Unexpected Error Encountered. Exiting!")
    my_logger.debug("Returning to main() with _copy_source_prefix: %s" % _copy_source_prefix)
    return _copy_source_prefix
Exemple #2
0
def findActiveEnv():
    my_logger.debug("Finding active environment...")
    try:
        my_logger.debug("Evaluating fp_internal_dns....")
        dns_int = ttLx.callSubprocess(_fp_dns_internal_cmd)
        _fp_dns_internal = dns_int.split("\n")[2]
        my_logger.debug("fp_dns_internal: %s" % _fp_dns_internal)
        my_logger.debug("Evaluating fp_external_dns....")
        dns_ext = ttLx.callSubprocess(_fp_dns_external_cmd)
        _fp_dns_external = dns_ext.split("\n")[1]
        my_logger.debug("fp_dns_external: %s" % _fp_dns_external)
        my_logger.debug("Evaluating _fp_live.....")
        live = ttLx.callSubprocess(_fp_live_cmd)
        _fp_live = live.split("\n")[0][3]
        my_logger.debug("fp_live: %s" % _fp_live)
        my_logger.debug("Evaluating _fp_live_dns.....")
        live_dns = ttLx.callSubprocess(_fp_live_dns_cmd)
        _fp_live_dns = live_dns.split("\n")[0]
        my_logger.debug("live_dns: %s" % _fp_live_dns)
    
        """
        ORIGINAL CODE WITH EXTERNAL AND INTERNAL CHECK
        **********************************************
        if _fp_dns_internal != _fp_dns_external:
            my_logger.error("The Internal Active Directory DNS and external AWS Route 53 DNS servers think different environments are live!  Internal DNS says %s and external says %s. EXITING!" %(_fp_dns_internal, _fp_dns_external))
            sys.exit("ERROR: The Internal Active Directory DNS and external AWS Route 53 DNS servers think different environments are live!  Internal DNS says %s and external says %s. EXITING!" %(_fp_dns_internal, _fp_dns_external))
        else:
            if _fp_live != "a" and _fp_live != "b":
                my_logger.error("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
                sys.exit("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
            else:
                if _fp_live == "a":
                    _copy_source_prefix = "prod-a"
                elif _fp_live == "b": 
                    _copy_source_prefix = "prod-b"
        """
        
        """
        NEW CODE W/O EXTERNAL AND INTERNAL CHECK START
        **********************************************
        """
        if _fp_live != "a" and _fp_live != "b":
            my_logger.error("Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
            sys.exit("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
        else:
            if _fp_live == "a":
                _copy_source_prefix = "prod-a"
            elif _fp_live == "b": 
                _copy_source_prefix = "prod-b"
        """
        NEW CODE W/O EXTERNAL AND INTERNAL CHECK STOP
        **********************************************
        """
        
    except:
        my_logger.error("Unexpected Error Encountered. Exiting!")
        sys.exit("Unexpected Error Encountered. Exiting!")
    my_logger.debug("Returning to main() with _copy_source_prefix: %s" % _copy_source_prefix)
    return _copy_source_prefix
Exemple #3
0
def awsmysqlclone(aws_cert, source_hostname, target_hostname, my_logger):
    my_logger.info("In awsmysqlclone()...")
    #print "awsmysqlclone start"
    drop_args="mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"DROP DATABASE IF EXISTS ebdb\""
    #mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --force --ssl-ca=" + aws_cert+ " --host=" + target_hostname + " --port=3306 -e \"DROP DATABASE IF EXISTS ebdb\""
    #print drop_args
    try:
        clone_drop_out=callSubprocess(drop_args)        
    except:
        e = str(sys.exc_info())
        my_logger.info("Error encountered in awsmysqlclone_drop table: %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %swapTimeStampDirPath)
        sys.exit(-1)
    #print "drop success"
    my_logger.info("Drop database success!")

    create_args="mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"CREATE DATABASE IF NOT EXISTS ebdb\""
                                                                                                                                                                
    #print create_args
    try:
        clone_create_out=callSubprocess(create_args)        
    except:
        e = str(sys.exc_info())
        my_logger.info("Error encountered in awsmysqlclone_create table: %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %swapTimeStampDirPath)
        sys.exit(-1)
    #print "create success"
    my_logger.info("Create database success! Output: %s"%clone_create_out)
    
    priv_args1="mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"USE ebdb; GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'replnyc'@'%' IDENTIFIED BY \'" + dict_ttSettings["_aws_rds_replpass"] + "\'; FLUSH PRIVILEGES;\" "
    #print priv_args1
    try:
        clone_priv_out=callSubprocess(priv_args1)            
    except:
        e = str(sys.exc_info())
        my_logger.info("Error encountered in awsmysqlclone_grant privileges: %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %swapTimeStampDirPath)
        sys.exit(-1)  
    #print "grant success"
    my_logger.info( "Grant privileges success!")
    final_clone="mysqldump --user=replnyc -p" + dict_ttSettings["_aws_rds_replpass"] + " --ssl-ca=" + aws_cert + " --host=" + source_hostname + " --port=3306 --single-transaction=TRUE ebdb | mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"]  + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 ebdb"
    #print final_clone
    #final_clone_out=callSubprocess(final_clone)
    try:
        os.system(final_clone)   
    except:
        e = str(sys.exc_info())
        my_logger.info("Error Encountered %s. Exiting...."%e)
        print("Error encountered awsmysqlclone_final_clone. Exiting! Logfile location: %s" %swapTimeStampDirPath)
        sys.exit(-1)
    #print "clone success"
    my_logger.info("MySQL Clone success!")
    return("Returning to mysql_operations()")
Exemple #4
0
def awsmysqlclone(aws_cert, source_hostname, target_hostname, my_logger, log_file):
    my_logger.info("In awsmysqlclone()...")
    #print "awsmysqlclone start"
    drop_args="mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"DROP DATABASE IF EXISTS ebdb\""
    #mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --force --ssl-ca=" + aws_cert+ " --host=" + target_hostname + " --port=3306 -e \"DROP DATABASE IF EXISTS ebdb\""
    #print drop_args
    try:
        clone_drop_out=callSubprocess(drop_args)        
    except:
        e = str(sys.exc_info())
        my_logger.info("Error encountered in awsmysqlclone_drop table: %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %log_file)
        sys.exit(-1)
    #print "drop success"
    my_logger.info("Drop database success!")

    create_args="mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"CREATE DATABASE IF NOT EXISTS ebdb\""
                                                                                                                                                                
    #print create_args
    try:
        clone_create_out=callSubprocess(create_args)        
    except:
        e = str(sys.exc_info())
        my_logger.info("Error encountered in awsmysqlclone_create table: %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %log_file)
        sys.exit(-1)
    #print "create success"
    my_logger.info("Create database success! Output: %s"%clone_create_out)
    
    priv_args1="mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"USE ebdb; GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'replnyc'@'%' IDENTIFIED BY \'" + dict_ttSettings["_aws_rds_replpass"] + "\'; FLUSH PRIVILEGES;\" "
    #print priv_args1
    try:
        clone_priv_out=callSubprocess(priv_args1)            
    except:
        e = str(sys.exc_info())
        my_logger.info("Error encountered in awsmysqlclone_grant privileges: %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %log_file)
        sys.exit(-1)  
    #print "grant success"
    my_logger.info( "Grant privileges success!")
    final_clone="mysqldump --user=replnyc -p" + dict_ttSettings["_aws_rds_replpass"] + " --ssl-ca=" + aws_cert + " --host=" + source_hostname + " --port=3306 --single-transaction=TRUE ebdb | mysql --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"]  + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 ebdb"
    #print final_clone
    #final_clone_out=callSubprocess(final_clone)
    try:
        os.system(final_clone)   
    except:
        e = str(sys.exc_info())
        my_logger.info("Error Encountered %s. Exiting...."%e)
        print("Error encountered awsmysqlclone_final_clone. Exiting! Logfile location: %s" %log_file)
        sys.exit(-1)
    #print "clone success"
    my_logger.info("MySQL Clone success!")
    return("Returning to mysql_operations()")
Exemple #5
0
def mongoclone(s_host, t_host, my_logger, log_file):
    my_logger.info(" In mongoclone()...")
    try:
        filename = "mongoclone.js"
        filepath = os.path.join(swapTimeStampDirPath, filename)
        my_logger.info("Create file success! %s " % filename)
        f = open(filepath, "wb")
        f.write("printjson(db = db.getSiblingDB('apis_cache'));")
        f.write("\nprintjson(db.getCollectionNames());")
        f.write("\nprintjson(db.dropDatabase());")
        f.write(
            "\nprintjson(db.copyDatabase (\"apis_cache\", \"apis_cache\", \"%s\", \"%s\", \"%s\"));"
            % (s_host, dict_ttSettings["aws_mongo_dbUser"],
               dict_ttSettings["aws_mongo_dbUser_password"]))
        f.write("\nprintjson(db.getCollectionNames());")
        f.close()
        clone_cmd = "mongo admin -u " + dict_ttSettings["mongodb"]["dba"][
            "username"] + " -p " + dict_ttSettings["mongodb"]["dba"][
                "password"] + " --host " + t_host + " --verbose --port 27017 " + filepath
        #print clone_cmd
        clone_OP = callSubprocess(clone_cmd)
    except:
        my_logger.info("Error encountered. Exiting! %s" % str(sys.exc_info()))
        sys.exit("Arguments mismatch. Exiting! \nLogfile location: %s" %
                 log_file)
    my_logger.info("Mongodump successful. \nOutput Received: %s" % clone_OP)
Exemple #6
0
def validate_mongodb_target_accounts(t_host):
    for k, v in dict_ttSettings["mongodb"].items():
        try:
            #print v["username"] , v["password"]
            conn_cmd="mongo " + t_host + ":27017/admin -u " + v["username"] + " -p " + v["password"] + " --eval \"printjson(db.getCollectionNames());\""
            conn_out=callSubprocess(conn_cmd)
        except:
            sys.exit("NYC account for %s cannot be validated. Error Encountered: %s. Exiting!" %(v["username"] , str(sys.exc_info())))
Exemple #7
0
def validate_mongodb_source_accounts(s_host):
    try:
        conn_cmd="mongo " + s_host + ":27017/apis_cache -u "+ dict_ttSettings["aws_mongo_dbUser"] + " -p " + dict_ttSettings["aws_mongo_dbUser_password"] + " --eval \"printjson(db.getCollectionNames());\""
        conn_out=callSubprocess(conn_cmd)
    except:
        print("NYC account for %s cannot be validated. Error Encountered: %s. Exiting!" %(dict_ttSettings["aws_mongo_dbUser"] , str(sys.exc_info())))
        sys.exit(-1)
    print("Connection Successful for user: %s. \nConnection Output: \n%s!"%(dict_ttSettings["aws_mongo_dbUser"] ,conn_out))
    print("Accounts validation successful for service: MongoDB !")
Exemple #8
0
def validate_mysql_nyc_accounts(target_hostname):
    #import MySQLdb
    for k,v in dict_ttSettings["mysql"].items():
        try:
            conn_cmd="mysql --user="******"username"] + " -p" + v["password"] + " --host=" + target_hostname + " --port=3306 -e \"CONNECT;\""
            conn_out=callSubprocess(conn_cmd)
        except:
            e = str(sys.exc_info())
            print("Error Encountered: %s. Exiting!" %e)
            sys.exit(-1)
Exemple #9
0
def validate_mysql_source(aws_cert, source_hostname):
    try:
        #print("In validate_mysql_source()...")
        val_s_cmd="mysql --user=replnyc -p" + dict_ttSettings["_aws_rds_replpass"] + " --ssl-ca=" + aws_cert + " --host=" + source_hostname + " --port=3306 -e \"CONNECT;\""
        val_s_cmd_out=callSubprocess(val_s_cmd)
    except:
        e = str(sys.exc_info())
        sys.exit("Encountered Error in mysqldump(): %s. Exiting!" %e)
        
    return("Accounts validation successful for service: MySQL source with output: %s"%val_s_cmd_out)
Exemple #10
0
def validate_mongodb_source_accounts(s_host):
    try:
        conn_cmd = "mongo " + s_host + ":27017/apis_cache -u " + dict_ttSettings[
            "aws_mongo_dbUser"] + " -p " + dict_ttSettings[
                "aws_mongo_dbUser_password"] + " --eval \"printjson(db.getCollectionNames());\""
        conn_out = callSubprocess(conn_cmd)
    except:
        sys.exit(
            "NYC account for %s cannot be validated. Error Encountered: %s. Exiting!"
            % (dict_ttSettings["aws_mongo_dbUser"], str(sys.exc_info())))
Exemple #11
0
def validate_mongodb_target_accounts(t_host):
    for k, v in dict_ttSettings["mongodb"].items():
        try:
            #print v["username"] , v["password"]
            conn_cmd="mongo " + t_host + ":27017/admin -u " + v["username"] + " -p " + v["password"] + " --eval \"printjson(db.getCollectionNames());\""
            conn_out=callSubprocess(conn_cmd)
        except:
            print("NYC account for %s cannot be validated. Error Encountered: %s. Exiting!" %(v["username"] , str(sys.exc_info())))
            sys.exit(-1)
        print("Connection Successful for %s user: %s. \nConnection Output: \n%s!"%(k, v["username"] ,conn_out))
    print("Accounts validation successful for service: MongoDB !")
Exemple #12
0
def validate_mysql_nyc_accounts(target_hostname):
    #import MySQLdb
    for k, v in dict_ttSettings["mysql"].items():
        try:
            conn_cmd = "mysql --user="******"username"] + " -p" + v[
                "password"] + " --host=" + target_hostname + " --port=3306 -e \"CONNECT;\""
            conn_out = callSubprocess(conn_cmd)
        except:
            e = str(sys.exc_info())
            print("Error Encountered: %s. Exiting!" % e)
            sys.exit(-1)
Exemple #13
0
def validate_mongodb_target_accounts(t_host):
    for k, v in dict_ttSettings["mongodb"].items():
        try:
            #print v["username"] , v["password"]
            conn_cmd = "mongo " + t_host + ":27017/admin -u " + v[
                "username"] + " -p " + v[
                    "password"] + " --eval \"printjson(db.getCollectionNames());\""
            conn_out = callSubprocess(conn_cmd)
        except:
            sys.exit(
                "NYC account for %s cannot be validated. Error Encountered: %s. Exiting!"
                % (v["username"], str(sys.exc_info())))
Exemple #14
0
def validate_mysql_source(aws_cert, source_hostname):
    try:
        #print("In validate_mysql_source()...")
        val_s_cmd = "mysql --user=replnyc -p" + dict_ttSettings[
            "_aws_rds_replpass"] + " --ssl-ca=" + aws_cert + " --host=" + source_hostname + " --port=3306 -e \"CONNECT;\""
        val_s_cmd_out = callSubprocess(val_s_cmd)
    except:
        e = str(sys.exc_info())
        sys.exit("Encountered Error in mysqldump(): %s. Exiting!" % e)

    return (
        "Accounts validation successful for service: MySQL source with output: %s"
        % val_s_cmd_out)
Exemple #15
0
 def findActiveEnv():
     my_logger.info("In ttAWS.findActiveEnv....")
     try:
         my_logger.info("Evaluating fp_internal_dns....")
         dns_int=ttLx.callSubprocess(_fp_dns_internal_cmd)
         _fp_dns_internal= dns_int.split("\n")[2]
         my_logger.info("fp_dns_internal: %s" % _fp_dns_internal)
         my_logger.info("Evaluating fp_external_dns....")
         dns_ext=ttLx.callSubprocess(_fp_dns_external_cmd)
         _fp_dns_external=dns_ext.split("\n")[1]
         my_logger.info("fp_dns_external: %s" % _fp_dns_external)
         my_logger.info("Evaluating _fp_live.....")
         live=ttLx.callSubprocess(_fp_live_cmd)
         _fp_live= live.split("\n")[0][3]
         my_logger.info("fp_live: %s" % _fp_live)
         my_logger.info("Evaluating _fp_live_dns.....")
         live_dns=ttLx.callSubprocess(_fp_live_dns_cmd)
         _fp_live_dns=live_dns.split("\n")[0]
         my_logger.info("live_dns: %s" % _fp_live_dns)
     
         if _fp_dns_internal != _fp_dns_external:
             my_logger.error("ERROR: The Internal Active Directory DNS and external AWS Route 53 DNS servers think different environments are live!  Internal DNS says %s and external says %s. EXITING!" %(_fp_dns_internal, _fp_dns_external))
             sys.exit(-1)
         else:
             if _fp_live != "a" and _fp_live != "b":
                 my_logger.error("ERROR: Could not resolve which prod environment is live, A or B. Script got %s from %s. EXITING!" %(_fp_live,_fp_live_dns))
                 sys.exit(-1)
             else:
                 if _fp_live == "a":
                     _copy_source_prefix="prod-a"
                 elif _fp_live == "b": 
                     _copy_source_prefix="prod-b"
     
         my_logger.info("_copy_source_prefix: %s" % _copy_source_prefix)
         return _copy_source_prefix
     except:
         e = sys.exc_info()[0]
         my_logger.info("Error Encountered %s. Exiting...." % e )
         sys.exit(-1)
def mysql_user_create():
    env_name = raw_input("Enter environment name (e.g., a.dev.aws.3top.com): ")
    if "aws.3top.com" in env_name:
        hostname = "fp-rds-1." + env_name
    elif "nyc.3top.com" in env_name:
        hostname = env_name
    dict_ttSettings = env_ttSettings(env_name)
    
    ebroot_password = raw_input("Enter ebroot password: "******"aws.3top.com" in hostname:
        cert = dict_ttSettings["mysql"]["certs"]["public"]
        dba_arg = "mysql --user=ebroot -p" + ebroot_password + " --ssl-ca=" + os.path.expanduser(cert)  + " --host=" + hostname + " --port=3306 -e \"GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, GRANT OPTION, INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, SELECT, SHOW DATABASES, SHOW VIEW, TRIGGER, UPDATE ON *.* TO '" + dict_ttSettings["mysql"]["users"]["dba"]["username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings["mysql"]["users"]["dba"]["password"] + "\'; FLUSH PRIVILEGES;\" "
        
        r_arg = "mysql --user=ebroot -p" + ebroot_password + " --ssl-ca=" + os.path.expanduser(cert)  + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings["mysql"]["users"]["r"]["username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings["mysql"]["users"]["r"]["password"] + "\'; FLUSH PRIVILEGES;\" "
        
        rw_arg = "mysql --user=ebroot -p" + ebroot_password + " --ssl-ca=" + os.path.expanduser(cert)  + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, INSERT, UPDATE, EXECUTE, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings["mysql"]["users"]["rw"]["username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings["mysql"]["users"]["rw"]["password"] + "\'; FLUSH PRIVILEGES;\" "
    
    elif "nyc.3top.com" in hostname:
        dba_arg = "mysql --user=ebroot -p" + ebroot_password + " --host=" + hostname + " --port=3306 -e \"GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, GRANT OPTION, INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, SELECT, SHOW DATABASES, SHOW VIEW, TRIGGER, UPDATE ON *.* TO '" + dict_ttSettings["mysql"]["users"]["dba"]["username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings["mysql"]["users"]["dba"]["password"] + "\'; FLUSH PRIVILEGES;\" "
        
        r_arg = "mysql --user=ebroot -p" + ebroot_password + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings["mysql"]["users"]["r"]["username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings["mysql"]["users"]["r"]["password"] + "\'; FLUSH PRIVILEGES;\" "
        
        rw_arg = "mysql --user=ebroot -p" + ebroot_password + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, INSERT, INSERT, UPDATE, EXECUTE, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings["mysql"]["users"]["rw"]["username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings["mysql"]["users"]["rw"]["password"] + "\'; FLUSH PRIVILEGES;\" "
    
    
    print "Creating \'mysql-dba' user..."
    print "Executing command: \n%s"%dba_arg
    dba_arg_out = callSubprocess(dba_arg)
    
    print "Creating \'mysql-r' user..."
    print "Executing command: \n%s"%r_arg
    r_arg_out = callSubprocess(r_arg)
    
    print "Creating \'mysql-rw' user..."
    print "Executing command: \n%s"%rw_arg
    rw_arg_out = callSubprocess(rw_arg)
    print( "Grant privileges success!")
Exemple #17
0
def validate_mysql_nyc_accounts(target_hostname):
    #import MySQLdb
    for k,v in dict_ttSettings["mysql"].items():
        try:
            conn_cmd="mysql --user="******"username"] + " -p" + v["password"] + " --host=" + target_hostname + " --port=3306 -e \"CONNECT;\""
            conn_out=callSubprocess(conn_cmd)
        except:
            e = str(sys.exc_info())
            print("Error Encountered: %s. Exiting!" %e)
            print("Error encountered. Exiting! Logfile location: %s" %swapTimeStampDirPath)
            sys.exit(-1)
        #conn.close()
        print(conn_out)
        print("Connection Successful for user: %s!"%k)
    print("Accounts validation successful for service: MySQL !")
Exemple #18
0
def validate_mysql_aws_accounts(aws_cert, target_hostname):
    #import MySQLdb
    for k,v in dict_ttSettings["mysql"].items():
        try:
            #print v["username"]
            #print v["password"]
            #print target_hostname
            #print aws_cert
            #conn_cmd= MySQLdb.Connection(user= v["username"], passwd= v["password"], host= target_hostname, ssl= aws_cert)
            conn_cmd="mysql --user="******"username"] + " -p" + v["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"CONNECT;\""
            conn_out=callSubprocess(conn_cmd)
        except:
            e = str(sys.exc_info())
            print("Error Encountered: %s. Exiting!" %e)
            sys.exit(-1)
Exemple #19
0
def validate_mysql_aws_accounts(aws_cert, target_hostname):
    #import MySQLdb
    for k, v in dict_ttSettings["mysql"].items():
        try:
            #print v["username"]
            #print v["password"]
            #print target_hostname
            #print aws_cert
            #conn_cmd= MySQLdb.Connection(user= v["username"], passwd= v["password"], host= target_hostname, ssl= aws_cert)
            conn_cmd = "mysql --user="******"username"] + " -p" + v[
                "password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 -e \"CONNECT;\""
            conn_out = callSubprocess(conn_cmd)
        except:
            e = str(sys.exc_info())
            print("Error Encountered: %s. Exiting!" % e)
            sys.exit(-1)
Exemple #20
0
def mongodump_source(suffix, s_host, my_logger):
    my_logger.info("In mongodump()...")
    try:
        filename="mongodb-" + suffix
        filepath=os.path.join(swapTimeStampDirPath,filename)
        my_logger.info("Create file success! %s " % filepath)
        dump_cmd="mongodump --host " + s_host + " --port 27017 --username "+ dict_ttSettings["aws_mongo_dbUser"] + " --password " + dict_ttSettings["aws_mongo_dbUser_password"] + " --db apis_cache --out " + filepath
        #print dump_cmd
        """
         mongodump --host mongodb.b.prod.aws.3top.com:27017 --username superuser1 --password HnFBg67tZJ0NZvPC33YvM2hy5H1Sh48mwEe --out mongodump/
        """
        dump_OP=callSubprocess(dump_cmd)
    except:
        my_logger.info("Error encountered. Exiting! %s"%str(sys.exc_info()))
        sys.exit("Arguments mismatch. Exiting! \nLogfile location: %s" %swapTimeStampDirPath)
    my_logger.info("Mongodump successful. \nOutput Received: %s"%dump_OP)
Exemple #21
0
def mongoclone(s_host, t_host, my_logger,log_file):
    my_logger.info(" In mongoclone()...")
    try:
        filename="mongoclone.js"
        filepath=os.path.join(swapTimeStampDirPath,filename)
        my_logger.info("Create file success! %s " % filename)
        f=open(filepath, "wb")
        f.write("printjson(db = db.getSiblingDB('apis_cache'));")
        f.write("\nprintjson(db.getCollectionNames());")
        f.write("\nprintjson(db.dropDatabase());")
        f.write("\nprintjson(db.copyDatabase (\"apis_cache\", \"apis_cache\", \"%s\", \"%s\", \"%s\"));"%(s_host, dict_ttSettings["aws_mongo_dbUser"],dict_ttSettings["aws_mongo_dbUser_password"]))
        f.write("\nprintjson(db.getCollectionNames());")
        f.close()
        clone_cmd="mongo admin -u " + dict_ttSettings["mongodb"]["dba"]["username"] + " -p " + dict_ttSettings["mongodb"]["dba"]["password"] + " --host " + t_host + " --verbose --port 27017 " + filepath
        #print clone_cmd
        clone_OP=callSubprocess(clone_cmd)
    except:
        my_logger.info("Error encountered. Exiting! %s"%str(sys.exc_info()))
        sys.exit("Arguments mismatch. Exiting! \nLogfile location: %s" %log_file)
    my_logger.info("Mongodump successful. \nOutput Received: %s"%clone_OP)
Exemple #22
0
def mysqldump_target(suffix, aws_cert, target_hostname, my_logger, log_file):
    try:
        my_logger.info("In mysqldump()...")
        dump_cmd="mysqldump --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 --single-transaction=TRUE --routines --events ebdb"
        #dump_cmd="mysqldump -u mysql_rw -p" + ttSettings["mysql_rw"] + " -ssl-ca " + ttSettings["AWS_MYSQL_CERT"] + " -h " + mysql_source_host + " -P 3306 --single-transaction=TRUE --routines --events ebdb"
        #print dump_cmd
        #print("command for dump: ",dump_cmd)
        #dump_cmd="mysqldump -u replnyc -p" + _aws_rds_replpass + " --host=" + source_host + " --port=3306 --single-transaction=TRUE ebdb"
        filename=suffix + "-ebdb.sql"
        filepath=os.path.join(swapTimeStampDirPath,filename)
        my_logger.info("Create file success! %s " % filename)
        dump_out=callSubprocess(dump_cmd)
        f=open(filepath, "wb")
        f.write(dump_out)
        f.close()
        my_logger.info("Backup successful!")
    except:
        e = str(sys.exc_info())
        my_logger.info("Encountered Error in mysqldump(): %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %log_file)
        sys.exit(-1)
    return("Returning to mysql_operations")
Exemple #23
0
def mysqldump_target(suffix, aws_cert, target_hostname, my_logger):
    try:
        my_logger.info("In mysqldump()...")
        dump_cmd="mysqldump --user="******"mysql"]["dba"]["username"] + " -p" + dict_ttSettings["mysql"]["dba"]["password"] + " --ssl-ca=" + aws_cert + " --host=" + target_hostname + " --port=3306 --single-transaction=TRUE --routines --events ebdb"
        #dump_cmd="mysqldump -u mysql_rw -p" + ttSettings["mysql_rw"] + " -ssl-ca " + ttSettings["AWS_MYSQL_CERT"] + " -h " + mysql_source_host + " -P 3306 --single-transaction=TRUE --routines --events ebdb"
        #print dump_cmd
        #print("command for dump: ",dump_cmd)
        #dump_cmd="mysqldump -u replnyc -p" + _aws_rds_replpass + " --host=" + source_host + " --port=3306 --single-transaction=TRUE ebdb"
        filename=suffix + "-ebdb.sql"
        filepath=os.path.join(swapTimeStampDirPath,filename)
        my_logger.info("Create file success! %s " % filename)
        dump_out=callSubprocess(dump_cmd)
        f=open(filepath, "wb")
        f.write(dump_out)
        f.close()
        my_logger.info("Backup successful!")
    except:
        e = str(sys.exc_info())
        my_logger.info("Encountered Error in mysqldump(): %s. Exiting!" %e)
        print("Error encountered. Exiting! Logfile location: %s" %swapTimeStampDirPath)
        sys.exit(-1)
    return("Returning to mysql_operations")
Exemple #24
0
def mysql_user_create():
    env_name = raw_input("Enter environment name (e.g., a.dev.aws.3top.com): ")
    if "aws.3top.com" in env_name:
        hostname = "fp-rds-1." + env_name
    elif "nyc.3top.com" in env_name:
        hostname = env_name
    dict_ttSettings = env_ttSettings(env_name)

    ebroot_password = raw_input("Enter ebroot password: "******"aws.3top.com" in hostname:
        cert = dict_ttSettings["mysql"]["certs"]["public"]
        dba_arg = "mysql --user=ebroot -p" + ebroot_password + " --ssl-ca=" + os.path.expanduser(
            cert
        ) + " --host=" + hostname + " --port=3306 -e \"GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, GRANT OPTION, INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, SELECT, SHOW DATABASES, SHOW VIEW, TRIGGER, UPDATE ON *.* TO '" + dict_ttSettings[
            "mysql"]["users"]["dba"][
                "username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings[
                    "mysql"]["users"]["dba"][
                        "password"] + "\'; FLUSH PRIVILEGES;\" "

        r_arg = "mysql --user=ebroot -p" + ebroot_password + " --ssl-ca=" + os.path.expanduser(
            cert
        ) + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings[
            "mysql"]["users"]["r"][
                "username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings[
                    "mysql"]["users"]["r"][
                        "password"] + "\'; FLUSH PRIVILEGES;\" "

        rw_arg = "mysql --user=ebroot -p" + ebroot_password + " --ssl-ca=" + os.path.expanduser(
            cert
        ) + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, INSERT, UPDATE, EXECUTE, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings[
            "mysql"]["users"]["rw"][
                "username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings[
                    "mysql"]["users"]["rw"][
                        "password"] + "\'; FLUSH PRIVILEGES;\" "

    elif "nyc.3top.com" in hostname:
        dba_arg = "mysql --user=ebroot -p" + ebroot_password + " --host=" + hostname + " --port=3306 -e \"GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, GRANT OPTION, INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, SELECT, SHOW DATABASES, SHOW VIEW, TRIGGER, UPDATE ON *.* TO '" + dict_ttSettings[
            "mysql"]["users"]["dba"][
                "username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings[
                    "mysql"]["users"]["dba"][
                        "password"] + "\'; FLUSH PRIVILEGES;\" "

        r_arg = "mysql --user=ebroot -p" + ebroot_password + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings[
            "mysql"]["users"]["r"][
                "username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings[
                    "mysql"]["users"]["r"][
                        "password"] + "\'; FLUSH PRIVILEGES;\" "

        rw_arg = "mysql --user=ebroot -p" + ebroot_password + " --host=" + hostname + " --port=3306 -e \"GRANT SELECT, INSERT, INSERT, UPDATE, EXECUTE, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO '" + dict_ttSettings[
            "mysql"]["users"]["rw"][
                "username"] + "'@'%' IDENTIFIED BY \'" + dict_ttSettings[
                    "mysql"]["users"]["rw"][
                        "password"] + "\'; FLUSH PRIVILEGES;\" "

    print "Creating \'mysql-dba' user..."
    print "Executing command: \n%s" % dba_arg
    dba_arg_out = callSubprocess(dba_arg)

    print "Creating \'mysql-r' user..."
    print "Executing command: \n%s" % r_arg
    r_arg_out = callSubprocess(r_arg)

    print "Creating \'mysql-rw' user..."
    print "Executing command: \n%s" % rw_arg
    rw_arg_out = callSubprocess(rw_arg)
    print("Grant privileges success!")
Exemple #25
0
def validate_mongodb_source_accounts(s_host):
    try:
        conn_cmd="mongo " + s_host + ":27017/apis_cache -u "+ dict_ttSettings["aws_mongo_dbUser"] + " -p " + dict_ttSettings["aws_mongo_dbUser_password"] + " --eval \"printjson(db.getCollectionNames());\""
        conn_out=callSubprocess(conn_cmd)
    except:
        sys.exit("NYC account for %s cannot be validated. Error Encountered: %s. Exiting!" %(dict_ttSettings["aws_mongo_dbUser"] , str(sys.exc_info())))