def configure_db():
 global _ENGINE
 if (not _ENGINE):
  sql_connection = cfg.CONF.DATABASE.sql_connection
  if (not sql_connection):
   LOG.warn(_(("Option 'sql_connection' not specified in any config file - using default value '%s'" % SQL_CONNECTION_DEFAULT)))
   sql_connection = SQL_CONNECTION_DEFAULT
  connection_dict = sql.engine.url.make_url(sql_connection)
  engine_args = {'pool_recycle': 3600, 'echo': False, 'convert_unicode': True}
  if ('mysql' in connection_dict.drivername):
   engine_args['listeners'] = [MySQLPingListener()]
   if ((MySQLdb is not None) and cfg.CONF.DATABASE.sql_dbpool_enable):
    pool_args = {'db': connection_dict.database, 'passwd': (connection_dict.password or ''), 'host': connection_dict.host, 'user': connection_dict.username, 'min_size': cfg.CONF.DATABASE.sql_min_pool_size, 'max_size': cfg.CONF.DATABASE.sql_max_pool_size, 'max_idle': cfg.CONF.DATABASE.sql_idle_timeout}
    pool = db_pool.ConnectionPool(MySQLdb, **pool_args)
    def creator():
     conn = pool.create()
     if isinstance(conn, tuple):
      (_1, _2, conn) = conn
     return conn
    engine_args['creator'] = creator
   if ((MySQLdb is None) and cfg.CONF.DATABASE.sql_dbpool_enable):
    LOG.warn(_('Eventlet connection pooling will not work without python-mysqldb!'))
  if ('sqlite' in connection_dict.drivername):
   engine_args['listeners'] = [SqliteForeignKeysListener()]
   if (sql_connection == 'sqlite://'):
    engine_args['connect_args'] = {'check_same_thread': False}
  _ENGINE = create_engine(sql_connection, **engine_args)
  sql.event.listen(_ENGINE, 'checkin', greenthread_yield)
  if (not register_models()):
   if cfg.CONF.DATABASE.reconnect_interval:
    remaining = cfg.CONF.DATABASE.sql_max_retries
    reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
    retry_registration(remaining, reconnect_interval)

def configure_db ( ) : global _ENGINE if ( not _ENGINE ) : sql_connection = cfg . CONF . DATABASE . sql_connection if ( not sql_connection ) : LOG . warn ( _ ( ( "Option 'sql_connection' not specified in any config file - using default value '%s'" % SQL_CONNECTION_DEFAULT ) ) ) sql_connection = SQL_CONNECTION_DEFAULT connection_dict = sql . engine . url . make_url ( sql_connection ) engine_args = { 'pool_recycle' : 3600 , 'echo' : False , 'convert_unicode' : True } if ( 'mysql' in connection_dict . drivername ) : engine_args [ 'listeners' ] = [ MySQLPingListener ( ) ] if ( ( MySQLdb is not None ) and cfg . CONF . DATABASE . sql_dbpool_enable ) : pool_args = { 'db' : connection_dict . database , 'passwd' : ( connection_dict . password or '' ) , 'host' : connection_dict . host , 'user' : connection_dict . username , 'min_size' : cfg . CONF . DATABASE . sql_min_pool_size , 'max_size' : cfg . CONF . DATABASE . sql_max_pool_size , 'max_idle' : cfg . CONF . DATABASE . sql_idle_timeout } pool = db_pool . ConnectionPool ( MySQLdb , ** pool_args ) def creator ( ) : conn = pool . create ( ) if isinstance ( conn , tuple ) : ( _1 , _2 , conn ) = conn return conn engine_args [ 'creator' ] = creator if ( ( MySQLdb is None ) and cfg . CONF . DATABASE . sql_dbpool_enable ) : LOG . warn ( _ ( 'Eventlet connection pooling will not work without python-mysqldb!' ) ) if ( 'sqlite' in connection_dict . drivername ) : engine_args [ 'listeners' ] = [ SqliteForeignKeysListener ( ) ] if ( sql_connection == 'sqlite://' ) : engine_args [ 'connect_args' ] = { 'check_same_thread' : False } _ENGINE = create_engine ( sql_connection , ** engine_args ) sql . event . listen ( _ENGINE , 'checkin' , greenthread_yield ) if ( not register_models ( ) ) : if cfg . CONF . DATABASE . reconnect_interval : remaining = cfg . CONF . DATABASE . sql_max_retries reconnect_interval = cfg . CONF . DATABASE . reconnect_interval retry_registration ( remaining , reconnect_interval )
establish the database .