Use stevedore to load storage engine drivers

Use the stevedore library to load the storage engine plugins.

Change-Id: I491317e64e4fa50340e16b0f67783bfeca09c979
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
Doug Hellmann 2012-09-15 16:28:26 -04:00
parent 0a431b2e7c
commit 06b2207ef7
3 changed files with 7 additions and 15 deletions

View File

@ -18,7 +18,7 @@
"""Storage backend management
"""
import pkg_resources
from stevedore import driver
from ceilometer.openstack.common import log
from ceilometer.openstack.common import cfg
@ -53,20 +53,10 @@ def get_engine(conf):
engine_name = urlparse(conf.database_connection).scheme
LOG.debug('looking for %r driver in %r',
engine_name, STORAGE_ENGINE_NAMESPACE)
for ep in pkg_resources.iter_entry_points(STORAGE_ENGINE_NAMESPACE,
engine_name):
try:
engine_class = ep.load()
engine = engine_class()
except Exception as err:
LOG.error('Failed to load storage engine %s: %s',
engine_name, err)
LOG.exception(err)
raise
LOG.info('Loaded %s storage engine %r', engine_name, ep)
return engine
else:
raise RuntimeError('No %r storage engine found' % engine_name)
mgr = driver.DriverManager(STORAGE_ENGINE_NAMESPACE,
engine_name,
invoke_on_load=True)
return mgr.driver
def get_connection(conf):

View File

@ -9,3 +9,4 @@ sqlalchemy
eventlet
anyjson==0.3.1
Flask==0.9
stevedore>=0.4

View File

@ -10,3 +10,4 @@ argparse
sqlalchemy
anyjson==0.3.1
Flask==0.9
stevedore>=0.4