X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fcodemux.py;h=6ac314d8696e08764b1d35463dfb19a887a01f68;hb=8cc494379bcba9a09f249cccf88d51f1ed9ea43c;hp=8aae38c24a776c691f06817a79118e7abafd38fe;hpb=4cfe5c0495fdebde635a66262dd14f8055cab443;p=nodemanager.git diff --git a/plugins/codemux.py b/plugins/codemux.py index 8aae38c..6ac314d 100644 --- a/plugins/codemux.py +++ b/plugins/codemux.py @@ -6,17 +6,16 @@ import logger import os import vserver -from sets import Set from config import Config CODEMUXCONF="/etc/codemux/codemux.conf" -def start(options, conf): +def start(): logger.log("codemux: plugin starting up...") def GetSlivers(data, config, plc = None): """ - For each sliver with the codemux attribute, parse out "host,port" + For each sliver with the codemux attribute, parse out "host,port" and make entry in conf. Restart service after. """ if 'OVERRIDES' in dir(config): @@ -30,7 +29,7 @@ def GetSlivers(data, config, plc = None): slicesinconf = parseConf() # slices that need to be written to the conf codemuxslices = {} - + # XXX Hack for planetflow if slicesinconf.has_key("root"): _writeconf = False else: _writeconf = True @@ -50,7 +49,7 @@ def GetSlivers(data, config, plc = None): if len(parts) == 3: ip = parts[2] else: - ip = None + ip = "" params = {'host': parts[0], 'port': parts[1], 'ip': ip} try: @@ -59,7 +58,7 @@ def GetSlivers(data, config, plc = None): # Check if new or needs updating if (sliver['name'] not in slicesinconf.keys()) \ or (params not in slicesinconf.get(sliver['name'], [])): - logger.log("codemux: Updaiting slice %s using %s" % \ + logger.log("codemux: Updating slice %s using %s" % \ (sliver['name'], params['host'])) # Toggle write. _writeconf = True @@ -73,13 +72,13 @@ def GetSlivers(data, config, plc = None): pass # Remove slices from conf that no longer have the attribute - for deadslice in Set(slicesinconf.keys()) - Set(codemuxslices.keys()): + for deadslice in set(slicesinconf.keys()) - set(codemuxslices.keys()): # XXX Hack for root slice - if deadslice != "root": + if deadslice != "root": logger.log("codemux: Removing %s" % deadslice) - _writeconf = True + _writeconf = True - if _writeconf: writeConf(sortDomains(codemuxslices)) + if _writeconf: writeConf(sortDomains(codemuxslices)) # ensure the service is running startService() @@ -88,9 +87,9 @@ def writeConf(slivers, conf = CODEMUXCONF): '''Write conf with default entry up top. Elements in [] should have lower order domain names first. Restart service.''' f = open(conf, "w") # This needs to be the first entry... - try: + try: f.write("* root 1080 %s\n" % Config().PLC_PLANETFLOW_HOST) - except AttributeError: + except AttributeError: logger.log("codemux: Can't find PLC_CONFIG_HOST in config. Using PLC_API_HOST") f.write("* root 1080 %s\n" % Config().PLC_API_HOST) # Sort items for like domains @@ -118,14 +117,14 @@ def sortDomains(slivers): # make list of slivers sortedslices = [] 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)}''' slicesinconf = {} # default - try: + try: f = open(conf) for line in f.readlines(): if line.startswith("#") \