def configure_db(conf): """ Establish the database, create an engine if needed, and register the models. :param conf: Mapping of configuration options """ global _ENGINE, sa_logger, logger, _MAX_RETRIES, _RETRY_INTERVAL if not _ENGINE: conf.register_opts(db_opts) 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 = create_engine(sql_connection, **engine_args) _ENGINE.create = wrap_db_error(_ENGINE.create) except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if conf.debug: sa_logger.setLevel(logging.DEBUG) elif conf.verbose: sa_logger.setLevel(logging.INFO) models.register_models(_ENGINE)
def configure_db(conf): """ Establish the database, create an engine if needed, and register the models. :param conf: Mapping of configuration options """ global _ENGINE, sa_logger, logger if not _ENGINE: conf.register_opts(db_opts) timeout = conf.sql_idle_timeout sql_connection = conf.sql_connection try: _ENGINE = create_engine(sql_connection, pool_recycle=timeout) except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if conf.debug: sa_logger.setLevel(logging.DEBUG) elif conf.verbose: sa_logger.setLevel(logging.INFO) models.register_models(_ENGINE)
def configure_db(options): """ Establish the database, create an engine if needed, and register the models. :param options: Mapping of configuration options """ global _ENGINE, sa_logger, logger if not _ENGINE: debug = config.get_option( options, 'debug', type='bool', default=False) verbose = config.get_option( options, 'verbose', type='bool', default=False) timeout = config.get_option( options, 'sql_idle_timeout', type='int', default=3600) sql_connection = config.get_option(options, 'sql_connection') try: _ENGINE = create_engine(sql_connection, pool_recycle=timeout) except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if debug: sa_logger.setLevel(logging.DEBUG) elif verbose: sa_logger.setLevel(logging.INFO) models.register_models(_ENGINE)
def configure_db(options): """ Establish the database, create an engine if needed, and register the models. :param options: Mapping of configuration options """ global _ENGINE, sa_logger, logger if not _ENGINE: debug = config.get_option(options, 'debug', type='bool', default=False) verbose = config.get_option(options, 'verbose', type='bool', default=False) timeout = config.get_option(options, 'sql_idle_timeout', type='int', default=3600) sql_connection = config.get_option(options, 'sql_connection') try: _ENGINE = create_engine(sql_connection, pool_recycle=timeout) except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if debug: sa_logger.setLevel(logging.DEBUG) elif verbose: sa_logger.setLevel(logging.INFO) models.register_models(_ENGINE)
def configure_db(options): """ Establish the database, create an engine if needed, and register the models. :param options: Mapping of configuration options """ global _ENGINE global logger if not _ENGINE: debug = config.get_option( options, 'debug', type='bool', default=False) verbose = config.get_option( options, 'verbose', type='bool', default=False) timeout = config.get_option( options, 'sql_idle_timeout', type='int', default=3600) _ENGINE = create_engine(options['sql_connection'], pool_recycle=timeout) logger = logging.getLogger('sqlalchemy.engine') if debug: logger.setLevel(logging.DEBUG) elif verbose: logger.setLevel(logging.INFO) models.register_models(_ENGINE)
def configure_db(conf): """ Establish the database, create an engine if needed, and register the models. :param conf: Mapping of configuration options """ global _ENGINE, sa_logger, logger, _MAX_RETRIES, _RETRY_INTERVAL if not _ENGINE: for opt in db_opts: # avoid duplicate registration if not opt.name in conf: conf.register_opt(opt) 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 } if 'mysql' in connection_dict.drivername: engine_args['listeners'] = [MySQLPingListener()] try: _ENGINE = create_engine(sql_connection, **engine_args) _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() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if conf.debug: sa_logger.setLevel(logging.DEBUG) elif conf.verbose: sa_logger.setLevel(logging.INFO) if conf.db_auto_create: logger.info('auto-creating glance registry DB') models.register_models(_ENGINE) try: migration.version_control(conf) except exception.DatabaseMigrationError: # only arises when the DB exists and is under version control pass else: logger.info('not auto-creating glance registry DB')
def configure_db(conf): """ Establish the database, create an engine if needed, and register the models. :param conf: Mapping of configuration options """ global _ENGINE, sa_logger, logger, _MAX_RETRIES, _RETRY_INTERVAL if not _ENGINE: conf.register_opts(db_opts) 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} if "mysql" in connection_dict.drivername: engine_args["listeners"] = [MySQLPingListener()] try: _ENGINE = create_engine(sql_connection, **engine_args) _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() ) logger.error(msg) raise sa_logger = logging.getLogger("sqlalchemy.engine") if conf.debug: sa_logger.setLevel(logging.DEBUG) elif conf.verbose: sa_logger.setLevel(logging.INFO) models.register_models(_ENGINE) try: migration.version_control(conf) except exception.DatabaseMigrationError: # only arises when the DB exists and is under version control pass
def configure_db(options): """ Establish the database, create an engine if needed, and register the models. :param options: Mapping of configuration options """ global _ENGINE, sa_logger, logger if not _ENGINE: debug = config.get_option( options, 'debug', type='bool', default=False) verbose = config.get_option( options, 'verbose', type='bool', default=False) timeout = config.get_option( options, 'sql_idle_timeout', type='int', default=3600) sql_connection = config.get_option(options, 'sql_connection') connection_dict = sqlalchemy.engine.url.make_url(sql_connection) engine_args = {'pool_recycle': timeout, 'echo': False, 'convert_unicode': True } if 'mysql' in connection_dict.drivername: engine_args['listeners'] = [MySQLPingListener()] try: _ENGINE = create_engine(sql_connection, **engine_args) except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if debug: sa_logger.setLevel(logging.DEBUG) elif verbose: sa_logger.setLevel(logging.INFO) models.register_models(_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)