Coverage for drivers/plugins/__init__.py : 0%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import glob
2import importlib
3import os
4import sys
5import traceback
7sys.path.append('/opt/xensource/sm/')
8import util
10plugindir = os.path.dirname(__file__)
12plugins = []
15def _log_exn_backtrace():
16 for line in traceback.format_exc().splitlines():
17 util.SMlog(line)
19for file_name in glob.glob(os.path.join(plugindir, '*.py')):
20 # Avoid recursively loading this module again. The __file__ variable might
21 # have a .pyc extension, so we have to compare the filenames without
22 # extension:
23 if os.path.splitext(file_name)[0] == os.path.splitext(__file__)[0]:
24 continue
25 module_name = os.path.splitext(os.path.split(file_name)[-1])[0]
26 try:
27 module = importlib.import_module('{}.{}'.format(__name__, module_name))
28 plugins.append(module)
29 except:
30 # ignore and log module import errors
31 util.SMlog('Failed to load key lookup plugin {}'.format(module_name))
32 _log_exn_backtrace()
34def load_key(key_hash, vdi_uuid):
35 for plugin in plugins:
36 try:
37 key = plugin.load_key(key_hash, vdi_uuid)
38 if key:
39 return key
40 except:
41 # ignore and log plugin failures
42 util.SMlog('Key lookup plugin {} failed while loading key'
43 ' with hash {} for VDI {}'.format(
44 plugin.__name__, key_hash, vdi_uuid))
45 _log_exn_backtrace()
47 return None