Added ISO kickstart templating
This commit is contained in:
parent
30ade4e685
commit
16db34cdbc
1
Makefile
1
Makefile
@ -13,6 +13,7 @@ help:
|
||||
@echo ' MIRROR_SRC: $(MIRROR_SRC)'
|
||||
@echo ' ISO_DIR/ISO_NAME: $(ISO_PATH)'
|
||||
@echo ' ENV_NAME: $(ENV_NAME)'
|
||||
@echo ' KSYAML: $(KSYAML)'
|
||||
@echo
|
||||
@echo 'Available targets:'
|
||||
@echo ' all - build product'
|
||||
|
@ -92,3 +92,7 @@ MIRROR_SRC?=internet
|
||||
|
||||
# INTEGRATION TEST CONFIG
|
||||
NOFORWARD:=1
|
||||
|
||||
# Path to yaml configuration file to build ISO ks.cfg
|
||||
KSYAML?=$(SOURCE_DIR)/iso/ks.yaml
|
||||
|
||||
|
59
iso/ks.py
Normal file
59
iso/ks.py
Normal file
@ -0,0 +1,59 @@
|
||||
import os
|
||||
import argparse
|
||||
import yaml
|
||||
|
||||
from jinja2 import FileSystemLoader
|
||||
from jinja2 import Environment
|
||||
|
||||
|
||||
class KickstartFile(object):
|
||||
def __init__(self, config_filename, template_filename):
|
||||
with open(config_filename, "r") as f:
|
||||
self.config = yaml.load(f.read())
|
||||
|
||||
self.env = Environment(
|
||||
loader=FileSystemLoader(
|
||||
os.path.dirname(os.path.abspath(template_filename))
|
||||
)
|
||||
)
|
||||
self.template = self.env.get_template(
|
||||
os.path.basename(os.path.abspath(template_filename))
|
||||
)
|
||||
|
||||
def render(self):
|
||||
return self.template.render(self.config)
|
||||
|
||||
def render2file(self, filename):
|
||||
with open(filename, "w") as f:
|
||||
f.write(self.render())
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
description = """
|
||||
This script builds kickstart file to using jinja2 template system.
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(epilog=description)
|
||||
parser.add_argument(
|
||||
'-t', '--template', dest='template', action='store', type=str,
|
||||
help='kickstart template file', required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-c', '--config', dest='config', action='store', type=str,
|
||||
help='yaml config file', required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-o', '--output', dest='output', action='store', type=str,
|
||||
help='where to output templating result', default='-'
|
||||
)
|
||||
params, other_params = parser.parse_known_args()
|
||||
|
||||
ks = KickstartFile(
|
||||
config_filename=params.config,
|
||||
template_filename=params.template
|
||||
)
|
||||
|
||||
if params.output == '-':
|
||||
print ks.render()
|
||||
else:
|
||||
ks.render2file(params.output)
|
@ -1,7 +1,7 @@
|
||||
install
|
||||
text
|
||||
%include /tmp/source.ks
|
||||
reboot --eject
|
||||
{{reboot}}
|
||||
lang en_US.UTF-8
|
||||
keyboard us
|
||||
rootpw r00tme
|
1
iso/ks.yaml
Normal file
1
iso/ks.yaml
Normal file
@ -0,0 +1 @@
|
||||
reboot: reboot --eject
|
@ -56,7 +56,9 @@ $(BUILD_DIR)/iso/isoroot-files.done: \
|
||||
$(ISOROOT)/.discinfo: $(SOURCE_DIR)/iso/.discinfo ; $(ACTION.COPY)
|
||||
$(ISOROOT)/.treeinfo: $(SOURCE_DIR)/iso/.treeinfo ; $(ACTION.COPY)
|
||||
$(ISOROOT)/isolinux/isolinux.cfg: $(SOURCE_DIR)/iso/isolinux/isolinux.cfg ; $(ACTION.COPY)
|
||||
$(ISOROOT)/ks.cfg: $(SOURCE_DIR)/iso/ks.cfg ; $(ACTION.COPY)
|
||||
$(ISOROOT)/ks.cfg: $(call depv,KSYAML)
|
||||
$(ISOROOT)/ks.cfg: $(SOURCE_DIR)/iso/ks.template $(SOURCE_DIR)/iso/ks.py $(KSYAML)
|
||||
python $(SOURCE_DIR)/iso/ks.py -t $(SOURCE_DIR)/iso/ks.template -c $(KSYAML) -o $@
|
||||
$(ISOROOT)/bootstrap_admin_node.sh: $(SOURCE_DIR)/iso/bootstrap_admin_node.sh ; $(ACTION.COPY)
|
||||
$(ISOROOT)/bootstrap_admin_node.conf: $(SOURCE_DIR)/iso/bootstrap_admin_node.conf ; $(ACTION.COPY)
|
||||
$(ISOROOT)/version.yaml: $(call depv,COMMIT_SHA)
|
||||
|
Loading…
Reference in New Issue
Block a user