From: Frank Brehm Date: Fri, 29 May 2020 11:17:50 +0000 (+0200) Subject: Seperating code into an extra method X-Git-Tag: 2.1.2^2~9^2~31^2~78 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=5e5eeea0d8aad0ca7dd02d8755c4465b3f536e84;p=pixelpark%2Fcreate-vmware-tpl.git Seperating code into an extra method --- diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 4d960b5..fd9abfe 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -35,7 +35,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.3.9' +__version__ = '0.3.10' LOG = logging.getLogger(__name__) @@ -305,24 +305,28 @@ class Cobbler(BaseHandler): return profile_list # ------------------------------------------------------------------------- - def ensure_profile_ks(self): + def ensure_remote_file(self, local_file, remote_file): - remote_ks = self.config.cobbler_profile_ks - local_ks = self.base_dir / 'kickstart' / (self.config.cobbler_profile + '.ks') + self.check_remote_directory(remote_file.parent) - if not local_ks.exists() or not local_ks.is_file(): - msg = _("Kickstart script {!r} either not exists or is not a regular file.").format( - str(local_ks)) + if self.verbose > 1: + msg = _("Checking remote file {rfile!r} based on local {lfile!r} ...").format( + rfile=str(remote_file), lfile=str(local_file)) + LOG.debug(msg) + + if not local_file.exists() or not local_file.is_file(): + msg = _("Local file {!r} either not exists or is not a regular file.").format( + str(local_file)) raise ExpectedCobblerError(msg) - local_ks_content = local_ks.read_bytes() - digest = hashlib.sha256(local_ks_content).hexdigest() + local_file_content = local_file.read_bytes() + digest = hashlib.sha256(local_file_content).hexdigest() if self.verbose > 1: LOG.debug(_('{typ} sum of {ks!r} is: {dig}').format( - typ='SHA256', ks=str(local_ks), dig=digest)) + typ='SHA256', ks=str(local_file), dig=digest)) cmd = textwrap.dedent("""\ - if [ -f {ks!r} ] ; then - digest=$(sha256sum {ks!r} | awk '{{print $1}}') + if [ -f {rfile!r} ] ; then + digest=$(sha256sum {rfile!r} | awk '{{print $1}}') echo "Digest: ${{digest}}" if [ "${{digest}}" != {dig!r} ] ; then echo "SHA256 sum does not match." >&2 @@ -332,18 +336,26 @@ class Cobbler(BaseHandler): else exit 3 fi - """).format(ks=str(remote_ks), dig=digest) + """).format(rfile=str(remote_file), dig=digest) proc = self.exec_ssh(cmd) if proc.returncode == 0: - LOG.debug(_("Remote Kickstart script {!r} has the correct content.").format( - str(remote_ks))) + LOG.debug(_("Remote file {!r} has the correct content.").format( + str(remote_file))) return - msg = _("Kickstart script {!r} has to be copied.").format(str(local_ks)) + msg = _("File {!r} has to be copied.").format(str(local_file)) LOG.warn(msg) - self.scp_to(local_ks, remote_ks) + self.scp_to(local_file, remote_file) + + # ------------------------------------------------------------------------- + def ensure_profile_ks(self): + + remote_ks = self.config.cobbler_profile_ks + local_ks = self.base_dir / 'kickstart' / (self.config.cobbler_profile + '.ks') + + self.ensure_remote_file(local_ks, remote_ks) # ------------------------------------------------------------------------- def ensure_profile(self):