def _preprocess_nics(network_details, network_adapters):
    # Initial checks.
    if not network_adapters:
        raise exception.CloudbaseInitException(
            "no network adapters available")
    # Sort VM adapters by name (assuming that those
    # from the context are in correct order).
    # Do this for a better matching by order
    # if hardware address is missing.
    network_adapters = sorted(network_adapters, key=lambda arg: arg[0])
    refined_network_details = []    # store here processed interfaces
    # Check and update every NetworkDetails object.
    total = len(network_adapters)
    for nic in network_details:
        if not isinstance(nic, service_base.NetworkDetails):
            raise exception.CloudbaseInitException(
                "invalid NetworkDetails object {!r}"
                .format(type(nic))
            )
        # Check requirements.
        final_status = True
        for fields, status in NET_REQUIRE.items():
            if not status:
                continue    # skip 'not required' entries
            if not isinstance(fields, tuple):
                fields = (fields,)
            final_status = any([getattr(nic, field) for field in fields])
            if not final_status:
                break
        address, netmask = nic.address, nic.netmask
        if final_status:
            # Additional check for info version.
            if not (address and netmask):
                final_status = nic.address6 and nic.netmask6
                if final_status:
                    address = address or network.address6_to_4_truncate(
                        nic.address6)
                    netmask = netmask or network.netmask6_to_4_truncate(
                        nic.netmask6)
        if not final_status:
            LOG.error("Incomplete NetworkDetails object %s", nic)
            continue
        # Complete hardware address if missing by selecting
        # the corresponding MAC in terms of naming, then ordering.
        if not nic.mac:
            # By name...
            macs = [adapter[1] for adapter in network_adapters
                    if adapter[0] == nic.name]
            mac = macs[0] if macs else None
            # ...or by order.
            idx = _name2idx(nic.name)
            if not mac and idx < total:
                mac = network_adapters[idx][1]
            nic = service_base.NetworkDetails(
                nic.name,
                mac,
                address,
                nic.address6,
                netmask,
                nic.netmask6,
                nic.broadcast,
                nic.gateway,
                nic.gateway6,
                nic.dnsnameservers
            )
        refined_network_details.append(nic)
    return refined_network_details
Attempts to discover IMAP settings for a given email address.
dataset/ETHPy150Open openstack/cloudbase-init/cloudbaseinit/plugins/common/networkconfig.py/_preprocess_nics--crossover with--dataset/ETHPy150Open contextio/Python-ContextIO/contextio/lib/api.py/Api.get_discovery