def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES,\ _RETRY_INTERVAL if not _ENGINE: tries = _MAX_RETRIES retry_interval = _RETRY_INTERVAL connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True } try: _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) if 'mysql' in connection_dict.drivername: sqlalchemy.event.listen(_ENGINE, 'checkout', _ping_listener) _ENGINE.connect = _wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = _("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.sqlalchemy_debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info(_('auto-creating glance registry DB')) models.register_models(_ENGINE) try: migration.version_control() except exception.DatabaseMigrationError: # only arises when the DB exists and is under version control pass else: LOG.info(_('not auto-creating glance registry DB')) return _ENGINE
def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES,\ _RETRY_INTERVAL if not _ENGINE: tries = _MAX_RETRIES retry_interval = _RETRY_INTERVAL connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True} try: _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) if 'mysql' in connection_dict.drivername: sqlalchemy.event.listen(_ENGINE, 'checkout', _ping_listener) _ENGINE.connect = _wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = _("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info(_('auto-creating glance registry DB')) models.register_models(_ENGINE) try: migration.version_control() except exception.DatabaseMigrationError: # only arises when the DB exists and is under version control pass else: LOG.info(_('not auto-creating glance registry DB')) return _ENGINE
def configure_db(): """ Establish the database, create an engine if needed, and register the models. """ global _ENGINE, sa_logger, _MAX_RETRIES, _RETRY_INTERVAL if not _ENGINE: sql_connection = CONF.sql_connection _MAX_RETRIES = CONF.sql_max_retries _RETRY_INTERVAL = CONF.sql_retry_interval connection_dict = sqlalchemy.engine.url.make_url(sql_connection) engine_args = {"pool_recycle": CONF.sql_idle_timeout, "echo": False, "convert_unicode": True} try: _ENGINE = sqlalchemy.create_engine(sql_connection, **engine_args) if "mysql" in connection_dict.drivername: sqlalchemy.event.listen(_ENGINE, "checkout", ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception, err: msg = ( _( "Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s" ) % locals() ) LOG.error(msg) raise sa_logger = logging.getLogger("sqlalchemy.engine") if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info("auto-creating glance registry DB") models.register_models(_ENGINE) try: migration.version_control() except exception.DatabaseMigrationError: # only arises when the DB exists and is under version control pass else: LOG.info("not auto-creating glance registry DB")
def configure_db(): """ Establish the database, create an engine if needed, and register the models. """ global _ENGINE, sa_logger, _MAX_RETRIES, _RETRY_INTERVAL if not _ENGINE: sql_connection = CONF.sql_connection _MAX_RETRIES = CONF.sql_max_retries _RETRY_INTERVAL = CONF.sql_retry_interval connection_dict = sqlalchemy.engine.url.make_url(sql_connection) engine_args = { 'pool_recycle': CONF.sql_idle_timeout, 'echo': False, 'convert_unicode': True } try: _ENGINE = sqlalchemy.create_engine(sql_connection, **engine_args) if 'mysql' in connection_dict.drivername: sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() LOG.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info('auto-creating glance registry DB') models.register_models(_ENGINE) try: migration.version_control() except exception.DatabaseMigrationError: # only arises when the DB exists and is under version control pass else: LOG.info('not auto-creating glance registry DB')
def reset_db(db_api): db_models.unregister_models(db_api._ENGINE) db_models.register_models(db_api._ENGINE)
def destroy_fixtures(self): # Easiest to just drop the models and re-create them... db_models.unregister_models(db_api.get_engine()) db_models.register_models(db_api.get_engine())
def destroy_fixtures(self): db_models.unregister_models(db_api.get_engine()) db_models.register_models(db_api.get_engine())
def reset_db(db_api): db_models.unregister_models(db_api.get_engine()) db_models.register_models(db_api.get_engine())
def destroy_fixtures(self): # Easiest to just drop the models and re-create them... db_models.unregister_models(db_api._ENGINE) db_models.register_models(db_api._ENGINE)
def destroy_fixtures(self): db_models.unregister_models(db_api._ENGINE) db_models.register_models(db_api._ENGINE)
def reset(self): db_models.unregister_models(self.db_api._ENGINE) db_models.register_models(self.db_api._ENGINE)