From f18c2cbddd90d35305887ef3a6346a693b9a05ea Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Mon, 8 Jun 2009 16:10:46 +0000 Subject: [PATCH] addresses one bug that failed to create ifcfg-eth0 for mlab boot images. Because the variable 'interface' is decremented as each interface is processed, by the time the primary, is_primary=True interface is reached, the device name "eth%s" % interface, is not eth0, but, something like eth-4, or eth-12. This patch sorts the interfaces, implicitly placing the primary (first created) interface first. There is a lot of room for improvement to how this script handles interfaces and how it chooses the primary interface. --- plnet.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plnet.py b/plnet.py index fd44eb3..1c92123 100755 --- a/plnet.py +++ b/plnet.py @@ -37,6 +37,23 @@ def InitInterfaces(logger, plc, data, root="", files_only=False, program="NodeMa 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, implicitly placing the primary (first created) + # interface 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 + if version == 4.3: + networks.sort( compare_by('interface_id') ) + else: + networks.sort( compare_by('nodenetwork_id') ) + for network in networks: logger.verbose('net:InitInterfaces interface %d: %s'%(interface,network)) logger.verbose('net:InitInterfaces macs = %s' % macs) -- 2.43.0