X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=94ba2d12eb2cca27d3df74dd2a5887706f05e6d7;hb=3224c1906c82596a86ae734181488ed14a0f0976;hp=bc4b49e84fd21896b1659e9a76041510e0fa16ca;hpb=b4a5dd8ec367eca5f04b7cf4b8daa31458e6da6c;p=nodemanager.git diff --git a/tools.py b/tools.py index bc4b49e..94ba2d1 100644 --- a/tools.py +++ b/tools.py @@ -1,3 +1,6 @@ +# $Id$ +# $URL$ + """A few things that didn't seem to fit anywhere else.""" import cPickle @@ -8,12 +11,32 @@ import tempfile import threading import fcntl import commands - import logger - PID_FILE = '/var/run/nm.pid' +def get_default_if(): + interface = get_if_from_hwaddr(get_hwaddr_from_plnode()) + if not interface: interface = "eth0" + return interface + +def get_hwaddr_from_plnode(): + try: + for line in open("/usr/boot/plnode.txt", 'r').readlines(): + if line.startswith("NET_DEVICE"): + return line.split("=")[1].strip().strip('"') + except: + pass + return None + +def get_if_from_hwaddr(hwaddr): + import sioc + devs = sioc.gifconf() + for dev in devs: + dev_hwaddr = sioc.gifhwaddr(dev) + if dev_hwaddr == hwaddr: return dev + return None + def as_daemon_thread(run): """Call function with no arguments in its own thread.""" thr = threading.Thread(target=run)