From 922eed1516c9f3504b86320625ecad158041b439 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 11 Jun 2020 15:27:50 +0200 Subject: [PATCH] Executing 'cobbler sync' after adding a new system --- lib/cr_vmware_tpl/cobbler.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 3e749b5..880c088 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.8' +__version__ = '0.4.9' LOG = logging.getLogger(__name__) @@ -677,11 +677,6 @@ class Cobbler(BaseHandler): args.append('--management') args.append('true') - 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)) - proc = self.exec_cobbler(args) if proc.returncode: @@ -694,6 +689,31 @@ class Cobbler(BaseHandler): rc=proc.returncode, err=err) raise ExpectedCobblerError(msg) + self.sync() + + # ------------------------------------------------------------------------- + def sync(self): + """Executing 'cobbler sync' to apply environment, especially DHCPD configuration.""" + + proc = self.exec_cobbler('sync') + + if proc.returncode != 0: + err = _('No error message') + if proc.stderr: + err = proc.stderr + elif proc.stdout: + err = proc.stdout + msg = _("Could syncing cobbler: {}").format(err) + raise ExpectedCobblerError(msg) + + if self.verbose > 1: + if proc.stdout: + LOG.debug(_("Output on {}:").format('STDOUT') + '\n' + proc.stdout) + if self.verbose: + if proc.stderr: + LOG.debug(_("Output on {}:").format('STDERR') + '\n' + proc.stderr) + + # ============================================================================= if __name__ == "__main__": -- 2.39.5