Merge changeset 11123 from the trunk
authorDaniel Hokka Zakrisson <dhokka@cs.princeton.edu>
Mon, 24 Nov 2008 17:09:46 +0000 (17:09 +0000)
committerDaniel Hokka Zakrisson <dhokka@cs.princeton.edu>
Mon, 24 Nov 2008 17:09:46 +0000 (17:09 +0000)
NodeManager.spec
nm.py
plugins/codemux.py [moved from codemux.py with 96% similarity]
plugins/vsys.py [moved from vsys.py with 98% similarity]

index 185db5c..093eba6 100644 (file)
@@ -97,7 +97,9 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-,root,root,-)
 %doc
 %dir %{_datadir}/NodeManager
+%dir %{_datadir}/NodeManager/plugins
 %{_datadir}/NodeManager/*
+%{_datadir}/NodeManager/plugins/*
 %{_bindir}/forward_api_calls
 %{_initrddir}/nm
 %{_initrddir}/conf_files
diff --git a/nm.py b/nm.py
index bb0a2ab..36d121b 100755 (executable)
--- a/nm.py
+++ b/nm.py
@@ -39,9 +39,15 @@ parser.add_option('-k', '--session', action='store', dest='session', default='/e
 parser.add_option('-p', '--period', action='store', dest='period', default=600, help='Polling interval (sec)')
 parser.add_option('-r', '--random', action='store', dest='random', default=301, help='Range for additional random polling interval (sec)')
 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='more verbose log')
+parser.add_option('-P', '--path', action='store', dest='path', default='/usr/share/NodeManager/plugins', help='Path to plugins directory')
 parser.add_option('-m', '--module', action='store', dest='module', default='', help='run a single module among '+' '.join(known_modules))
 (options, args) = parser.parse_args()
 
+# Deal with plugins directory
+if os.path.exists(options.path):
+    sys.path.append(options.path)
+    known_modules += [i[:-3] for i in os.listdir(options.path) if i.endswith(".py") and (i[:-3] not in known_modules)]
+
 modules = []
 
 def GetSlivers(plc):
similarity index 96%
rename from codemux.py
rename to plugins/codemux.py
index 7b11350..ce69e4a 100644 (file)
@@ -16,7 +16,10 @@ def start(options, config):
 
 
 def GetSlivers(data):
-    """For each sliver with the codemux attribute, parse out "host,port" and make entry in conf.  Restart service after."""
+    """
+    For each sliver with the codemux attribute, parse out "host,port" 
+    and make entry in conf.  Restart service after.
+    """
     logger.log("codemux:  Starting.", 2)
     # slices already in conf
     slicesinconf = parseConf()
@@ -30,7 +33,7 @@ def GetSlivers(data):
     # Parse attributes and update dict of scripts
     for sliver in data['slivers']:
         for attribute in sliver['attributes']:
-            if attribute['name'] == 'codemux':
+            if attribute['tagname'] == 'codemux':
                 # add to conf.  Attribute is [host, port]
                 params = {'host': attribute['value'].split(",")[0], 
                           'port': attribute['value'].split(",")[1]}
similarity index 98%
rename from vsys.py
rename to plugins/vsys.py
index c72941c..d26ee4a 100644 (file)
--- a/vsys.py
@@ -25,7 +25,7 @@ def GetSlivers(data):
     # Parse attributes and update dict of scripts
     for sliver in data['slivers']:
         for attribute in sliver['attributes']:
-            if attribute['name'] == 'vsys':
+            if attribute['tagname'] == 'vsys':
                 if sliver['name'] not in slices:
                     # add to conf
                     slices.append(sliver['name'])
@@ -46,7 +46,7 @@ def createVsysDir(sliver):
     try: 
         os.mkdir("/vservers/%s/vsys" % sliver)
         return True
-    except OSError:
+    except OSError: 
         return False