/usr/lib/python2.7/dist-packages/os_faults/registry.py is in python-os-faults 0.1.17-0ubuntu1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import inspect
import os
import sys
from oslo_utils import importutils
import os_faults
from os_faults.api import base_driver
from os_faults.api import error
DRIVERS = {}
def _import_modules_from_package():
folder = os.path.dirname(os_faults.__file__)
library_root = os.path.normpath(os.path.join(folder, os.pardir))
for root, dirs, files in os.walk(folder):
for filename in files:
if (filename.startswith('__') or
filename.startswith('test') or
not filename.endswith('.py')):
continue
relative_path = os.path.relpath(os.path.join(root, filename),
library_root)
name = os.path.splitext(relative_path)[0] # remove extension
module_name = '.'.join(name.split(os.sep)) # convert / to .
if module_name not in sys.modules:
module = importutils.import_module(module_name)
sys.modules[module_name] = module
else:
module = sys.modules[module_name]
yield module
def _list_drivers():
modules = _import_modules_from_package()
for module in modules:
class_info_list = inspect.getmembers(module, inspect.isclass)
for class_info in class_info_list:
klazz = class_info[1]
if not issubclass(klazz, base_driver.BaseDriver):
continue
if 'NAME' not in vars(klazz): # driver must have a name
continue
if klazz.NAME == 'base': # skip base class
continue
yield klazz
def get_drivers():
global DRIVERS
if not DRIVERS:
DRIVERS = {}
for k in _list_drivers():
driver_name = k.get_driver_name()
if driver_name in DRIVERS:
orig_k = DRIVERS[driver_name]
orig_path = orig_k.__module__ + '.' + orig_k.__name__
dup_path = k.__module__ + '.' + k.__name__
raise error.OSFDriverWithSuchNameExists(
'Driver "%s" already defined in %s. '
'Found a duplicate in %s ' % (
driver_name, orig_path, dup_path))
DRIVERS[driver_name] = k
return DRIVERS
def get_driver(name):
all_drivers = get_drivers()
if name not in all_drivers:
raise error.OSFDriverNotFound('Driver %s is not found' % name)
return all_drivers[name]
|