Пример #1
0
def check_and_update_node_interfaces(node):
    """Ensure that node interfaces (e.g. for creation or updating) are valid.

    Updates interfaces with calculated defaults, if they are not provided.

    :param node: node object to check and potentially update
    :raises: InterfaceNotFoundInEntrypoint on validation failure
    :returns: True if any changes were made to the node, otherwise False
    """
    # NOTE(dtantsur): objects raise NotImplementedError on accessing fields
    # that are known, but missing from an object. Thus, we cannot just use
    # getattr(node, 'network_interface', None) here.
    if 'network_interface' in node and node.network_interface is not None:
        if node.network_interface not in CONF.enabled_network_interfaces:
            raise exception.InterfaceNotFoundInEntrypoint(
                iface=node.network_interface,
                entrypoint=NetworkInterfaceFactory._entrypoint_name,
                valid=NetworkInterfaceFactory().names)
    else:
        node.network_interface = (
            CONF.default_network_interface or
            ('flat' if CONF.dhcp.dhcp_provider == 'neutron' else 'noop'))
        return True

    return False
Пример #2
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.InterfaceNotFoundInEntrypoint(
            iface=network_iface,
            entrypoint=network_factory._entrypoint_name,
            valid=network_factory.names)
    driver.network = net_driver
Пример #3
0
def get_interface(driver_or_hw_type, interface_type, interface_name):
    """Get interface implementation instance.

    For hardware types also validates compatibility.

    :param driver_or_hw_type: a hardware type or classic driver instance.
    :param interface_type: name of the interface type (e.g. 'boot').
    :param interface_name: name of the interface implementation from an
                           appropriate entry point
                           (ironic.hardware.interfaces.<interface type>).
    :returns: instance of the requested interface implementation.
    :raises: InterfaceNotFoundInEntrypoint if the entry point was not found.
    :raises: IncompatibleInterface if driver_or_hw_type is a hardware type and
             the requested implementation is not compatible with it.
    """
    factory = _INTERFACE_LOADERS[interface_type]()
    try:
        impl_instance = factory.get_driver(interface_name)
    except KeyError:
        raise exception.InterfaceNotFoundInEntrypoint(
            iface=interface_name,
            entrypoint=factory._entrypoint_name,
            valid=factory.names)

    if not isinstance(driver_or_hw_type, hardware_type.AbstractHardwareType):
        # NOTE(dtantsur): classic drivers do not have notion of compatibility
        return impl_instance

    if isinstance(driver_or_hw_type, fake_hardware.FakeHardware):
        # NOTE(dtantsur): special-case fake hardware type to allow testing with
        # any combinations of interface implementations.
        return impl_instance

    supported_impls = getattr(driver_or_hw_type,
                              'supported_%s_interfaces' % interface_type)
    if type(impl_instance) not in supported_impls:
        raise exception.IncompatibleInterface(
            interface_type=interface_type,
            interface_impl=impl_instance,
            hardware_type=driver_or_hw_type.__class__.__name__)

    return impl_instance