

def _preprocess_nics(network_details, network_adapters):
    'Check NICs and fill missing data if possible.'
    if (not network_adapters):
        raise exception.CloudbaseInitException('no network adapters available')
    network_adapters = sorted(network_adapters, key=(lambda arg: arg[0]))
    refined_network_details = []
    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)))
        final_status = True
        for (fields, status) in NET_REQUIRE.items():
            if (not status):
                continue
            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:
            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
        if (not nic.mac):
            macs = [adapter[1] for adapter in network_adapters if (adapter[0] == nic.name)]
            mac = (macs[0] if macs else None)
            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

dataset/ETHPy150Open openstack/cloudbase-init/cloudbaseinit/plugins/common/networkconfig.py _preprocess_nics/original