"""
from __future__ import absolute_import, print_function
-# Standard module
+# Standard modules
import logging
import re
import datetime
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
# =============================================================================
-class Cobbler(BaseHandler):
+class Cobbler(BaseHandler, CobblerDistro):
"""
A handler class for executing cobbler actions.
"""
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."""
--- /dev/null
+#!/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