]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Separating distro dependend methods from cr_vmware_tpl.cobbler to cr_vmware_tpl.cobbl...
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Sep 2023 08:33:57 +0000 (10:33 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Sep 2023 08:33:57 +0000 (10:33 +0200)
lib/cr_vmware_tpl/cobbler/__init__.py
lib/cr_vmware_tpl/cobbler/distro.py [new file with mode: 0644]

index 031f5d61eff0755d2004c049202b23cdde3004ce..19d9127cc1e482e3a4ed1b8e9af64aaa1a79c78a 100644 (file)
@@ -8,7 +8,7 @@
 """
 from __future__ import absolute_import, print_function
 
-# Standard module
+# Standard modules
 import logging
 import re
 import datetime
@@ -38,6 +38,8 @@ from fb_tools.handling_obj import CompletedProcess
 from fb_tools.handler import BaseHandler
 from fb_tools.xlate import format_list
 
+from .distro import CobblerDistro
+
 from .. import print_section_start, print_section_end
 
 from ..config import CrTplConfiguration
@@ -55,7 +57,7 @@ ngettext = XLATOR.ngettext
 
 
 # =============================================================================
-class Cobbler(BaseHandler):
+class Cobbler(BaseHandler, CobblerDistro):
     """
     A handler class for executing cobbler actions.
     """
@@ -353,57 +355,6 @@ class Cobbler(BaseHandler):
                 dsc=dsc, rdir=str(rdir), host=self.host, err=err)
             raise ExpectedCobblerError(msg)
 
-    # -------------------------------------------------------------------------
-    def get_distro_list(self):
-        """Trying to get a list of all configured distros."""
-
-        distro_list = []
-        proc = self.exec_cobbler(('distro', 'list'), no_simulate=True, show_output=False)
-        for line in proc.stdout.splitlines():
-            distro = line.strip()
-            if distro:
-                distro_list.append(distro)
-        distro_list.sort(key=str.lower)
-        if self.verbose > 1:
-            LOG.debug(_("Sorted list of found distros:") + "\n{}".format(pp(distro_list)))
-        return distro_list
-
-    # -------------------------------------------------------------------------
-    def get_repo_list(self):
-        """Trying to get a list of all configured repositories."""
-
-        repo_list = []
-
-        proc = self.exec_cobbler(('repo', 'list'), no_simulate=True, show_output=False)
-        for line in proc.stdout.splitlines():
-            repo = line.strip()
-            if repo:
-                repo_list.append(repo)
-        repo_list.sort(key=str.lower)
-        if self.verbose > 1:
-            LOG.debug(_("Sorted list of found repositories:") + "\n{}".format(pp(repo_list)))
-        return repo_list
-
-    # -------------------------------------------------------------------------
-    def verify_distro_repos(self, distro):
-
-        repo_list = self.get_repo_list()
-
-        LOG.debug(_("Checking existence of repos for distro {!r}.").format(distro.name))
-
-        all_ok = True
-        for repo in distro.repos:
-            if repo not in repo_list:
-                msg = _("Repo {r!r} for distro {d!r} not found on cobbler server.").format(
-                    r=repo, d=distro.name)
-                LOG.warn(msg)
-                all_ok = False
-            elif self.verbose > 1:
-                msg = _("Found repo {r!r} for distro {d!r}.").format(r=repo, d=distro.name)
-                LOG.debug(msg)
-
-        return all_ok
-
     # -------------------------------------------------------------------------
     def get_profile_list(self):
         """Trying to get a list of all configured cobbler profiles."""
diff --git a/lib/cr_vmware_tpl/cobbler/distro.py b/lib/cr_vmware_tpl/cobbler/distro.py
new file mode 100644 (file)
index 0000000..c35233f
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2023 by Frank Brehm, Berlin
+@summary: A mixin module forthe Cobbler class
+"""
+from __future__ import absolute_import, print_function
+
+# Standard modules
+import logging
+
+from fb_tools.common import pp, to_str, is_sequence, to_bool
+from fb_tools.xlate import format_list
+
+# Own modules
+
+from ..xlate import XLATOR
+
+__version__ = '0.1.1'
+
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
+# =============================================================================
+class CobblerDistro():
+    """
+    A mixin class for extending the Cobbler class for repo dependend methods.
+    """
+
+    # -------------------------------------------------------------------------
+    def get_distro_list(self):
+        """Trying to get a list of all configured distros."""
+
+        distro_list = []
+        proc = self.exec_cobbler(('distro', 'list'), no_simulate=True, show_output=False)
+        for line in proc.stdout.splitlines():
+            distro = line.strip()
+            if distro:
+                distro_list.append(distro)
+        distro_list.sort(key=str.lower)
+        if self.verbose > 1:
+            LOG.debug(_("Sorted list of found distros:") + "\n{}".format(pp(distro_list)))
+        return distro_list
+
+    # -------------------------------------------------------------------------
+    def get_repo_list(self):
+        """Trying to get a list of all configured repositories."""
+
+        repo_list = []
+
+        proc = self.exec_cobbler(('repo', 'list'), no_simulate=True, show_output=False)
+        for line in proc.stdout.splitlines():
+            repo = line.strip()
+            if repo:
+                repo_list.append(repo)
+        repo_list.sort(key=str.lower)
+        if self.verbose > 1:
+            LOG.debug(_("Sorted list of found repositories:") + "\n{}".format(pp(repo_list)))
+        return repo_list
+
+    # -------------------------------------------------------------------------
+    def verify_distro_repos(self, distro):
+
+        repo_list = self.get_repo_list()
+
+        LOG.debug(_("Checking existence of repos for distro {!r}.").format(distro.name))
+
+        all_ok = True
+        for repo in distro.repos:
+            if repo not in repo_list:
+                msg = _("Repo {r!r} for distro {d!r} not found on cobbler server.").format(
+                    r=repo, d=distro.name)
+                LOG.warn(msg)
+                all_ok = False
+            elif self.verbose > 1:
+                msg = _("Found repo {r!r} for distro {d!r}.").format(r=repo, d=distro.name)
+                LOG.debug(msg)
+
+        return all_ok
+
+
+# =============================================================================
+if __name__ == "__main__":
+
+    pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list