summaryrefslogtreecommitdiffstats
path: root/cobbler/utils.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-10-19 16:44:06 -0400
committerMichael DeHaan <mdehaan@redhat.com>2007-10-19 16:44:06 -0400
commit1b1222ec7f95a773fcab39bf1ebe68da198919be (patch)
treeb180dc9a976886f143d0743cd725d3ec5bd3c707 /cobbler/utils.py
parentd09c20fc07efb87cffcbac467f189e312eb67e9e (diff)
downloadthird_party-cobbler-1b1222ec7f95a773fcab39bf1ebe68da198919be.tar.gz
third_party-cobbler-1b1222ec7f95a773fcab39bf1ebe68da198919be.tar.xz
third_party-cobbler-1b1222ec7f95a773fcab39bf1ebe68da198919be.zip
Service restarting has been abstracted out of the action_sync code, and is now a trigger.
This commit adds pre/post sync triggers, for scripting of arbitrary actions. The idea is that a cobbler user can now modify the restart-services script to rsync DHCP configurations to a remote box and instead restart them there, for hosting DHCP on a different box. Or do anything else that might be required. The restart-services trigger will ship in the cobbler RPM. Users can modify it at will and it is marked as config(noreplace) so upgrades will not affect it.
Diffstat (limited to 'cobbler/utils.py')
-rw-r--r--cobbler/utils.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/cobbler/utils.py b/cobbler/utils.py
index f8b2193..a2cee35 100644
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -393,3 +393,31 @@ def hash_to_string(hash):
buffer = buffer + str(key) + "=" + str(value) + " "
return buffer
+def run_triggers(ref,globber):
+ """
+ Runs all the trigger scripts in a given directory.
+ ref can be a cobbler object, if not None, the name will be passed
+ to the script. If ref is None, the script will be called with
+ no argumenets. Globber is a wildcard expression indicating which
+ triggers to run. Example: "/var/lib/cobbler/triggers/blah/*"
+ """
+
+ triggers = glob.glob(globber)
+ triggers.sort()
+ for file in triggers:
+ try:
+ if file.find(".rpm") != -1:
+ # skip .rpmnew files that may have been installed
+ # in the triggers directory
+ continue
+ if ref:
+ rc = sub_process.call([file,ref.name], shell=False)
+ else:
+ rc = sub_process.call([file], shell=False)
+ except:
+ print _("Warning: failed to execute trigger: %s" % file)
+ continue
+
+ if rc != 0:
+ raise CX(_("cobbler trigger failed: %(file)s returns %(code)d") % { "file" : file, "code" : rc })
+