Skip to contentSkip to conversation

Trigger a script when a resource's label changes

PATCH New Stefan Berger 1 participant 1 message Oct 26, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Trigger a script when a resource's label changes

This patch triggers a script when a resource's label changes. The xend config file should provide a variable 'resource-label-change-script' that can then be launched.

Signed-off-by; Stefan Berger <[email protected]>

---
 xen-unstable.hg/tools/examples/xend-config.sxp       |    3 +-
 xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py |   22 +++++++++++++++++++
 xen-unstable.hg/tools/python/xen/xend/XendOptions.py |   10 ++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py +22 -0
Index: root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py
===================================================================
@@ -27,6 +27,7 @@ import stat
 from xen.lowlevel import acm
 from xen.xend import sxp
 from xen.xend import XendConstants
+from xen.xend import XendOptions
 from xen.xend.XendLogging import log
 from xen.xend.XendError import VmError
 from xen.util import dictio, xsconstants
@@ -1081,9 +1082,14 @@ def set_resource_label(resource, policyt
         if reslabel != "":
             new_entry = { resource : tuple([policytype, policyref, reslabel])}
             access_control.update(new_entry)
+            command = "add"
+            reslbl = ":".join([policytype, policyref, reslabel])
         else:
             if access_control.has_key(resource):
                 del access_control[resource]
+            command = "remove"
+            reslbl = ""
+        run_resource_label_change_script(resource, reslbl, command)
         dictio.dict_write(access_control, "resources", res_label_filename)
     finally:
         resfile_unlock()
@@ -1273,6 +1279,7 @@ def change_acm_policy(bin_pol, del_array
                 label = reslabel_map[label]
             elif label not in polnew_reslabels:
                 policytype = xsconstants.INVALID_POLICY_PREFIX + policytype
+                run_resource_label_change_script(key, "", "remove")
             # Update entry
             access_control[key] = \
                    tuple([ policytype, new_policyname, label ])
@@ -1383,3 +1390,18 @@ def get_security_label(self, xspol=None)
     if domid != 0:
         label = self.info.get('security_label', label)
     return label
+
+def run_resource_label_change_script(resource, label, command):
+    script = XendOptions.instance().get_resource_label_change_script()
+    if script:
+        parms = {
+            'resource' : resource,
+            'label'    : label,
+            'command'  : command,
+        }
+        log.info("Running resource label change script %s: %s" %
+                 (script, parms))
+        parms.update(os.environ)
+        os.spawnve(os.P_NOWAIT, script[0], script, parms)
+    else:
+        log.info("No script given for relabeling of resources.")
xen-unstable.hg/tools/python/xen/xend/XendOptions.py +10 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/XendOptions.py
===================================================================
@@ -278,6 +278,16 @@ class XendOptions:
     def get_keymap(self):
         return self.get_config_value('keymap', None)
 
+    def get_resource_label_change_script(self):
+        s = self.get_config_value('resource-label-change-script')
+        if s:
+            result = s.split(" ")
+            result[0] = os.path.join(osdep.scripts_dir, result[0])
+            return result
+        else:
+            return None
+
+
 class XendOptionsFile(XendOptions):
 
     """Default path to the config file."""
xen-unstable.hg/tools/examples/xend-config.sxp +2 -1
Index: root/xen-unstable.hg/tools/examples/xend-config.sxp
===================================================================
@@ -196,4 +196,5 @@
 # when not specififed in VM's configuration
 #(keymap 'en-us')
 
-
+# Script to run when the label of a resource has changed.
+#(resource-label-change-script '')

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel