From 3aea80f19f17aebdbd3f7b997704f0fa9a6b1cc8 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 11 Jun 2020 11:22:46 +0200 Subject: [PATCH] Implementing syncing of snippets --- lib/cr_vmware_tpl/cobbler.py | 10 +++++++++- lib/cr_vmware_tpl/config.py | 9 ++++++++- lib/cr_vmware_tpl/handler.py | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 34d077f..7d0d1d6 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -37,7 +37,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.4.5' +__version__ = '0.4.6' LOG = logging.getLogger(__name__) @@ -612,6 +612,11 @@ class Cobbler(BaseHandler): def ensure_snippets(self): local_snippets_dir = self.base_dir / 'snippets' + self.ensure_remote_directory(self.config.snippets_dir) + + for local_snippet in local_snippets_dir.glob('*'): + remote_snippet = self.config.snippets_dir / local_snippet.name + self.ensure_remote_file(local_snippet, remote_snippet, check_parent=False) # ------------------------------------------------------------------------- def add_system(self, name, fqdn, mac_address, comment=None): @@ -629,6 +634,7 @@ class Cobbler(BaseHandler): ks_meta_list = [] ks_meta_list.append("ROOT_PWD_HASH={}".format(self.config.get_root_pwd_hash())) ks_meta_list.append("SWAP_SIZE_MB={}".format(self.config.swap_size_mb)) + ks_meta_list.append("SYSTEM_STATUS={}".format(status)) ks_meta = None if ks_meta_list: @@ -650,6 +656,8 @@ class Cobbler(BaseHandler): args.append('--ksmeta') args.append(ks_meta) + cmd_str = 'cobbler ' + ' '.join(map(lambda x: pipes.quote(x), args)) + LOG.debug("Should execute: {}".format(cmd_str)) if self.verbose > 1: LOG.debug(_("Cobbler arguments for creating a new system:") + "\n" + pp(args)) diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 58ed6fc..683ae29 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -22,7 +22,7 @@ from fb_tools.config import ConfigError, BaseConfiguration from .xlate import XLATOR -__version__ = '1.5.5' +__version__ = '1.5.6' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -219,6 +219,12 @@ class CrTplConfiguration(BaseConfiguration): ks_base = 'template-' + self.os_id + '-' + self.system_status + '.ks' return self.cobbler_ks_dir / ks_base + # ------------------------------------------------------------------------- + @property + def snippets_dir(self): + """The path to the snippets dirctory, depending of the system status.""" + return self.cobbler_rootdir / 'snippets' / 'per_status' / self.system_status + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -237,6 +243,7 @@ class CrTplConfiguration(BaseConfiguration): res['data_size'] = self.data_size res['ram_gb'] = self.ram_gb res['system_ks'] = self.system_ks + res['snippets_dir'] = self.snippets_dir res['root_password'] = None if self.root_password: diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index ea03527..f44d629 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -42,7 +42,7 @@ from .cobbler import CobblerError, Cobbler from .xlate import XLATOR -__version__ = '1.5.7' +__version__ = '1.5.8' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -227,6 +227,8 @@ class CrTplHandler(BaseHandler): self.check_for_cobbler_distro() self.cobbler.ensure_profile() self.cobbler.ensure_root_authkeys() + self.cobbler.ensure_system_ks() + self.cobbler.ensure_snippets() self.vsphere.get_about() self.vsphere.get_clusters() -- 2.39.5