diff --git a/configdb/db/interface/sa_interface.py b/configdb/db/interface/sa_interface.py index 0bb05d4cb7d21ec16ad0e543dace074413c659b2..bbd4ee045894ed44bde5fa78420575b9afec4f54 100644 --- a/configdb/db/interface/sa_interface.py +++ b/configdb/db/interface/sa_interface.py @@ -44,7 +44,7 @@ class SqlAlchemyDbInterface(base.DbInterface): AUDIT_SUPPORT = True - def __init__(self, uri, schema, schema_dir=None): + def __init__(self, uri, schema, schema_dir=None, opts={}): self.Session = sessionmaker(autocommit=False, autoflush=False) Base = declarative_base() @@ -53,7 +53,7 @@ class SqlAlchemyDbInterface(base.DbInterface): self._schema_dir = schema_dir # unused, meant for caching self._load_schema() - self.engine = create_engine(uri, pool_recycle=1800) + self.engine = create_engine(uri, pool_recycle=1800, **opts) self.Session.configure(bind=self.engine) Base.metadata.create_all(self.engine) diff --git a/configdb/server/wsgiapp.py b/configdb/server/wsgiapp.py index 9fd3ffce9a7d9330c12d31e93459e23ec9225575..8a4a6146e1cc7c877c563f00cf12bff6ce0d64f5 100644 --- a/configdb/server/wsgiapp.py +++ b/configdb/server/wsgiapp.py @@ -215,11 +215,12 @@ def make_app(config={}): # Initialize the database interface. schema_obj = schema.Schema(app.config['SCHEMA_JSON']) db_driver = app.config.get('DB_DRIVER', 'sqlalchemy') + db_opts = app.config.get('DB_OPTIONS', {}) if db_driver == 'sqlalchemy': from configdb.db.interface import sa_interface db = sa_interface.SqlAlchemyDbInterface( app.config.get('DB_URI', 'sqlite:///:memory:'), - schema_obj) + schema_obj, opts=db_opts) elif db_driver == 'leveldb': from configdb.db.interface import leveldb_interface db = leveldb_interface.LevelDbInterface( @@ -230,8 +231,15 @@ def make_app(config={}): if not 'ZK_HOSTS' in app.config: raise Exception('you need to define ZK_HOSTS list to use zookeeper as db backend') db = zookeeper_interface.ZookeeperInterface(app.config['ZK_HOSTS'], schema_obj, app.config['DB_URI']) + elif db_driver == 'etcd': + from configdb.db.interface import etcd_interface + if not 'ETCD_URL' in app.config: + raise Exception( + 'You need to define an ETCD_URL to use the etcd backend') + db = etcd_interface.EtcdInterface( + app.config['ETCD_URL'], schema_obj, **db_opts) else: - raise Exception('DB_DRIVER not one of "sqlalchemy" or "leveldb"') + raise Exception('DB_DRIVER not supported: %s' % db_driver) app.api = db_api.AdmDbApi(schema_obj, db)