X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=bd911e8fa317ee8ad3a18f0e1ceca7561d6da8d4;hb=daea12f08fc20740d05dcde1cd9512b8b308b54c;hp=bc4b49e84fd21896b1659e9a76041510e0fa16ca;hpb=c06eab4d42d0dbe8a42d9007fe69453301a33ccf;p=nodemanager.git diff --git a/tools.py b/tools.py index bc4b49e..bd911e8 100644 --- a/tools.py +++ b/tools.py @@ -8,12 +8,31 @@ import tempfile import threading import fcntl import commands +import sioc 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(): + for line in open("/usr/share/boot/plnode.txt", 'r').readlines(): + if line.startswith("NET_DEVICE"): + return line.split("=")[1].strip().strip('"') + return None + +def get_if_from_hwaddr(hwaddr): + 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)