def connect_to_single_db_with_conf(conf, database_name):
    LOG.info("open database connection to {}:{}, user '{}', database '{}'",
             conf['postgres']['host'], conf['postgres']['port'],
             conf['postgres']['user'], database_name)
    return get_db_connection(database_name,
                             conf['postgres']['user'],
                             conf['postgres']['password'],
                             host=conf['postgres']['host'],
                             port=int(conf['postgres']['port']))
def connect_to_single_db_with_conf(conf, database_name):
    LOG.info("open database connection to {}:{}, user '{}', database '{}'",
             conf['postgres']['host'], conf['postgres']['port'],
             conf['postgres']['user'], database_name)
    return get_db_connection(database_name,
                             conf['postgres']['user'],
                             conf['postgres']['password'],
                             host=conf['postgres']['host'],
                             port=int(conf['postgres']['port']))
Example #3
0
def connect_as_super_user(db_name, conf):
    db_connection = None
    try:
        db_connection = psycopg2.connect(database=db_name)
        db_connection.autocommit = True
    except psycopg2.OperationalError:
        LOG.info("could not connect as local superuser with current user, credentials required")

    if not db_connection:
        superuser, password = query_user_for_superuser_credentials()
        db_connection = get_db_connection(db_name, superuser, password,
                                          host=conf['postgres']['host'],
                                          port=int(conf['postgres']['port']))

    if not db_connection or db_connection.closed:
        raise Exception("failed connecting the database: " + db_name)

    return db_connection
Example #4
0
def connect_as_super_user(db_name, conf):
    db_connection = None
    try:
        db_connection = psycopg2.connect(database=db_name)
        db_connection.autocommit = True
    except psycopg2.OperationalError:
        LOG.info("could not connect as local superuser with current user, credentials required")

    if not db_connection:
        superuser, password = query_user_for_superuser_credentials()
        db_connection = get_db_connection(db_name, superuser, password,
                                          host=conf['postgres']['host'],
                                          port=int(conf['postgres']['port']))

    if not db_connection or db_connection.closed:
        raise Exception("failed connecting the database: " + db_name)

    return db_connection