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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

import glob 

import importlib 

import logging 

import logging.handlers 

import os 

import re 

import sys 

import traceback 

 

import util 

 

plugindir = os.path.dirname(__file__) 

 

plugins = [] 

 

def _log_exn_backtrace(): 

    for line in traceback.format_exc().splitlines(): 

        util.SMlog(line) 

 

for file_name in glob.glob(os.path.join(plugindir, '*.py')): 

    # Avoid recursively loading this module again. The __file__ variable might 

    # have a .pyc extension, so we have to compare the filenames without 

    # extension: 

    if os.path.splitext(file_name)[0] == os.path.splitext(__file__)[0]: 

        continue 

    module_name = os.path.splitext(os.path.split(file_name)[-1])[0] 

    try: 

        module = importlib.import_module('{}.{}'.format(__name__, module_name)) 

        plugins.append(module) 

    except: 

        # ignore and log module import errors 

        util.SMlog('Failed to load key lookup plugin {}'.format(module_name)) 

        _log_exn_backtrace() 

 

def load_key(key_hash, vdi_uuid): 

    for plugin in plugins: 

        try: 

            key = plugin.load_key(key_hash, vdi_uuid) 

            if key: 

                return key 

        except: 

            # ignore and log plugin failures 

            util.SMlog('Key lookup plugin {} failed while loading key' 

                       ' with hash {} for VDI {}'.format( 

                           plugin.__name__, key_hash, vdi_uuid)) 

            _log_exn_backtrace() 

 

    return None