From: Frank Brehm Date: Fri, 24 Jun 2022 11:20:51 +0000 (+0200) Subject: First generating of kickstart file X-Git-Tag: 2.6.2~1^2~8^2~44 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=88cf40a252606542a4496ffcca4cbc37e2fc74c4;p=pixelpark%2Fcreate-vmware-tpl.git First generating of kickstart file --- diff --git a/etc/cobbler-distros.yaml.default b/etc/cobbler-distros.yaml.default index 52be71a..60bc984 100644 --- a/etc/cobbler-distros.yaml.default +++ b/etc/cobbler-distros.yaml.default @@ -4,6 +4,7 @@ cobbler-distros: distro: 'AlmaLinux-8.6-x86_64' description: 'AlmaLinux 8 x86_64' shortname: 'alma8' + ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/almalinux/8/BaseOS/x86_64/os' repos: - 'almalinux-8-x86_64-baseos' - 'almalinux-8-x86_64-appstream' @@ -20,6 +21,7 @@ cobbler-distros: distro: 'CentOS-7.9-x86_64' description: 'CentOS 7 x86_64' shortname: 'centos7' + ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/centos/8/os/x86_64' repos: - 'centos-7-x86_64-baseos' - 'centos-7-x86_64-extras' @@ -34,6 +36,7 @@ cobbler-distros: distro: 'CentOS-Stream-8-x86_64' description: 'CentOS Stream 8 x86_64' shortname: 'centos8' + ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/centos/8-stream/BaseOS/x86_64/os' repos: - 'centos-stream-8-x86_64-baseos' - 'centos-stream-8-x86_64-appstream' @@ -50,6 +53,7 @@ cobbler-distros: distro: 'Oracle-Linux-7.9-x86_64' description: 'Oracle Enterprise Linux 7 x86_64' shortname: 'oel7' + ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/OracleLinux/OL7/ol7_latest' repos: - 'oraclelinux-7-x86_64-addons' - 'oraclelinux-7-x86_64-latest' @@ -66,6 +70,7 @@ cobbler-distros: distro: 'Rocky-8.6-x86_64' description: 'Rocky Linux 8 x86_64' shortname: 'rocky8' + ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/rockylinux/8/BaseOS/x86_64/os' repos: - 'rocky-8-x86_64-baseos' - 'rocky-8-x86_64-appstream' diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 7f9294e..5244644 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -28,6 +28,8 @@ from paramiko.ssh_exception import SSHException from packaging.version import Version +import jinja2 + # Own modules from fb_tools.common import pp, to_str, is_sequence @@ -679,6 +681,16 @@ class Cobbler(BaseHandler): remote_ks = self.cfg.system_ks LOG.info(_("Ensuring currentness of system kickstart script {!r}.").format( str(remote_ks))) + + jinja_env = jinja2.Environment( + loader=jinja2.FileSystemLoader(str(self.base_dir / 'templates')), + autoescape=jinja2.select_autoescape(), + ) + ks_template = jinja_env.get_template('el-standard.ks') + ks_content = ks_template.render(distro=self.cfg.current_distro) + if self.verbose > 1: + LOG.debug(_("Generated kickstart file content:") + '\n' + ks_content) + return print_section_start( 'ensure_system_ks', 'Ensuring currentness of system kickstart script', collapsed=True) diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 8a308f6..68b54e3 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -58,13 +58,14 @@ class CobblerDistroInfo(FbGenericBaseObject): # ------------------------------------------------------------------------- def __init__( self, name, shortname=None, distro=None, description=None, arch=DEFAULT_DISTRO_ARCH, - repos=None, snippets=None): + ks_repo_url=None, repos=None, snippets=None): self._name = None self._shortname = None self._distro = None self._description = None self._arch = DEFAULT_DISTRO_ARCH + self._ks_repo_url = None self.repos = CIStringSet() self.snippets = CIStringSet() @@ -184,6 +185,25 @@ class CobblerDistroInfo(FbGenericBaseObject): self._description = desc + # ------------------------------------------------------------------------- + @property + def ks_repo_url(self): + """The URL for the base installation repository.""" + return getattr(self, '_ks_repo_url', None) + + @ks_repo_url.setter + def ks_repo_url(self, value): + if value is None: + self._ks_repo_url = None + return + + ks_repo_url = value.strip() + if ks_repo_url == '': + self._ks_repo_url = None + return + + self._ks_repo_url = ks_repo_url + # ------------------------------------------------------------------------- def __repr__(self): """Typecasting into a string for reproduction.""" @@ -196,6 +216,7 @@ class CobblerDistroInfo(FbGenericBaseObject): fields.append("distro={!r}".format(self.distro)) fields.append("arch={!r}".format(self.arch)) fields.append("description={!r}".format(self.description)) + fields.append("ks_repo_url={!r}".format(self.ks_repo_url)) out += ", ".join(fields) + ")>" @@ -220,6 +241,7 @@ class CobblerDistroInfo(FbGenericBaseObject): res['distro'] = self.distro res['arch'] = self.arch res['description'] = self.description + res['ks_repo_url'] = self.ks_repo_url return res @@ -236,7 +258,7 @@ class CobblerDistroInfo(FbGenericBaseObject): new = self.__class__( self.name, shortname=self.shortname, distro=self.distro, arch=arch, - description=self.description) + ks_repo_url=self.ks_repo_url, description=self.description) for repo in self.repos: new.repos.add(repo) @@ -256,19 +278,23 @@ class CobblerDistroInfo(FbGenericBaseObject): value = data[key] if key.lower() == 'shortname' and value.strip() != '': - new.shortname = value + new.shortname = value.strip() continue if key.lower() == 'distro' and value.strip() != '': - new.distro = value + new.distro = value.strip() continue if key.lower() == 'description' and value.strip() != '': - new.description = value + new.description = value.strip() continue if key.lower() == 'arch' and value.strip() != '': - new.arch = value + new.arch = value.strip() + continue + + if key.lower() == 'ks_repo_url' and value.strip() != '': + new.ks_repo_url = value.strip() continue if key.lower() == 'repos': @@ -651,6 +677,12 @@ class CrTplConfiguration(BaseMultiConfig): distro_id) raise CrTplConfigError(msg) + if not distro.ks_repo_url: + msg = _( + "Did not found the base install repo URL of configured Cobbler " + "distro {!r}.").format( distro_id) + raise CrTplConfigError(msg) + if not len(distro.repos): msg = _( "Did not found repo definitions for configured Cobbler " diff --git a/requirements.txt b/requirements.txt index d6c11a3..dda7db9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ Babel PyYAML toml hjson +jinja2 fb_logging fb_tools fb_vmware