Files
freezer-api/freezer_api/storage/driver.py
Saad Zaher 49e934d589 Implement API v2 with fully support Mutli-tenancy
Added Freezer API V2 which supports mainly multitenancy
Added a new database driver to support project_id parameter.
API v2 will be in development status till the end of pike
API v1 will be deprecated by end of Pike
oslo.db patch will be based on API v2

Implements blueprint api-v2-multi-tenancy
Signed-off-by: Saad Zaher <eng.szaher@gmail.com>

Change-Id: I2791246b7d6dc6c91427af45c0930e5d334a4861
2017-04-10 10:48:55 +00:00

77 lines
2.2 KiB
Python

"""
(c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from freezer_api.storage import elastic
from oslo_config import cfg
from oslo_log import log
from oslo_utils import importutils
CONF = cfg.CONF
LOG = log.getLogger(__name__)
# storage backend options to be registered
_OPTS = [
cfg.StrOpt("backend",
help="Databse backend section name. This section "
"will be loaded by the proper driver to connect to "
"the database."
),
cfg.StrOpt('driver',
default='freezer_api.storage.elastic.ElasticSearchEngine',
help="Database driver to be used."
)
]
def register_storage_opts():
"""Register storage configuration options"""
opt_group = cfg.OptGroup(name='storage',
title='Freezer Storage Engine')
CONF.register_group(opt_group)
CONF.register_opts(_OPTS, group=opt_group)
def get_db(driver=None):
"""Automatically loads the database driver to be used."""
storage = CONF.get('storage')
if not driver:
driver = storage['driver']
driver_instance = importutils.import_object(
driver,
backend=storage['backend']
)
return driver_instance
def get_storage_opts():
"""Returns a dict that contains list of options for db backend"""
opts = {"storage": _OPTS}
opts.update(_get_elastic_opts())
return opts
def _get_elastic_opts(backend=None):
"""Return Opts for elasticsearch driver"""
if not backend:
backend = "elasticsearch"
es = elastic.ElasticSearchEngine(backend=backend)
return {backend: es.get_opts()}