patch by Thomas Dreibholz - ovs-vsctl and not ovs-ovsctl
[nodemanager.git] / bwmon.py
index 0f23390..476ef6d 100644 (file)
--- a/bwmon.py
+++ b/bwmon.py
@@ -23,10 +23,12 @@ import socket
 import copy
 import threading
 
 import copy
 import threading
 
+import plnode.bwlimit as bwlimit
+
 import logger
 import tools
 import logger
 import tools
-import bwlimit
 import database
 import database
+from config import Config
 
 priority = 20
 
 
 priority = 20
 
@@ -38,14 +40,6 @@ ENABLE = True
 
 DB_FILE = "/var/lib/nodemanager/bwmon.pickle"
 
 
 DB_FILE = "/var/lib/nodemanager/bwmon.pickle"
 
-try:
-    sys.path.append("/etc/planetlab")
-    from plc_config import *
-except:
-    DEBUG = True
-    logger.verbose("bwmon: Warning: Configuration file /etc/planetlab/plc_config.py not found")
-    logger.log("bwmon: Running in DEBUG mode.  Logging to file and not emailing.")
-
 # Constants
 seconds_per_day = 24 * 60 * 60
 bits_per_byte = 8
 # Constants
 seconds_per_day = 24 * 60 * 60
 bits_per_byte = 8
@@ -141,16 +135,17 @@ def slicemail(slice, subject, body):
     '''
     Front end to sendmail.  Sends email to slice alias with given subject and body.
     '''
     '''
     Front end to sendmail.  Sends email to slice alias with given subject and body.
     '''
-
-    sendmail = os.popen("/usr/sbin/sendmail -N never -t -f%s" % PLC_MAIL_SUPPORT_ADDRESS, "w")
+    config = Config()
+    sendmail = os.popen("/usr/sbin/sendmail -N never -t -f%s" % config.PLC_MAIL_SUPPORT_ADDRESS, "w")
 
     # Parsed from MyPLC config
 
     # Parsed from MyPLC config
-    to = [PLC_MAIL_MOM_LIST_ADDRESS]
+    to = [config.PLC_MAIL_MOM_LIST_ADDRESS]
 
     if slice is not None and slice != "root":
 
     if slice is not None and slice != "root":
-        to.append(PLC_MAIL_SLICE_ADDRESS.replace("SLICE", slice))
+        to.append(config.PLC_MAIL_SLICE_ADDRESS.replace("SLICE", slice))
 
 
-    header = {'from': "%s Support <%s>" % (PLC_NAME, PLC_MAIL_SUPPORT_ADDRESS),
+    header = {'from': "%s Support <%s>" % (config.PLC_NAME,
+                                           config.PLC_MAIL_SUPPORT_ADDRESS),
               'to': ", ".join(to),
               'version': sys.version.split(" ")[0],
               'subject': subject}
               'to': ", ".join(to),
               'version': sys.version.split(" ")[0],
               'subject': subject}
@@ -428,7 +423,7 @@ class Slice:
         if (runningrates['maxrate'] != new_maxrate) or \
         (runningrates['minrate'] != self.MinRate * 1000) or \
         (runningrates['maxexemptrate'] != new_maxi2rate) or \
         if (runningrates['maxrate'] != new_maxrate) or \
         (runningrates['minrate'] != self.MinRate * 1000) or \
         (runningrates['maxexemptrate'] != new_maxi2rate) or \
-        (runningrates['minexemptrate'] != self.Mini2Rate * 1000) or \
+        ('minexemptrate' in runningrates and runningrates['minexemptrate'] != self.Mini2Rate * 1000) or \
         (runningrates['share'] != self.Share):
             # Apply parameters
             bwlimit.set(xid = self.xid, dev = dev_default,
         (runningrates['share'] != self.Share):
             # Apply parameters
             bwlimit.set(xid = self.xid, dev = dev_default,
@@ -487,8 +482,8 @@ def sync(nmdbcopy):
         period, \
         default_MaxRate, \
         default_Maxi2Rate, \
         period, \
         default_MaxRate, \
         default_Maxi2Rate, \
-        default_MaxKByte,\
-        default_Maxi2KByte,\
+        default_MaxKByte, \
+        default_Maxi2KByte, \
         default_Share, \
         dev_default
 
         default_Share, \
         dev_default
 
@@ -502,6 +497,9 @@ def sync(nmdbcopy):
     if default_MaxRate == -1:
         default_MaxRate = 1000000
 
     if default_MaxRate == -1:
         default_MaxRate = 1000000
 
+    # xxx $Id$ 
+    # with svn we used to have a trick to detect upgrades of this file
+    # this has gone with the move to git, without any noticeable effect on operations though
     try:
         f = open(DB_FILE, "r+")
         logger.verbose("bwmon: Loading %s" % DB_FILE)
     try:
         f = open(DB_FILE, "r+")
         logger.verbose("bwmon: Loading %s" % DB_FILE)
@@ -658,7 +656,7 @@ def sync(nmdbcopy):
             # Update byte counts
             slice.update(kernelhtbs[xid], live[xid]['_rspec'])
 
             # Update byte counts
             slice.update(kernelhtbs[xid], live[xid]['_rspec'])
 
-    logger.verbose("bwmon: Saving %s slices in %s" % (slices.keys().__len__(),DB_FILE))
+    logger.verbose("bwmon: Saving %s slices in %s" % (slices.keys().__len__(), DB_FILE))
     f = open(DB_FILE, "w")
     pickle.dump((version, slices, deaddb), f)
     f.close()
     f = open(DB_FILE, "w")
     pickle.dump((version, slices, deaddb), f)
     f.close()
@@ -671,7 +669,7 @@ def getDefaults(nmdbcopy):
     '''
     status = True
     # default slice
     '''
     status = True
     # default slice
-    dfltslice = nmdbcopy.get(PLC_SLICE_PREFIX+"_default")
+    dfltslice = nmdbcopy.get(Config().PLC_SLICE_PREFIX+"_default")
     if dfltslice:
         if dfltslice['rspec']['net_max_rate'] == -1:
             allOff()
     if dfltslice:
         if dfltslice['rspec']['net_max_rate'] == -1:
             allOff()