diff --git a/share/aarch64.tmpl b/share/aarch64.tmpl index 09d5a062..24cb0cad 100644 --- a/share/aarch64.tmpl +++ b/share/aarch64.tmpl @@ -46,6 +46,13 @@ mkdir ${KERNELDIR} %endif %endfor + # Inherit iso-graft/ if it exists from external templates + <% + import os + if os.path.exists(workdir + "/iso-graft"): + imggraft += " " + workdir + "/iso-graft" + %> + ## make boot.iso runcmd mkisofs -o ${outroot}/images/boot.iso \ ${efiargs} -R -J -V '${isolabel}' -T -graft-points \ diff --git a/share/arm.tmpl b/share/arm.tmpl index 637e13fd..488a8eda 100644 --- a/share/arm.tmpl +++ b/share/arm.tmpl @@ -112,5 +112,12 @@ mkdir ${KERNELDIR} treeinfo ${basearch} platforms ${platforms} +# Inherit iso-graft/ if it exists from external templates +<% + import os + if os.path.exists(workdir + "/iso-graft"): + imggraft += " " + workdir + "/iso-graft" +%> + ## FIXME: ARM may need some extra boot config diff --git a/share/ppc.tmpl b/share/ppc.tmpl index 4d13001c..13c8e5e1 100644 --- a/share/ppc.tmpl +++ b/share/ppc.tmpl @@ -98,6 +98,13 @@ install ${configdir}/magic ${BOOTDIR} %endif %endfor +# Inherit iso-graft/ if it exists from external templates +<% + import os + if os.path.exists(workdir + "/iso-graft"): + imggraft += " " + workdir + "/iso-graft" +%> + ## make boot.iso runcmd mkisofs -o ${outroot}/images/boot.iso -chrp-boot -U \ ${prepboot} -part -hfs -T -r -l -J \ diff --git a/share/x86.tmpl b/share/x86.tmpl index 9d03400c..5a835d3c 100644 --- a/share/x86.tmpl +++ b/share/x86.tmpl @@ -88,6 +88,13 @@ hardlink ${KERNELDIR}/initrd.img ${BOOTDIR} %endif %endfor +# Inherit iso-graft/ if it exists from external templates +<% + import os + if os.path.exists(workdir + "/iso-graft"): + imggraft += " " + workdir + "/iso-graft" +%> + ## make boot.iso runcmd mkisofs -o ${outroot}/images/boot.iso \ -b ${BOOTDIR}/isolinux.bin -c ${BOOTDIR}/boot.cat \ diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index c38ea2bc..e7dd0d58 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -145,7 +145,10 @@ class Lorax(BaseLoraxClass): domacboot=False, doupgrade=True, remove_temp=False, size=2, add_templates=None, - add_template_vars=None): + add_template_vars=None, + add_arch_templates=None, + add_arch_template_vars=None, + template_tempdir=None): assert self._configured @@ -298,7 +301,10 @@ class Lorax(BaseLoraxClass): inroot=installroot, outroot=self.outputdir, runtime=runtime, isolabel=isolabel, domacboot=domacboot, doupgrade=doupgrade, - templatedir=templatedir) + templatedir=templatedir, + add_templates=add_arch_templates, + add_template_vars=add_arch_template_vars, + workdir=self.workdir) logger.info("rebuilding initramfs images") dracut_args = ["--xz", "--install", "/.buildstamp"] diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 4a75bf53..19275e50 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -173,7 +173,7 @@ class LoraxTemplateRunner(object): def run(self, templatefile, **variables): for k,v in self.defaults.items() + self.builtins.items(): variables.setdefault(k,v) - logger.debug("parsing %s", templatefile) + logger.debug("executing {0} with variables={1}".format(templatefile, variables)) self.templatefile = templatefile t = LoraxTemplate(directories=[self.templatedir]) commands = t.parse(templatefile, variables) diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py index 51e42e95..85a7fe91 100644 --- a/src/pylorax/treebuilder.py +++ b/src/pylorax/treebuilder.py @@ -167,16 +167,20 @@ class RuntimeBuilder(object): class TreeBuilder(object): '''Builds the arch-specific boot images. inroot should be the installtree root (the newly-built runtime dir)''' - def __init__(self, product, arch, inroot, outroot, runtime, isolabel, domacboot=False, doupgrade=True, templatedir=None): + def __init__(self, product, arch, inroot, outroot, runtime, isolabel, domacboot=False, doupgrade=True, templatedir=None, add_templates=None, add_template_vars=None, workdir=None): + # NOTE: if you pass an arg named "runtime" to a mako template it'll # clobber some mako internal variables - hence "runtime_img". self.vars = DataHolder(arch=arch, product=product, runtime_img=runtime, runtime_base=basename(runtime), inroot=inroot, outroot=outroot, basearch=arch.basearch, libdir=arch.libdir, - isolabel=isolabel, udev=udev_escape, domacboot=domacboot, doupgrade=doupgrade) + isolabel=isolabel, udev=udev_escape, domacboot=domacboot, doupgrade=doupgrade, + workdir=workdir) self._runner = LoraxTemplateRunner(inroot, outroot, templatedir=templatedir) self._runner.defaults = self.vars + self.add_templates = add_templates or [] + self.add_template_vars = add_template_vars or {} self.templatedir = templatedir @property @@ -223,6 +227,8 @@ class TreeBuilder(object): def build(self): templatefile = templatemap[self.vars.arch.basearch] + for tmpl in self.add_templates: + self._runner.run(tmpl, **self.add_template_vars) self._runner.run(templatefile, kernels=self.kernels) self.treeinfo_data = self._runner.results.treeinfo self.implantisomd5() diff --git a/src/sbin/lorax b/src/sbin/lorax index 496e4920..1e087079 100755 --- a/src/sbin/lorax +++ b/src/sbin/lorax @@ -134,10 +134,16 @@ def main(args): 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", + action="append", help="Additional template for runtime image", default=[]) optional.add_option("--add-template-var", dest="add_template_vars", - action="append", help="Set variable for additional templates", + action="append", help="Set variable for runtime image template", + default=[]) + optional.add_option("--add-arch-template", dest="add_arch_templates", + action="append", help="Additional template for architecture-specific image", + default=[]) + optional.add_option("--add-arch-template-var", dest="add_arch_template_vars", + action="append", help="Set variable for architecture-specific image", default=[]) # add the option groups to the parser @@ -198,6 +204,13 @@ def main(args): raise ValueError("Missing '=' for key=value in " % kv) parsed_add_template_vars[k] = v + parsed_add_arch_template_vars = {} + for kv in opts.add_arch_template_vars: + k, t, v = kv.partition('=') + if t == '': + raise ValueError("Missing '=' for key=value in " % kv) + parsed_add_arch_template_vars[k] = v + # run lorax lorax = pylorax.Lorax() lorax.configure(conf_file=opts.config) @@ -207,6 +220,8 @@ def main(args): volid=opts.volid, domacboot=opts.domacboot, doupgrade=opts.doupgrade, add_templates=opts.add_templates, add_template_vars=parsed_add_template_vars, + add_arch_templates=opts.add_arch_templates, + add_arch_template_vars=parsed_add_arch_template_vars, remove_temp=True)