示例#1
0
def create_mongodb(params):
    dbtype = params['dbtype']
    con_name = params['dbname']
    config_dat = Config.info[dbtype]
    volumes = config_dat['volumes']
    for vol in volumes:
        if vol[0] == 'DBVOL': vol[0] = params['db_vol']
        if vol[0] == 'BAKVOL': vol[0] = Config.backup_vol
    if container_util.container_exists(con_name):
        return "Container name %s already in use" % (con_name)
    port = container_util.get_max_port()
    params['port'] = port
    Ports = {config_dat['pub_ports'][0]: (Config.container_ip, port)}
    params['port_bindings'] = Ports
    env = {'DB_USER': params['dbuser']}

    # create container without Auth enabled
    container_util.make_dirs(con_name, volumes)
    (c_id, con) = container_util.create_con(params, env, config_dat['command'])
    print("DEBUG: noauth MongoDB created. Sleeping while it starts.\n")
    time.sleep(4)

    mongodb_create_account(params)

    print("DEBUG: stop and remove container")
    root = Config.accounts[params['dbtype']]['admin']
    password = Config.accounts[params['dbtype']]['admin_pass']
    result = container_util.kill_con(params['dbname'], root, password,
                                     params['username'])
    print("DEBUG: mongodb_util kill: %s" % result)
    admin_db.delete_container(c_id)  # we don't duplicate container data
    print('Sleeping a bit before recreating mongo')
    time.sleep(4)

    print("DEBUG: Start with Auth")
    (c_id, con) = container_util.create_con(params, env, '--auth')
    print("DEBUG: MongoDB with --auth created: %s." % con['Id'])
    res = "Your MongoDB container has been created; %s\n\n" % con_name
    res += 'Mongo URI: "mongodb://%s:%s@%s:%s"' % (
        params['dbuser'], params['dbuserpass'], Config.container_host, port)
    message = 'MongoDB created\n'
    message += res
    send_mail("DB4SCI: created MongoDB", message)
    return res
示例#2
0
def setup(dbtype, con_name):
    params = {
        'dbname': con_name,
        'dbuser': Config.accounts['test_user']['admin'],
        'dbuserpass': Config.accounts['test_user']['admin_pass'],
        'username': Config.accounts['test_user']['admin'],
        'support': 'Basic',
        'owner': Config.accounts['test_user']['owner'],
        'description': 'Test the Mongo',
        'contact': Config.accounts['test_user']['contact'],
        'life': 'medium',
        'backup_freq': 'Daily',
        'backup_life': '6',
        'backup_window': 'any',
        'pitr': 'n',
        'maintain': 'standard',
        'phi': 'No',
        'pitr': 'n',
        'db_vol': '/mydb/dbs_data',
    }
    params['dbtype'] = dbtype
    params['port'] = container_util.get_max_port()
    params['image'] = Config.info[dbtype]['images'][0][1]
    return params
示例#3
0
def create(params):
    """Create Postgres Container"""
    con_name = params['dbname']
    config_dat = Config.info[params['dbtype']]
    volumes = config_dat['volumes']
    for vol in volumes:
        if vol[0] == 'DBVOL':
            vol[0] = params['db_vol']
    if container_util.container_exists(con_name):
        return "Container name %s already in use" % con_name
    # Ports is a dict of internal too external mappings
    if 'port' in params:
        port = params['port']
    else:
        port = container_util.get_max_port()
        params['port'] = port
    Ports = {config_dat['pub_ports'][0]: (Config.container_host, port)}
    params['port_bindings'] = Ports
    params['longpass'] = generate_password()
    env = {
        'POSTGRES_DB': params[
            'dbname'],  # default database that is created when the image is first started
        'POSTGRES_USER': params['dbuser'],
        'POSTGRES_PASSWORD': params['dbuserpass']
    }

    # create container
    container_util.make_dirs(con_name, volumes)
    (c_id, con) = container_util.create_con(params, env, config_dat['command'])
    params['con'] = con
    print("DEBUG: %s created. ID=%s\n" % (dbtype, con['Id']))
    time.sleep(5)
    status = create_accounts(params)
    badness = 0
    while status == 'connect error' and badness < 6:
        time.sleep(3)
        badness += 1
        status = create_accounts(params)
    if status != 'ok':
        res = 'This is embarrassing. Your Postgres container; %s ' % params[
            'dbname']
        res += 'has been created but I was unable to create your account.\n'
        res += 'This unfortunate incident will be reported to the DB4SCI admin staff.'
        send_mail("DB4SCI: Error creating account", res)
        return res
    # restart the container
    container_util.restart(con['Id'])
    res = "Your database server has been created. Use the following command "
    res += "to connect from the Linux command line.\n\n"
    res += "psql -h %s " % Config.container_host
    res += "-p %s -d %s " % (str(port), params['dbname'])
    res += "-U %s\n\n" % params['dbuser']
    res += "If you would like to connect to the database without entering a "
    res += "password, create a .pgpass file in your home directory.\n"
    res += "Set permissions to 600. Format is hostname:port:database:"
    res += "username:password.\n"
    res += "Cut/paste this line and place in your /home/user/.pgpass file.\n\n"
    res += Config.container_host + ":" + str(port) + ":" + params['dbname']
    res += ":" + params['dbuser'] + ":" + params['dbuserpass'] + "\n\n"
    res += "To use psql on the linux command line load the PostgreSQL"
    res += " module.\n"
    res += "module load PostgreSQL\n\n"

    message = 'DB4SCI created a new %s database called: %s\n' % (
        dbtype, params['dbname'])
    message += 'Created by: %s <%s>\n' % (params['owner'], params['contact'])
    send_mail("DB4SCI: created %s" % dbtype, message)
    return res
