Sync up plugin code from Moniker

Use the get_plugin of StorageEngine instead
Add get_plugin() to Plugin

Change-Id: Icc52b65d7ce98d19da54ffaac523d729feffdeb6
This commit is contained in:
Endre Karlson 2012-11-22 22:10:06 +01:00
parent 1ad51d967a
commit a69b12e620
3 changed files with 21 additions and 10 deletions

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import abc
from stevedore import driver
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import log as logging
@ -42,6 +43,22 @@ class Plugin(object):
"""
return True
@classmethod
def get_plugin(cls, name, ns=None, conf=None, invoke_on_load=False,
invoke_args=(), invoke_kwds={}):
"""
Load a plugin from namespace
"""
ns = ns or cls.__plugin_ns__
if ns is None:
raise RuntimeError('No namespace provided or __plugin_ns__ unset')
LOG.debug('Looking for plugin %s in %s', name, ns)
mgr = driver.DriverManager(ns, name)
if conf:
mgr.driver.register_opts(conf)
return mgr.driver(*invoke_args, **invoke_kwds) if invoke_on_load \
else mgr.driver
@classmethod
def get_canonical_name(cls):
"""

View File

@ -17,14 +17,12 @@
# under the License.
# NOTE(zykes): Copied from Ceilometer
from urlparse import urlparse
from stevedore import driver
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import log
from bufunfa.storage.base import StorageEngine
LOG = log.getLogger(__name__)
DRIVER_NAMESPACE = 'bufunfa.storage'
cfg.CONF.register_opts([
cfg.StrOpt('database_connection',
default='sqlite:///$state_path/bufunfa.db',
@ -42,13 +40,8 @@ def get_engine_name(string):
def get_engine(conf):
scheme = urlparse(conf.database_connection).scheme
engine_name = get_engine_name(scheme)
LOG.debug('looking for %r engine in %r', engine_name, DRIVER_NAMESPACE)
mgr = driver.DriverManager(
DRIVER_NAMESPACE,
engine_name,
invoke_on_load=False)
mgr.driver.register_opts(conf)
return mgr.driver()
return StorageEngine.get_plugin(
engine_name, conf=conf, invoke_on_load=True)
def get_connection(conf):

View File

@ -23,6 +23,7 @@ class StorageEngine(Plugin):
Base class for storage engines
"""
__plugin_ns__ = 'bufunfa.storage'
__plugin_type__ = 'storage'
@abc.abstractmethod