gateway = None
networks = data['networks']
failedToGetSettings = False
+
+ # NOTE: GetInterfaces/NodeNetworks does not necessarily order the interfaces
+ # returned. Because 'interface'is decremented as each interface is processed,
+ # by the time is_primary=True (primary) interface is reached, the device
+ # "eth%s" % interface, is not eth0. But, something like eth-4, or eth-12.
+ # This code sorts the interfaces, placing is_primary=True interfaces first.
+ # There is a lot of room for improvement to how this
+ # script handles interfaces and how it chooses the primary interface.
+ def compare_by (fieldname):
+ def compare_two_dicts (a, b):
+ return cmp(a[fieldname], b[fieldname])
+ return compare_two_dicts
+
+ # NOTE: by sorting on 'is_primary' and then reversing (since False is sorted
+ # before True) all 'is_primary' interfaces are at the beginning of the list.
+ networks.sort( compare_by('is_primary') )
+ networks.reverse()
+
for network in networks:
logger.verbose('net:InitInterfaces interface %d: %s'%(interface,network))
logger.verbose('net:InitInterfaces macs = %s' % macs)