From 1ef49fca1e3ab560adea8f15224f9d6a799d492d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 1 May 2014 21:34:54 -0400 Subject: [PATCH] Add --add-template{,-var} What I need is to make something like the traditional DVD which also includes packages. At present this is apparently handled by the entirely separate pungi tool. At the moment for me, it's the least bad option to modify lorax to inject data from an external source than to create a new tool, or attempt to also modify pungi to do this. This would also allow pungi's DVD creation to eventually be a set of external templates for Lorax. (cherry picked from commit 66359415be7e63672966be00e91fd4cda1902dfb) Resolves: rhbz#1157777 --- src/pylorax/__init__.py | 9 +++++++-- src/pylorax/treebuilder.py | 11 +++++++++-- src/sbin/lorax | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index 2c4f7013..c38ea2bc 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -142,7 +142,10 @@ class Lorax(BaseLoraxClass): def run(self, ybo, product, version, release, variant="", bugurl="", isfinal=False, workdir=None, outputdir=None, buildarch=None, volid=None, - domacboot=False, doupgrade=True, remove_temp=False): + domacboot=False, doupgrade=True, remove_temp=False, + size=2, + add_templates=None, + add_template_vars=None): assert self._configured @@ -240,7 +243,9 @@ class Lorax(BaseLoraxClass): templatedir = self.conf.get("lorax", "sharedir") # NOTE: rb.root = ybo.conf.installroot (== self.inroot) rb = RuntimeBuilder(product=self.product, arch=self.arch, - yum=ybo, templatedir=templatedir) + yum=ybo, templatedir=templatedir, + add_templates=add_templates, + add_template_vars=add_template_vars) logger.info("installing runtime packages") rb.yum.conf.skip_broken = self.conf.getboolean("yum", "skipbroken") diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py index 7924803f..28b64542 100644 --- a/src/pylorax/treebuilder.py +++ b/src/pylorax/treebuilder.py @@ -67,7 +67,9 @@ def generate_module_info(moddir, outfile=None): class RuntimeBuilder(object): '''Builds the anaconda runtime image.''' - def __init__(self, product, arch, yum, templatedir=None): + def __init__(self, product, arch, yum, templatedir=None, + add_templates=None, + add_template_vars=None): root = yum.conf.installroot # use a copy of product so we can modify it locally product = product.copy() @@ -77,6 +79,8 @@ class RuntimeBuilder(object): self.yum = yum self._runner = LoraxTemplateRunner(inroot=root, outroot=root, yum=yum, templatedir=templatedir) + self.add_templates = add_templates or [] + self.add_template_vars = add_template_vars or {} self._runner.defaults = self.vars def _install_branding(self): @@ -104,6 +108,8 @@ class RuntimeBuilder(object): '''Install packages and do initial setup with runtime-install.tmpl''' self._install_branding() self._runner.run("runtime-install.tmpl") + for tmpl in self.add_templates: + self._runner.run(tmpl, **self.add_template_vars) def writepkglists(self, pkglistdir): '''debugging data: write out lists of package contents''' @@ -160,7 +166,8 @@ class RuntimeBuilder(object): # Reset selinux context on new rootfs with imgutils.LoopDev( joinpaths(workdir, "LiveOS/rootfs.img") ) as loopdev: with imgutils.Mount(loopdev) as mnt: - cmd = [ "setfiles", "-e", "/proc", "-e", "/sys", "-e", "/dev", "/etc/selinux/targeted/contexts/files/file_contexts", "/"] + cmd = [ "setfiles", "-e", "/proc", "-e", "/sys", "-e", "/dev", "-e", "/install", + "/etc/selinux/targeted/contexts/files/file_contexts", "/"] runcmd(cmd, root=mnt) # squash the live rootfs and clean up workdir diff --git a/src/sbin/lorax b/src/sbin/lorax index 8a76ef97..496e4920 100755 --- a/src/sbin/lorax +++ b/src/sbin/lorax @@ -133,6 +133,12 @@ def main(args): help="Path to logfile") optional.add_option("--tmp", default="/var/tmp", help="Top level temporary directory" ) + optional.add_option("--add-template", dest="add_templates", + action="append", help="Additional template to execute", + default=[]) + optional.add_option("--add-template-var", dest="add_template_vars", + action="append", help="Set variable for additional templates", + default=[]) # add the option groups to the parser parser.add_option_group(required) @@ -185,6 +191,13 @@ def main(args): shutil.rmtree(tempdir) sys.exit(1) + parsed_add_template_vars = {} + for kv in opts.add_template_vars: + k, t, v = kv.partition('=') + if t == '': + raise ValueError("Missing '=' for key=value in " % kv) + parsed_add_template_vars[k] = v + # run lorax lorax = pylorax.Lorax() lorax.configure(conf_file=opts.config) @@ -192,6 +205,8 @@ def main(args): opts.variant, opts.bugurl, opts.isfinal, workdir=tempdir, outputdir=outputdir, buildarch=opts.buildarch, volid=opts.volid, domacboot=opts.domacboot, doupgrade=opts.doupgrade, + add_templates=opts.add_templates, + add_template_vars=parsed_add_template_vars, remove_temp=True)