"""Defines interface for DB access.
-The underlying driver is loaded as a :class:`LazyPluggable`.
-
Functions in this module are imported into the cinder.db namespace. Call these
functions from cinder.db namespace, not the cinder.db.api namespace.
**Related Flags**
-:backend: string to lookup in the list of LazyPluggable backends.
- `sqlalchemy` is the only supported backend right now.
-
:connection: string specifying the sqlalchemy connection to use, like:
`sqlite:///var/lib/cinder/cinder.sqlite`.
db_opts = [
- # TODO(rpodolyaka): this option is deprecated but still passed to
- # LazyPluggable class which doesn't support retrieving
- # of options put into groups. Nova's version of this
- # class supports this. Perhaps, we should put it to Oslo
- # and then reuse here.
- cfg.StrOpt('db_backend',
- default='sqlalchemy',
- help='The backend to use for db'),
cfg.BoolOpt('enable_new_services',
default=True,
help='Services to be added to the available pool on create'),
return (begin, end)
-class LazyPluggable(object):
- """A pluggable backend loaded lazily based on some value."""
-
- def __init__(self, pivot, **backends):
- self.__backends = backends
- self.__pivot = pivot
- self.__backend = None
-
- def __get_backend(self):
- if not self.__backend:
- backend_name = CONF[self.__pivot]
- if backend_name not in self.__backends:
- raise exception.Error(_('Invalid backend: %s') % backend_name)
-
- backend = self.__backends[backend_name]
- if isinstance(backend, tuple):
- name = backend[0]
- fromlist = backend[1]
- else:
- name = backend
- fromlist = backend
-
- self.__backend = __import__(name, None, None, fromlist)
- LOG.debug('backend %s', self.__backend)
- return self.__backend
-
- def __getattr__(self, key):
- backend = self.__get_backend()
- return getattr(backend, key)
-
-
class ProtectedExpatParser(expatreader.ExpatParser):
"""An expat parser which disables DTD's and entities by default."""