示例#4
0
        description='Test the Dev',
        contact=Config.accounts['test_user']['contact'],
        life='medium',
        backup_type='User',
        backup_freq='Daily',
        backup_life='6',
        backup_window='any',
        maintain='standard',
        phi='No',
        pitr='n',
        username=Config.accounts['test_user']['admin'],
        db_vol='/mydb/db_data',
    )
    params['dbuserpass'] = unicode(Config.accounts['test_user']['admin_pass'])
    params['dbtype'] = dbtype
    params['port'] = container_util.get_max_port()
    params['image'] = Config.info[dbtype]['images'][0][1]

    parser = argparse.ArgumentParser(prog='mariadb_test.py',
                                     description='Test MariaDB routines')
    parser.add_argument('--purge',
                        '-d',
                        action='store_true',
                        default=False,
                        help='Delete test container')
    parser.add_argument('--backup',
                        '-b',
                        action='store_true',
                        default=False,
                        help='backup %s' % params['dbname'])
    args = parser.parse_args()
示例#5
0
def create_mariadb(params):
    """
    Create MariaDB Docker instance
    :param params: dict
    :return: Help message for end user
    """
    con_name = params['dbname']
    if container_util.container_exists(con_name):
        return "Container name %s already in use" % con_name
    dbtype = params['dbtype']
    config_dat = Config.info[params['dbtype']]
    volumes = config_dat['volumes']
    print('DEBUG: DBVOL: %s' % params['db_vol'])
    for vol in volumes:
        if vol[0] == 'DBVOL': vol[0] = params['db_vol']
        if vol[0] == 'BAKVOL': vol[0] = Config.backup_vol
    container_util.make_dirs(con_name, volumes)
    #  Add key volume, encrypt.cnf file
    result = make_keys.create_mariadb_key(con_name, params)
    port = container_util.get_max_port()
    params['port'] = port
    pub_port = config_dat['pub_ports'][0]
    params['port_bindings'] = {pub_port: (Config.container_ip, str(port))}
    env = {
        'MYSQL_ROOT_PASSWORD': Config.accounts[dbtype]['admin_pass'],
        'MYSQL_USER': params['dbuser'],
        'MYSQL_PASSWORD': params['dbuserpass'],
    }

    # create container
    container_util.make_dirs(con_name, volumes)
    cmd = config_dat['command'] + ' --ft_min_word_len=3'
    (c_id, con) = container_util.create_con(params, env, cmd)
    print("DEBUG: MariaDB created. ID=%s\n" % con['Id'])
    time.sleep(25)
    status = maria_create_account(params)
    badness = 0
    while status == 'connect error' and badness < 6:
        time.sleep(10)
        badness += 1
        status = maria_create_account(params)
    if status != 'ok':
        res = 'This is embarrassing. Your MariaDB container; %s ' % params[
            'dbname']
        res += 'has been created but I was unable to create your account.\n'
        res += 'This unfortunate incident will be reported to the DB4SCI admin staff.'
        send_mail("DB4SCI: Error creating account", res)
    else:
        res = "Your MariaDB container has been created. "
        res += "Container name: %s\n\n" % con_name
        res += "Use mysql command line tools to access your new MariaDB.\n\n"
        res += "mysql --host %s --port %s --user %s --password\n\n" % (
            Config.container_host, params['port'], params['dbuser'])
        res += 'Leave the password argument blank. You will be prompted to enter '
        res += 'the password.\n\n'
        res += 'Encryption at Rest is enabled and TLS support is enabled.'
        res += 'Download TLS keys from the Documentation tab. Select "TLS '
        res += 'for MariaDB."'

    msg = 'MariaDB created: %s\n' % params['dbname']
    msg += 'Created by: %s <%s>\n' % (params['owner'], params['contact'])
    send_mail("DB4SCI: created MariaDB", msg)
    return res