Skip to content
Snippets Groups Projects
Commit ddd29d29 authored by joe's avatar joe
Browse files

Enabling etcd interface from the app; allowing input of db options

from the app config file.
parent 7df1c612
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ class SqlAlchemyDbInterface(base.DbInterface): ...@@ -44,7 +44,7 @@ class SqlAlchemyDbInterface(base.DbInterface):
AUDIT_SUPPORT = True 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) self.Session = sessionmaker(autocommit=False, autoflush=False)
Base = declarative_base() Base = declarative_base()
...@@ -53,7 +53,7 @@ class SqlAlchemyDbInterface(base.DbInterface): ...@@ -53,7 +53,7 @@ class SqlAlchemyDbInterface(base.DbInterface):
self._schema_dir = schema_dir # unused, meant for caching self._schema_dir = schema_dir # unused, meant for caching
self._load_schema() 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) self.Session.configure(bind=self.engine)
Base.metadata.create_all(self.engine) Base.metadata.create_all(self.engine)
......
...@@ -215,11 +215,12 @@ def make_app(config={}): ...@@ -215,11 +215,12 @@ def make_app(config={}):
# Initialize the database interface. # Initialize the database interface.
schema_obj = schema.Schema(app.config['SCHEMA_JSON']) schema_obj = schema.Schema(app.config['SCHEMA_JSON'])
db_driver = app.config.get('DB_DRIVER', 'sqlalchemy') db_driver = app.config.get('DB_DRIVER', 'sqlalchemy')
db_opts = app.config.get('DB_OPTIONS', {})
if db_driver == 'sqlalchemy': if db_driver == 'sqlalchemy':
from configdb.db.interface import sa_interface from configdb.db.interface import sa_interface
db = sa_interface.SqlAlchemyDbInterface( db = sa_interface.SqlAlchemyDbInterface(
app.config.get('DB_URI', 'sqlite:///:memory:'), app.config.get('DB_URI', 'sqlite:///:memory:'),
schema_obj) schema_obj, opts=db_opts)
elif db_driver == 'leveldb': elif db_driver == 'leveldb':
from configdb.db.interface import leveldb_interface from configdb.db.interface import leveldb_interface
db = leveldb_interface.LevelDbInterface( db = leveldb_interface.LevelDbInterface(
...@@ -230,8 +231,15 @@ def make_app(config={}): ...@@ -230,8 +231,15 @@ def make_app(config={}):
if not 'ZK_HOSTS' in app.config: if not 'ZK_HOSTS' in app.config:
raise Exception('you need to define ZK_HOSTS list to use zookeeper as db backend') 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']) 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: 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) app.api = db_api.AdmDbApi(schema_obj, db)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment