diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2007-01-24 02:19:43 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2007-01-24 02:19:43 +0000 |
commit | b238887ad8172c6a613b7d68bb551dac1aac57bb (patch) | |
tree | 1a0ce284f2c9b2b95447f4ea768b02e68f04797b /src/lib/Client/Tools | |
parent | 9182bcf5871ee041e789bb48d057323b6bc6b4b1 (diff) | |
download | bcfg2-b238887ad8172c6a613b7d68bb551dac1aac57bb.tar.gz bcfg2-b238887ad8172c6a613b7d68bb551dac1aac57bb.tar.bz2 bcfg2-b238887ad8172c6a613b7d68bb551dac1aac57bb.zip |
Implement Action support
- Schema addition for bundles/rules
- Tool driver for actions
- Frame support for pre-actions and post-actions
- Frame blacklist support (to preclude blocked entries from getting installed on the post-clobber pass)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2713 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client/Tools')
-rw-r--r-- | src/lib/Client/Tools/Action.py | 52 | ||||
-rw-r--r-- | src/lib/Client/Tools/__init__.py | 4 |
2 files changed, 54 insertions, 2 deletions
diff --git a/src/lib/Client/Tools/Action.py b/src/lib/Client/Tools/Action.py new file mode 100644 index 000000000..ddd15a264 --- /dev/null +++ b/src/lib/Client/Tools/Action.py @@ -0,0 +1,52 @@ +'''Action driver''' +__revision__ = '$Revision$' + +import Bcfg2.Client.Tools + +# <Action timing='pre|post|both' name='name' command='cmd text' when='always|modified' +# status='ignore|check'/> +# <PostInstall name='foo'/> +# => <Action timing='post' when='modified' name='n' command='foo' status='ignore'/> + +class Action(Bcfg2.Client.Tools.Tool): + '''Implement Actions''' + __name__ = 'Action' + __handles__ = [('PostInstall', None), ('Action', None)] + __req__ = {'PostInstall': ['name'], + 'Action':['name', 'timing', 'when', 'command', 'status']} + + def RunAction(self, entry): + '''This method handles command execution and status return''' + self.logger.debug("Running Action %s" % (entry.get('name'))) + rc = self.cmd.run(entry.get('command'))[0] + self.logger.debug("Action: %s got rc %s" % (entry.get('command'), rc)) + if entry.get('status', 'check') == 'ignore': + return True + else: + return rc == 0 + + def VerifyAction(self, dummy, _): + '''Actions always verify true''' + return True + + def InstallAction(self, entry): + '''Run actions as pre-checks for bundle installation''' + if entry.get('timing') != 'post': + self.states[entry] = self.RunAction(entry) + return self.states[entry] + return True + + def BundleUpdated(self, bundle): + '''Run postinstalls when bundles have been updated''' + for postinst in bundle.findall("PostInstall"): + self.cmd.run(postinst.get('name')) + for action in bundle.findall("Action"): + if action.get('timing') in ['post', 'both']: + self.states[action] = self.RunAction(action) + + def BundleNotUpdated(self, bundle): + '''Run Actions when bundles have not been updated''' + for action in bundle.findall("Action"): + if action.get('timing') in ['post', 'both'] and \ + action.get('when') != 'modified': + self.states[action] = self.RunAction(action) diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py index 142084792..90d3cedbc 100644 --- a/src/lib/Client/Tools/__init__.py +++ b/src/lib/Client/Tools/__init__.py @@ -1,8 +1,8 @@ '''This contains all Bcfg2 Tool modules''' __revision__ = '$Revision$' -__all__ = ["APT", "Blast", "Chkconfig", "DebInit", "Encap", "Portage", "Yum", - "PostInstall", "POSIX", "RPM", "RcUpdate", "SMF", "SYSV", "launchd"] +__all__ = ["Action", "APT", "Blast", "Chkconfig", "DebInit", "Encap", "launchd", + "Portage", "POSIX", "RPM", "RcUpdate", "SMF", "SYSV", "Yum"] import os, popen2, stat, sys, Bcfg2.Client.XML |