예제 #1
0
def _attach_interfaces_to_driver(driver, node, driver_name=None):
    driver_singleton = get_driver(driver_name or node.driver)
    for iface in driver_singleton.all_interfaces:
        impl = getattr(driver_singleton, iface, None)
        setattr(driver, iface, impl)

    network_iface = node.network_interface
    network_factory = NetworkInterfaceFactory()
    try:
        net_driver = network_factory.get_driver(network_iface)
    except KeyError:
        raise exception.DriverNotFoundInEntrypoint(
            driver_name=network_iface,
            entrypoint=network_factory._entrypoint_name)
    driver.network = net_driver
예제 #2
0
 def missing_callback(names):
     names = ', '.join(names)
     raise exception.DriverNotFoundInEntrypoint(
         names=names, entrypoint=cls._entrypoint_name)
예제 #3
0
    def _init_extension_manager(cls):
        # NOTE(deva): In case multiple greenthreads queue up on this lock
        #             before _extension_manager is initialized, prevent
        #             creation of multiple NameDispatchExtensionManagers.
        if cls._extension_manager:
            return
        enabled_drivers = getattr(CONF, cls._enabled_driver_list_config_option,
                                  [])

        # Check for duplicated driver entries and warn the operator
        # about them
        counter = collections.Counter(enabled_drivers).items()
        duplicated_drivers = []
        cls._enabled_driver_list = []
        for item, cnt in counter:
            if not item:
                LOG.warning(
                    _LW('An empty driver was specified in the "%s" '
                        'configuration option and will be ignored. Please '
                        'fix your ironic.conf file to avoid this warning '
                        'message.'), cls._enabled_driver_list_config_option)
                continue
            if cnt > 1:
                duplicated_drivers.append(item)
            cls._enabled_driver_list.append(item)
        if duplicated_drivers:
            LOG.warning(
                _LW('The driver(s) "%s" is/are duplicated in the '
                    'list of enabled_drivers. Please check your '
                    'configuration file.'), ', '.join(duplicated_drivers))

        # NOTE(deva): Drivers raise "DriverLoadError" if they are unable to be
        #             loaded, eg. due to missing external dependencies.
        #             We capture that exception, and, only if it is for an
        #             enabled driver, raise it from here. If enabled driver
        #             raises other exception type, it is wrapped in
        #             "DriverLoadError", providing the name of the driver that
        #             caused it, and raised. If the exception is for a
        #             non-enabled driver, we suppress it.
        def _catch_driver_not_found(mgr, ep, exc):
            # NOTE(deva): stevedore loads plugins *before* evaluating
            #             _check_func, so we need to check here, too.
            if ep.name in cls._enabled_driver_list:
                if not isinstance(exc, exception.DriverLoadError):
                    raise exception.DriverLoadError(driver=ep.name, reason=exc)
                raise exc

        def _check_func(ext):
            return ext.name in cls._enabled_driver_list

        cls._extension_manager = (dispatch.NameDispatchExtensionManager(
            cls._entrypoint_name,
            _check_func,
            invoke_on_load=True,
            on_load_failure_callback=_catch_driver_not_found,
            propagate_map_exceptions=True))

        # NOTE(deva): if we were unable to load any configured driver, perhaps
        #             because it is not present on the system, raise an error.
        if (sorted(cls._enabled_driver_list) != sorted(
                cls._extension_manager.names())):
            found = cls._extension_manager.names()
            names = [n for n in cls._enabled_driver_list if n not in found]
            # just in case more than one could not be found ...
            names = ', '.join(names)
            raise exception.DriverNotFoundInEntrypoint(
                names=names, entrypoint=cls._entrypoint_name)

        # warn for any untested/unsupported/deprecated drivers or interfaces
        cls._extension_manager.map(cls._extension_manager.names(),
                                   _warn_if_unsupported)

        LOG.info(cls._logging_template, cls._extension_manager.names())