X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plnet.py;h=abfeb375cd002f35090cf3838f8601bbe5b43bdf;hb=ff4f3eff4f870d1d26f5c7f14f45bbcef08e6340;hp=fd44eb345a9d57add94e123a26388e5b72893415;hpb=7877e3b72811d6d588103463460b23ccbe100c17;p=pyplnet.git diff --git a/plnet.py b/plnet.py index fd44eb3..abfeb37 100755 --- a/plnet.py +++ b/plnet.py @@ -37,6 +37,24 @@ 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, 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) @@ -67,10 +85,12 @@ def InitInterfaces(logger, plc, data, root="", files_only=False, program="NodeMa inter['BOOTPROTO'] = "static" inter['IPADDR'] = network['ip'] inter['NETMASK'] = network['netmask'] - inter['DNS1'] = network['dns1'] - inter['DNS2'] = network['dns2'] if network['is_primary']: gateway = network['gateway'] + if network['dns1']: + inter['DNS1'] = network['dns1'] + if network['dns2']: + inter['DNS2'] = network['dns2'] elif network['method'] == "dhcp": inter['BOOTPROTO'] = "dhcp" @@ -138,7 +158,7 @@ def InitInterfaces(logger, plc, data, root="", files_only=False, program="NodeMa (inter['IFNAME'],hwifname)) inter['IFNAME'] = hwifname else: - logger.log('net:InitInterfaces WARNING: mac addr %s for alias not found' %(hwaddr,alias)) + logger.log('net:InitInterfaces WARNING: mac addr %s for alias not found' %(hwaddr)) if 'IFNAME' in inter: # stupid RH /etc/sysconfig/network-scripts/ifup-aliases:new_interface()