fix codemux restarting every 15 minutes
[nodemanager.git] / plugins / codemux.py
index c3a6a8f..af7fb58 100644 (file)
@@ -1,12 +1,10 @@
-# $Id$
-# $URL$
-
 """Codemux configurator.  Monitors slice attributes and configures CoDemux to mux port 80 based on HOST field in HTTP request.  Forwards to localhost port belonging to configured slice."""
 
 import logger
 import os
-import libvirt
+
 from config import Config
+import slivermanager
 
 CODEMUXCONF="/etc/codemux/codemux.conf"
 
@@ -54,7 +52,7 @@ def GetSlivers(data, config, plc = None):
 
                 try:
                     # Check to see if sliver is running.  If not, continue
-                    if isLXCDomRunning(sliver['name']):
+                    if slivermanager.is_running(sliver['name']):
                         # Check if new or needs updating
                         if (sliver['name'] not in slicesinconf.keys()) \
                         or (params not in slicesinconf.get(sliver['name'], [])):
@@ -127,14 +125,19 @@ def parseConf(conf = CODEMUXCONF):
     try:
         f = open(conf)
         for line in f.readlines():
-            if line.startswith("#") \
-            or (len(line.split()) > 4) \
-            or (len(line.split()) < 3):
+            parts = line.split()
+            if line.startswith("#") or (len(parts) > 4) or (len(parts) < 3):
                 continue
-            (host, slice, port) = line.split()[:3]
-            logger.log("codemux:  found %s in conf" % slice, 2)
-            slicesinconf.setdefault(slice, [])
-            slicesinconf[slice].append({"host": host, "port": port})
+            if len(parts) == 4:
+                (host, slice, port, ip) = parts
+                logger.log("codemux:  found %s in conf" % slice, 2)
+                slicesinconf.setdefault(slice, [])
+                slicesinconf[slice].append({"host": host, "port": port, "ip": ip})
+            else:
+                (host, slice, port) = parts[:3]
+                logger.log("codemux:  found %s in conf" % slice, 2)
+                slicesinconf.setdefault(slice, [])
+                slicesinconf[slice].append({"host": host, "port": port})
         f.close()
     except IOError: logger.log_exc("codemux.parseConf got IOError")
     return slicesinconf
@@ -169,13 +172,3 @@ def stopService():
         logger.log_call(["/etc/init.d/codemux", "stop", ])
     logger.log_call(["/sbin/chkconfig", "codemux", "off"])
 
-def isLXCDomRunning(domName):
-    try:
-        running = False
-        conn = libvirt.open('lxc://')
-        dom  = conn.lookupByName(domName)
-        running = dom.info()[0] == libvirt.VIR_DOMAIN_RUNNING
-    finally:
-        conn.close()
-    return running
-