handle all installed versions
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 11 Mar 2010 17:43:05 +0000 (17:43 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 11 Mar 2010 17:43:05 +0000 (17:43 +0000)
plugins/omf_resctl.py

index 1401bc8..406be09 100644 (file)
@@ -8,15 +8,14 @@
 Overwrites the 'resctl' tag of slivers controlled by OMF so sm.py does the right thing
 """
 
 Overwrites the 'resctl' tag of slivers controlled by OMF so sm.py does the right thing
 """
 
+import os
+import glob
 import subprocess
 
 import tools
 import logger
 
 import subprocess
 
 import tools
 import logger
 
-priority = 11
-
-### xxx this should not be version-dependent
-service_name='omf-resctl-5.3'
+priority = 50
 
 def start(options, conf):
     logger.log("omf_resctl: plugin starting up...")
 
 def start(options, conf):
     logger.log("omf_resctl: plugin starting up...")
@@ -37,21 +36,31 @@ def GetSlivers(data, conf = None, plc = None):
         name=sliver['name']
         for chunk in sliver['attributes']:
             if chunk['tagname']=='omf_control':
         name=sliver['name']
         for chunk in sliver['attributes']:
             if chunk['tagname']=='omf_control':
-                # filenames
-                yaml="/vservers/%s/etc/omf-resctl/omf-resctl.yaml"%name
-                template="%s.in"%yaml
-                # read template and replace
-                template=file(template).read()
-                yaml_contents=template\
-                    .replace('@XMPP_SERVER@',xmpp_server)\
-                    .replace('@NODE_HRN@','default')\
-                    .replace('@SLICE_NAME@',name)
-                changes=tools.replace_file_with_string(yaml,yaml_contents)
-                if changes:
-                    sp=subprocess.Popen(['vserver',name,'exec','service',service_name,'restart'],
-                                        stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
-                    (output,retcod)=sp.communicate()
-                    logger.log("omf_resctl: %s: restarted resource controller (retcod=%r)"%(name,retcod))
-                    logger.log("omf_resctl: got output\n%s"%output)
-                else:
-                    logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % name)
+                # scan all versions of omf-resctl
+                etc_path="/vservers/%s/etc/"%name
+                pattern = etc_path + "omf-resctl-*/omf-resctl.yaml.in"
+                templates = glob.glob (pattern)
+                if not templates:
+                    logger.log("WARNING: omf_resctl plugin, no template found for slice %s using pattern %s"\
+                                   %(name,pattern))
+                    continue
+                for template in templates:
+                    # remove the .in extension
+                    yaml=template[:-3]
+                    # figure service name as subdir under etc/
+                    service_name=os.path.split(template.replace(etc_path,''))[0]
+                    # read template and replace
+                    template_contents=file(template).read()
+                    yaml_contents=template_contents\
+                        .replace('@XMPP_SERVER@',xmpp_server)\
+                        .replace('@NODE_HRN@','default # xxx todo in omf-resctl nm plugin')\
+                        .replace('@SLICE_NAME@',name)
+                    changes=tools.replace_file_with_string(yaml,yaml_contents)
+                    if changes:
+                        sp=subprocess.Popen(['vserver',name,'exec','service',service_name,'restart'],
+                                            stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
+                        (output,retcod)=sp.communicate()
+                        logger.log("omf_resctl: %s: restarted resource controller (retcod=%r)"%(name,retcod))
+                        logger.log("omf_resctl: got output\n%s"%output)
+                    else:
+                        logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % name)