Beispiel #1
0
def load_plugins():
    plugins = {}
    cl = classloader.ClassLoader()
    for class_path in CONF.user_data_plugins:
        plugin = cl.load_class(class_path)()
        plugins[plugin.get_mime_type()] = plugin
    return plugins
Beispiel #2
0
def get_os_utils():
    osutils_class_paths = {
        'nt': 'cloudbaseinit.osutils.windows.WindowsUtils',
        'posix': 'cloudbaseinit.osutils.posix.PosixUtils'
    }

    cl = classloader.ClassLoader()
    return cl.load_class(osutils_class_paths[os.name])()
Beispiel #3
0
 def get_metadata_service(self):
     # Return the first service that loads correctly
     cl = classloader.ClassLoader()
     for class_path in CONF.metadata_services:
         service = cl.load_class(class_path)()
         try:
             if service.load():
                 return service
         except Exception, ex:
             LOG.error('Failed to load metadata service \'%(class_path)s\' '
                       'with error: %(ex)s' % locals())
Beispiel #4
0
def get_metadata_service():
    # Return the first service that loads correctly
    cl = classloader.ClassLoader()
    for class_path in CONF.metadata_services:
        service = cl.load_class(class_path)()
        try:
            if service.load():
                return service
        except Exception as ex:
            LOG.error("Failed to load metadata service '%s'" % class_path)
            LOG.exception(ex)
    raise exception.CloudbaseInitException("No available service found")
Beispiel #5
0
    def process(self, part):
        temp_dir = tempfile.gettempdir()
        part_handler_path = os.path.join(temp_dir, part.get_filename())
        encoding.write_file(part_handler_path, part.get_payload())

        part_handler = classloader.ClassLoader().load_module(part_handler_path)

        if (part_handler and
                hasattr(part_handler, "list_types") and
                hasattr(part_handler, "handle_part")):
            part_handlers_dict = {}
            for handled_type in part_handler.list_types():
                part_handlers_dict[handled_type] = part_handler.handle_part
            return part_handlers_dict
Beispiel #6
0
def get_config_drive_manager():
    class_paths = {
        'win32':
        'cloudbaseinit.metadata.services.osconfigdrive.windows.'
        'WindowsConfigDriveManager',
    }

    class_path = class_paths.get(sys.platform)
    if not class_path:
        raise NotImplementedError('ConfigDrive is not supported on '
                                  'this platform: %s' % sys.platform)

    cl = classloader.ClassLoader()
    return cl.load_class(class_path)()
Beispiel #7
0
def get_template_engine(user_data):
    """Returns the first template engine that loads correctly"""

    cl = classloader.ClassLoader()
    for class_path in TEMPLATE_ENGINE_CLASS_PATHS:
        tpl_engine = cl.load_class(class_path)()
        try:
            if tpl_engine.load(user_data):
                LOG.info("Using template engine: %s" %
                         tpl_engine.get_template_type())
                return tpl_engine
        except Exception as ex:
            LOG.error("Failed to load template engine '%s'" % class_path)
            LOG.exception(ex)
    return
Beispiel #8
0
def get_storage_manager():
    class_paths = {
        "VDS": "cloudbaseinit.utils.windows.storage.vds_storage_manager."
        "VDSStorageManager",
        "WSM": "cloudbaseinit.utils.windows.storage.wsm_storage_manager."
        "WSMStorageManager",
    }

    osutils = osutils_factory.get_os_utils()
    cl = classloader.ClassLoader()
    if os.name == "nt":
        if osutils.is_nano_server():
            # VDS is not available on Nano Server
            # WSM supersedes VDS since Windows Server 2012 / Windows 8
            return cl.load_class(class_paths["WSM"])()
        else:
            return cl.load_class(class_paths["VDS"])()

    raise NotImplementedError("No storage manager available for this platform")
Beispiel #9
0
def load_plugins(stage):
    plugins = []
    cl = classloader.ClassLoader()
    for class_path in CONF.plugins:
        if class_path in OLD_PLUGINS:
            new_class_path = OLD_PLUGINS[class_path]
            LOG.warn("Old plugin module %r was found. The new name is %r. "
                     "The old name will not be supported starting with "
                     "cloudbaseinit 1.0", class_path, new_class_path)
            class_path = new_class_path

        try:
            plugin_cls = cl.load_class(class_path)
            if not stage or plugin_cls.execution_stage == stage:
                plugin = plugin_cls()
                plugins.append(plugin)
        except ImportError:
            LOG.error("Could not import plugin module %r", class_path)
            continue
    return plugins
 def load_plugins(self):
     plugins = []
     cl = classloader.ClassLoader()
     for class_path in CONF.plugins:
         plugins.append(cl.load_class(class_path)())
     return plugins
Beispiel #11
0
def load_plugins():
    loader = classloader.ClassLoader()
    return {
        section: loader.load_class(class_path)().process
        for section, class_path in PLUGINS.items()
    }
Beispiel #12
0
def get_os_utils():
    cl = classloader.ClassLoader()
    return cl.load_class('cloudbaseinit.osutils.freebsd.FreeBSDUtils')()
Beispiel #13
0
def get_options():
    """Return a list of all the available `Options` subclasses."""
    loader = classloader.ClassLoader()
    return [loader.load_class(class_path) for class_path in _OPT_PATHS]
 def setUp(self):
     self._loader = classloader.ClassLoader()