]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Seperating code into an extra method
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 29 May 2020 11:17:50 +0000 (13:17 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 29 May 2020 11:17:50 +0000 (13:17 +0200)
lib/cr_vmware_tpl/cobbler.py

index 4d960b50cb135eb077af9d1880ec9df7f4abfe00..fd9abfe685369a7c84f45c03e00321a27b13d2c0 100644 (file)
@@ -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):