From 7446d0d1e206145de1c9d61fd4c65e00c3564d16 Mon Sep 17 00:00:00 2001 From: Martin Gracik Date: Fri, 1 Jun 2012 14:42:55 +0200 Subject: [PATCH] Add a --required switch to installpkg Some packages are critical to the compose. If --required is specified in the template's installpkg command, lorax will exit if the package is not available. --- src/pylorax/ltmpl.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 2caf22ba..2560f27b 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -382,17 +382,24 @@ class LoraxTemplateRunner(object): def installpkg(self, *pkgs): ''' - installpkg PKGGLOB [PKGGLOB ...] + installpkg [--required] PKGGLOB [PKGGLOB ...] Request installation of all packages matching the given globs. Note that this is just a *request* - nothing is *actually* installed until the 'run_pkg_transaction' command is given. ''' + required = False + if pkgs[0] == '--required': + pkgs = pkgs[1:] + required = True + for p in pkgs: try: self.yum.install(pattern=p) except Exception as e: # FIXME: save exception and re-raise after the loop finishes - logger.warn("installpkg %s failed: %s",p,str(e)) + logger.error("installpkg %s failed: %s",p,str(e)) + if required: + sys.exit(1) def removepkg(self, *pkgs): '''