don't hardcode the device name.
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 14 Oct 2009 08:47:48 +0000 (08:47 +0000)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 14 Oct 2009 08:47:48 +0000 (08:47 +0000)
bwmon.py
net.py
tools.py

index 69325c9..a80a586 100644 (file)
--- a/bwmon.py
+++ b/bwmon.py
@@ -52,8 +52,9 @@ except:
 seconds_per_day = 24 * 60 * 60
 bits_per_byte = 8
 
+dev_default = tools.get_default_if()
 # Burst to line rate (or node cap).  Set by NM. in KBit/s
-default_MaxRate = int(bwlimit.get_bwcap() / 1000)
+default_MaxRate = int(bwlimit.get_bwcap(dev_default) / 1000)
 default_Maxi2Rate = int(bwlimit.bwmax / 1000)
 # 5.4 Gbyte per day. 5.4 * 1024 k * 1024M * 1024G 
 # 5.4 Gbyte per day max allowed transfered per recording period
@@ -704,7 +705,7 @@ def run():
         nmdbcopy = copy.deepcopy(database.db)
         database.db_lock.release()
         try:  
-            if getDefaults(nmdbcopy) and len(bwlimit.tc("class show dev eth0")) > 0:
+            if getDefaults(nmdbcopy) and len(bwlimit.tc("class show dev %s" % dev_default)) > 0:
                 # class show to check if net:InitNodeLimit:bwlimit.init has run.
                 sync(nmdbcopy)
             else: logger.log("bwmon:  BW limits DISABLED.")
diff --git a/net.py b/net.py
index 2d02905..be4e16e 100644 (file)
--- a/net.py
+++ b/net.py
@@ -11,7 +11,9 @@ import os, string, time, socket
 import sioc, plnet
 
 # local modules
-import bwlimit, logger, iptables
+import bwlimit, logger, iptables, tools
+
+dev_default = tools.get_default_if()
 
 def start(options, conf):
     logger.log("net plugin starting up...")
@@ -22,7 +24,7 @@ def GetSlivers(data, config, plc):
     if 'OVERRIDES' in dir(config): 
         if config.OVERRIDES.get('net_max_rate') == '-1':
             logger.log("net: Slice and node BW Limits disabled.")
-            if len(bwlimit.tc("class show dev eth0")): 
+            if len(bwlimit.tc("class show dev %s" % dev_default)): 
                 logger.verbose("*** DISABLING NODE BW LIMITS ***")
                 bwlimit.stop()
         else:
index bc4b49e..bd911e8 100644 (file)
--- 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 <run> with no arguments in its own thread."""
     thr = threading.Thread(target=run)