def useable_interfaces()

in misc/kickstart_create_network_line.py [0:0]


def useable_interfaces(net_devs, nc, iface_speed):
    ''' This takes a go at figuring out which interfaces to use.'''
    iface_list = False
    notes = False
    if TO_LOG:
        print("in usable interfaces")

    if "bond" not in nc['BOND_DEVICE'].lower():
        if TO_LOG:
            print("useable interfaces if not", nc['BOND_DEVICE'])
        #  Not doing a bond, so  we check to make sure the requested device,
        #  nc['BOND_DEVICE'], is in the list of devices with carrier:
        if nc['BOND_DEVICE'] == '""':
            # In this case we have no network interface in the configuration but we
            # network settings.
            # First we check how many net_devs we have:
            if TO_LOG:
                print("nc['BOND_DEVICE']=''", len(net_devs), net_devs)
            if len(net_devs) == 1: # This is a dict of speed: devices
                speeds = net_devs.keys()
                speeds.sort(reverse=True)
                speed = speeds[0]
                possibles = net_devs[speed]
                if TO_LOG:
                    print(possibles)
                # At this point we have options, but no information, so:
                notes = "No device in the configuration file and multiple devices found. Picking the first"
                iface_list = [possibles[0]]
        else:
            if TO_LOG:
                print("inner else")
            for speed in net_devs:
                if nc['BOND_DEVICE'] in net_devs[speed]:
                    iface_list = [nc['BOND_DEVICE']]
                else:
                    iface_list = [nc['BOND_DEVICE']]
                    notes = "{0} did not have carrier at install time, and may not work".format(nc['BOND_DEVICE'])
    elif iface_speed != 'auto':
        if len(net_devs[iface_speed]) > 0:
            iface_list = net_devs[iface_speed]
        else:
            notes = "no devices set to {0}".format(iface_speed)
    else: # This SHOULD be iface_speed == auto, and nc['BOND_DEVCE'] containing bond.
        #  if not it is anyway.
        # Thus we are doing a bond of some sort.
        # This gives us the fastest interfaces first:
        speeds = [k for k in sorted(net_devs.keys(), reverse=True)]
        fastest = speeds[0]
        # Walk through "speeds" and take the first one that has more than one
        # interface. This will only set iface_list if there are 2 or more interfaces:
        # previous_speed = 0
        for i in speeds:
            if len(net_devs[i]) > 1:
                iface_list = net_devs[i]
                break
        if TO_LOG:
            print("iface list:", iface_list)
        # if iface_list is still false, and we are requesting a bond, we will
        # want the fastest interface with link:
        if (iface_list == False) and ("bond" in nc['BOND_DEVICE'].lower()):
                if TO_LOG:
                    print(len(net_devs), net_devs, i)
                if len(net_devs) == 0:
                    iface_list = net_devs
                    notes = "no devices found for the bond. Will not have network after reboot"
                else:
                    iface_list = net_devs[fastest] # This is assuming that we'll want to bond the fastest interaface.
                    if TO_LOG:
                        print("dev:", net_devs[fastest])
    if TO_LOG:
        print(iface_list, notes)
    return iface_list, notes