def create_airflow_conn(conf):
    conn = Connection()
    conn.conn_id = conf.get('conn_id')
    conn.conn_type = conf.get('conn_type')
    conn.host = conf.get('host')
    conn.port = conf.get('port')
    conn.login = conf.get('login')
    conn.password = conf.get('password')
    conn.schema = conf.get('schema')
    conn.extra = conf.get('extra')

    session = settings.Session()
    try:
        conn_name = session.\
            query(Connection).\
            filter(Connection.conn_id == conn.conn_id).first()
        if str(conn_name) == str(conf.get('conn_id')):
            logger.info(f"Connection {conn.conn_id} already exists")
            logger.info(f"Deleting connection {conn.conn_id}")
            session.delete(conn_name)
        else:
            session.add(conn)
            session.commit()
        session.close()
        logger.info(Connection.log_info(conn))
        logger.info(f'Connection {conn.conn_id} is created')
    except Exception as e:
        logging.info(f"Exception occured while creating connection \n {e}")
Esempio n. 2
0
def create_airflow_conn(conf):
    conn = Connection()
    conn.conn_id = conf.get('conn_id')
    conn.conn_type = conf.get('conn_type')
    conn.host = conf.get('host')
    conn.port = conf.get('port')
    conn.login = conf.get('login')
    conn.password = conf.get('password')
    conn.schema = conf.get('schema')
    conn.extra = conf.get('extra')

    session = settings.Session()
    try:
        existing_conns = session.query(Connection).filter(
            Connection.conn_id == conn.conn_id).delete()
    finally:
        session.add(conn)
        session.commit()
    session.close()