* give all modules access to the API and to the config class
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 29 Jun 2009 20:56:52 +0000 (20:56 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 29 Jun 2009 20:56:52 +0000 (20:56 +0000)
* Fix delegation
* codemux can be disabled using the _default slice

api.py
bwmon.py
conf_files.py
nm.py
plugins/codemux.py
plugins/vsys.py
sm.py

diff --git a/api.py b/api.py
index 0e51ba3..9b09d06 100644 (file)
--- a/api.py
+++ b/api.py
@@ -62,7 +62,7 @@ class APIRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
             SO_PEERCRED = 17
             sizeof_struct_ucred = 12
             ucred = self.request.getsockopt(socket.SOL_SOCKET, SO_PEERCRED, sizeof_struct_ucred)
-            xid = struct.unpack('3i', ucred)[2]
+            xid = struct.unpack('3i', ucred)[1]
             caller_name = pwd.getpwuid(xid)[0]
             # Special case the genicw
             if method_name == "AdminTicket":
index 53eb3bc..69325c9 100644 (file)
--- a/bwmon.py
+++ b/bwmon.py
@@ -661,7 +661,8 @@ def sync(nmdbcopy):
     pickle.dump((version, slices, deaddb), f)
     f.close()
 
-
+# doesnt use generic default interface because this runs as its own thread.
+# changing the config variable will not have an effect since GetSlivers: pass
 def getDefaults(nmdbcopy):
     '''
     Get defaults from default slice's slice attributes.
index 94560d6..fc90da2 100644 (file)
@@ -86,7 +86,7 @@ class conf_files:
 
 def start(options, config): pass
 
-def GetSlivers(data):
+def GetSlivers(data, plc = None, config = None):
     logger.log("conf_files: Running.")
     cf = conf_files()
     cf.run_once(data)
diff --git a/nm.py b/nm.py
index 2c05d20..1dd1b67 100755 (executable)
--- a/nm.py
+++ b/nm.py
@@ -70,7 +70,7 @@ def GetSlivers(plc, config):
     for module in modules:
         try:        
             callback = getattr(module, 'GetSlivers')
-            callback(data)
+            callback(data, plc, config)
         except: logger.log_exc()
 
 
index 78ae100..aa29351 100644 (file)
@@ -15,11 +15,17 @@ def start(options, config):
     pass
 
 
-def GetSlivers(data):
+def GetSlivers(data, plc = None, config = None):
     """
     For each sliver with the codemux attribute, parse out "host,port" 
     and make entry in conf.  Restart service after.
     """
+    if 'OVERRIDES' in dir(config):
+        if config.OVERRIDES.get('codemux') == '-1':
+            logger.log("codemux:  Disabled", 2)
+            stopService()
+            return
+
     logger.log("codemux:  Starting.", 2)
     # slices already in conf
     slicesinconf = parseConf()
@@ -63,7 +69,10 @@ def GetSlivers(data):
             logger.log("codemux:  Removing %s" % deadslice)
             _writeconf = True 
 
-    if _writeconf:  writeConf(sortDomains(codemuxslices))
+    if _writeconf:  writeConf(sortDomains(codemuxslices))    
+    # ensure the service is running
+    startService()
+
 
 def writeConf(slivers, conf = CODEMUXCONF):
     '''Write conf with default entry up top. Elements in [] should have lower order domain names first. Restart service.'''
@@ -84,6 +93,7 @@ def writeConf(slivers, conf = CODEMUXCONF):
     try:  restartService()
     except:  logger.log_exc()
 
+
 def sortDomains(slivers):
     '''Given a dict of {slice: {domainname, port}}, return array of slivers with lower order domains first'''
     dnames = {} # {host: slice}
@@ -100,6 +110,7 @@ def sortDomains(slivers):
     for host in hosts: sortedslices.append({host: dnames[host]})
     
     return sortedslices
+
         
 def parseConf(conf = CODEMUXCONF):
     '''Parse the CODEMUXCONF and return dict of slices in conf. {slice: (host,port)}'''
@@ -119,6 +130,29 @@ def parseConf(conf = CODEMUXCONF):
     except IOError: logger.log_exc()
     return slicesinconf
 
+
+def isRunning():
+    if len(os.popen("pidof codemux").readline().rstrip("\n")) > 0:
+        return True
+    else:
+        return False
+
+
 def restartService():
     logger.log("codemux:  Restarting codemux service")
-    os.system("/etc/init.d/codemux condrestart")
+    if isRunning():
+        logger.log_call("/etc/init.d/codemux","condrestart")
+    else:
+        logger.log_call("/etc/init.d/codemux","restart")
+
+
+def startService():
+    if not isRunning():
+        logger.log("codemux:  Starting codemux service")
+        logger.log_call("/etc/init.d/codemux", "start")
+
+
+def stopService():
+    if isRunning():
+        logger.log("codemux:  Stopping codemux service")
+        logger.log_call("/etc/init.d/codemux", "stop")
index 939158c..dad1b75 100644 (file)
@@ -14,7 +14,7 @@ def start(options, config):
     pass
 
 
-def GetSlivers(data):
+def GetSlivers(data, plc = None, config = None):
     """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys."""
     # Touch ACLs and create dict of available
     scripts = {}
diff --git a/sm.py b/sm.py
index bcf2dbf..395a3fb 100644 (file)
--- a/sm.py
+++ b/sm.py
@@ -54,7 +54,7 @@ DEFAULT_ALLOCATION = {
 start_requested = False  # set to True in order to request that all slivers be started
 
 @database.synchronized
-def GetSlivers(data, fullupdate=True):
+def GetSlivers(data, plc = None, config = None, fullupdate=True):
     """This function has two purposes.  One, convert GetSlivers() data
     into a more convenient format.  Two, even if no updates are coming
     in, use the GetSlivers() heartbeat as a cue to scan for expired