- deal with error results from NM correctly, and don't give up after a single error
authorMark Huang <mlhuang@cs.princeton.edu>
Fri, 2 Jun 2006 04:01:41 +0000 (04:01 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Fri, 2 Jun 2006 04:01:41 +0000 (04:01 +0000)
bwmon.py
pl_mom.py
pl_mom.spec

index b6f5697..1abdda1 100755 (executable)
--- a/bwmon.py
+++ b/bwmon.py
@@ -14,7 +14,7 @@
 # Andy Bavier <acb@cs.princeton.edu>
 # Copyright (C) 2004-2006 The Trustees of Princeton University
 #
-# $Id: bwmon.py,v 1.2 2006/04/28 20:25:19 mlhuang Exp $
+# $Id: bwmon.py,v 1.3 2006/05/08 17:37:28 mlhuang Exp $
 #
 
 import syslog
@@ -111,12 +111,12 @@ class Slice:
         self.exemptbytes = exemptbytes
 
         # Query Node Manager for max rate overrides
-        (new_maxrate, new_maxexemptrate) = nm.query(self.name, ['nm_net_max_rate', 'nm_net_max_exempt_rate'])
-        if new_maxrate is not None:
+        (new_maxrate, new_maxexemptrate) = nm.query(self.name, [('nm_net_max_rate', -1), ('nm_net_max_exempt_rate', -1)])
+        if new_maxrate != -1:
             new_maxrate *= 1000
         else:
             new_maxrate = default_maxrate
-        if new_maxexemptrate is not None:
+        if new_maxexemptrate != -1:
             new_maxexemptrate *= 1000
         else:
             new_maxexemptrate = default_maxexemptrate
@@ -140,10 +140,10 @@ class Slice:
         """
 
         # Query Node Manager for max average rate overrides
-        (self.avgrate, self.avgexemptrate) = nm.query(self.name, ['nm_net_avg_rate', 'nm_net_avg_exempt_rate'])
-        if self.avgrate is None:
+        (self.avgrate, self.avgexemptrate) = nm.query(self.name, [('nm_net_avg_rate', -1), ('nm_net_avg_exempt_rate', -1)])
+        if self.avgrate == -1:
             self.avgrate = default_avgrate
-        if self.avgexemptrate is None:
+        if self.avgexemptrate == -1:
             self.avgexemptrate = default_avgexemptrate
 
         # Prepare message parameters from the template
@@ -273,11 +273,11 @@ def main():
         (version, slices) = pickle.load(f)
         f.close()
         # Check version of data file
-        if version != "$Id: bwmon.py,v 1.2 2006/04/28 20:25:19 mlhuang Exp $":
+        if version != "$Id: bwmon.py,v 1.3 2006/05/08 17:37:28 mlhuang Exp $":
             print "Not using old version '%s' data file %s" % (version, datafile)
             raise Exception
     except Exception:
-        version = "$Id: bwmon.py,v 1.2 2006/04/28 20:25:19 mlhuang Exp $"
+        version = "$Id: bwmon.py,v 1.3 2006/05/08 17:37:28 mlhuang Exp $"
         slices = {}
 
     # Get special slice IDs
index d889e88..51cb34e 100644 (file)
--- a/pl_mom.py
+++ b/pl_mom.py
@@ -5,7 +5,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: pl_mom.py,v 1.2 2006/05/08 17:37:28 mlhuang Exp $
+# $Id: pl_mom.py,v 1.3 2006/05/09 03:22:25 mlhuang Exp $
 #
 
 import os
@@ -184,10 +184,10 @@ class NM:
         Get values of various slice attributes from the local Node Manager
 
         slice - slice name
-        attributes - [attribute_name, (attribute_name, return_value_if_not_set), ...]
+        attributes - [(attribute_name, return_value_if_not_set), ...]
         """
 
-        values = [None for attribute in attributes]
+        values = [attribute[1] for attribute in attributes]
 
         if self.nm is not None:
             try:
@@ -196,18 +196,10 @@ class NM:
                 rspec = rcap.readline().strip()
                 rcap.close()
 
-                for i, attribute in enumerate(attributes):
-                    # NM interface allows you to pass in a tuple
-                    # (attribute, default) instead of just an
-                    # attribute name. default is returned if the
-                    # attribute is not set.
-                    if type(attribute) != tuple:
-                        attribute = (attribute, 0)
-                    (rc, (value,)) = self.nm.nm_inspect(rspec, [attribute])
-                    if rc == 0 and value != attribute[1]:
-                        values[i] = value
+                (rc, result) = self.nm.nm_inspect(rspec, attributes)
+               if rc == 0 and type(result) == list and len(result) == len(values):
+                   values = result
             except Exception, err:
                 print "Warning: Exception received while querying Node Manager:", err
-                self.nm = None
 
         return values
index 34875f4..79545c0 100644 (file)
@@ -1,6 +1,6 @@
 %define name pl_mom
 %define version 0.4
-%define release 2%{?pldistro:.%{pldistro}}%{?date:.%{date}}
+%define release 3%{?pldistro:.%{pldistro}}%{?date:.%{date}}
  
 Summary: PlanetLab node monitoring tools
 Name: %{name}