summaryrefslogtreecommitdiffstats
path: root/cobbler
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
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')
-rw-r--r--cobbler/action_sync.py28
-rw-r--r--cobbler/collection.py6
-rw-r--r--cobbler/utils.py28
-rw-r--r--cobbler/webui/master.py4
4 files changed, 33 insertions, 33 deletions
diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py
index b9909cb..49c01ea 100644
--- a/cobbler/action_sync.py
+++ b/cobbler/action_sync.py
@@ -59,6 +59,7 @@ class BootSync:
Syncs the current configuration file with the config tree.
Using the Check().run_ functions previously is recommended
"""
+ utils.run_triggers(None, "/var/lib/cobbler/triggers/sync/pre/*")
if not os.path.exists(self.settings.tftpboot):
raise CX(_("cannot find directory: %s") % self.settings.tftpboot)
self.clean_trees()
@@ -71,27 +72,10 @@ class BootSync:
self.write_dhcp_file()
self.regen_ethers()
self.regen_hosts()
- self.restart_dhcp()
self.make_pxe_menu()
+ utils.run_triggers(None, "/var/lib/cobbler/triggers/sync/post/*")
return True
- def restart_dhcp(self):
- """
- DHCP restarts need to be made when the config file is
- changed. ISC or DNSMASQ. Support for ISC omshell not
- yet available (adding dynamically w/o restart).
- """
- try:
- mode = self.settings.manage_dhcp_mode.lower()
- service = "dhcpd"
- if mode == "dnsmasq":
- service = "dnsmasq"
- retcode = self.service(service, "restart")
- if retcode != 0:
- print _("Warning: %s restart failed") % service
- except OSError, e:
- print _("Warning: %s restart failed: ") % service, e
-
def copy_bootloaders(self):
"""
Copy bootloaders to the configured tftpboot directory
@@ -907,11 +891,3 @@ class BootSync:
print oe.errno
raise CX(_("Error creating") % path)
- def service(self, name, action):
- """
- Call /sbin/service NAME ACTION
- """
-
- cmd = "/sbin/service %s %s" % (name, action)
- return sub_process.call(cmd, shell=True)
-
diff --git a/cobbler/collection.py b/cobbler/collection.py
index 4117bd9..8e6be39 100644
--- a/cobbler/collection.py
+++ b/cobbler/collection.py
@@ -155,11 +155,7 @@ class Collection(serializable.Serializable):
return True
def _run_triggers(self,ref,globber):
- triggers = glob.glob(globber)
- for file in triggers:
- rc = sub_process.call("%s %s" % (file,ref.name), shell=True)
- if rc != 0:
- raise CX(_("cobbler trigger failed: %(file)s returns %(code)d") % { "file" : file, "code" : rc })
+ return utils.run_triggers(ref,globber)
def printable(self):
"""
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 })
+
diff --git a/cobbler/webui/master.py b/cobbler/webui/master.py
index c861aeb..17d93b0 100644
--- a/cobbler/webui/master.py
+++ b/cobbler/webui/master.py
@@ -33,8 +33,8 @@ VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.0rc8'
__CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 8)
-__CHEETAH_genTime__ = 1192820351.713706
-__CHEETAH_genTimestamp__ = 'Fri Oct 19 14:59:11 2007'
+__CHEETAH_genTime__ = 1192826261.8448961
+__CHEETAH_genTimestamp__ = 'Fri Oct 19 16:37:41 2007'
__CHEETAH_src__ = 'webui_templates/master.tmpl'
__CHEETAH_srcLastModified__ = 'Fri Oct 12 11:53:14 2007'
__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'