expects the 'interfaces' key in GetSlivers - review logs to always mention module
[nodemanager.git] / plugins / codemux.py
index b367b58..471f269 100644 (file)
@@ -12,9 +12,9 @@ from config import Config
 CODEMUXCONF="/etc/codemux/codemux.conf"
 
 def start(options, conf):
-    logger.log("codemux plugin starting up...")
+    logger.log("codemux: plugin starting up...")
 
-def GetSlivers(plc, data, config):
+def GetSlivers(data, config, plc = None):
     """
     For each sliver with the codemux attribute, parse out "host,port" 
     and make entry in conf.  Restart service after.
@@ -36,12 +36,18 @@ def GetSlivers(plc, data, config):
     else: _writeconf = True
 
     # Parse attributes and update dict of scripts
+    if 'slivers' not in data:
+        logger.log_missing_data("codemux.GetSlivers", 'slivers')
+        return
     for sliver in data['slivers']:
         for attribute in sliver['attributes']:
             if attribute['tagname'] == 'codemux':
                 # add to conf.  Attribute is [host, port]
-                params = {'host': attribute['value'].split(",")[0], 
-                          'port': attribute['value'].split(",")[1]}
+                parts = attribute['value'].split(",")
+                if len(parts)<2:
+                    logger.log("codemux: attribute value (%s) for codemux not separated by comma. Skipping."%attribute['value'])
+                    continue
+                params = {'host': parts[0], 'port': parts[1]}
                 try:
                     # Check to see if sliver is running.  If not, continue
                     if vserver.VServer(sliver['name']).is_running():
@@ -90,7 +96,7 @@ def writeConf(slivers, conf = CODEMUXCONF):
     f.truncate()
     f.close()
     try:  restartService()
-    except:  logger.log_exc()
+    except:  logger.log_exc("codemux.writeConf failed to restart service")
 
 
 def sortDomains(slivers):
@@ -126,7 +132,7 @@ def parseConf(conf = CODEMUXCONF):
             slicesinconf.setdefault(slice, [])
             slicesinconf[slice].append({"host": host, "port": port})
         f.close()
-    except IOError: logger.log_exc()
+    except IOError: logger.log_exc("codemux.parseConf got IOError")
     return slicesinconf