from ..xlate import XLATOR
-from .distro import CobblerDistroInfo
+from .cobbler import ConfigCobbler
from .ldap import LdapConnectionInfo, LdapConnectionDict
-__version__ = '3.0.2'
+__version__ = '3.1.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# =============================================================================
-class CrTplConfiguration(BaseMultiConfig):
+class CrTplConfiguration(BaseMultiConfig, ConfigCobbler):
"""
A class for providing a configuration for the CrTplApplication class
and methods to read it from configuration files.
return False
- # -------------------------------------------------------------------------
- def verify_cobbler_distros(self):
-
- LOG.debug(_("Verifying cobbler distros ..."))
-
- if not len(self.cobbler_distros):
- msg = _("Did not found configured Cobbler distros.")
- raise CrTplConfigError(msg)
-
- for distro_id in self.cobbler_distros.keys():
- distro = self.cobbler_distros[distro_id]
-
- if not distro.distro:
- msg = _("Did not found distro of configured Cobbler distro {!r}.").format(
- distro_id)
- raise CrTplConfigError(msg)
-
- if not distro.ks_repo_url:
- msg = _(
- "Did not found the base install repo URL of configured Cobbler "
- "distro {!r}.").format(distro_id)
- raise CrTplConfigError(msg)
-
- if not len(distro.repos):
- msg = _(
- "Did not found repo definitions for configured Cobbler "
- "distro {!r}.").format(distro_id)
- LOG.warn(msg)
-
- if not distro.description:
- distro.description = distro_id
-
- LOG.debug(_("Searching for distro with ID {!r} ...").format(self.os_id))
-
- if self.os_id not in self.cobbler_distros:
- msg = _("Did not found distro {!r} in configured Cobbler distros.").format(self.os_id)
- raise CrTplConfigError(msg)
-
- self.current_distro = self.cobbler_distros[self.os_id]
- self.cobbler_distro = self.current_distro.distro
-
- LOG.info(_("Using OS {os!r} with cobbler distro {di!r}.").format(
- os=self.os_id, di=self.cobbler_distro))
-
# -------------------------------------------------------------------------
def eval_section(self, section_name):
default_val=self.default_max_wait_for_finish_install)
continue
- # -------------------------------------------------------------------------
- def _eval_config_cobbler(self, section_name, section):
-
- if self.verbose > 1:
- LOG.debug(_("Checking config section {!r} ...").format(section_name))
-
- re_port_key = re.compile(r'^\s*ssh[-_]?port\s*$', re.IGNORECASE)
- re_user_key = re.compile(r'^\s*ssh[-_]?user\s*$', re.IGNORECASE)
- re_timeout_key = re.compile(r'^\s*ssh[-_]?timeout\s*$', re.IGNORECASE)
- re_rootdir_key = re.compile(r'^\s*root[-_]?dir(?:ectory)?\s*$', re.IGNORECASE)
- re_split_values = re.compile(r'[,;\s]+')
- re_pr_repos_key = re.compile(r'^\s*profile[-_]?repos?\s*$', re.IGNORECASE)
- re_nameserver_key = re.compile(r'^\s*nameservers?\s*$', re.IGNORECASE)
- re_dns_search_key = re.compile(r'^\s*dns[-_]?search\s*$', re.IGNORECASE)
- re_ws_base_url_key = re.compile(
- r'^\s*(?:ws|webserver)[-_]?base[-_]?url\s*$', re.IGNORECASE)
- re_ws_docroot_key = re.compile(
- r'^\s*(?:ws|webserver)[-_]?docroot\s*$', re.IGNORECASE)
- re_ws_rel_filesdir_key = re.compile(
- r'^\s*(?:ws|webserver)[-_]?rel(?:ative)?[-_]?filesdir\s*$', re.IGNORECASE)
- re_system_status = re.compile(r'^\s*system[-_]?status\s*$', re.IGNORECASE)
- re_cobbler_bin_key = re.compile(r'^\s*(?:cobbler[_-]?)?bin\s*$', re.IGNORECASE)
-
- for key in section.keys():
- value = section[key]
-
- if key.lower() == 'distro' and value.strip() != '':
- self.cobbler_distro = value.strip()
- continue
- if key.lower() == 'host' and value.strip() != '':
- self.cobbler_host = value.strip().lower()
- continue
- if re_port_key.match(key) and value.strip() != '':
- self.cobbler_ssh_port = int(value)
- continue
- if re_user_key.match(key):
- self.cobbler_ssh_user = value.strip().lower()
- continue
- if re_timeout_key.match(key):
- self.cobbler_ssh_timeout = int(value)
- continue
- if re_cobbler_bin_key.match(key) and value.strip() != '':
- self.cobbler_bin = value.strip()
- continue
- if re_rootdir_key.match(key):
- dpath = Path(value)
- if dpath.is_absolute():
- self.cobbler_rootdir = Path(value)
- else:
- msg = _("Path for {what} {path!r} is not absolute.").format(
- what=_("Cobbler root directory"), path=str(dpath))
- LOG.error(msg)
- continue
- if key.lower() == 'profile' and value.strip() != '':
- self.cobbler_profile = value.strip().lower()
- self.cobbler_profile_given = True
- continue
- if re_pr_repos_key.match(key) and value.strip() != '':
- self.cobbler_profile_repos = re_split_values.split(value.strip())
- continue
- if re_nameserver_key.match(key) and value.strip() != '':
- self.cobbler_nameservers = re_split_values.split(value.strip().lower())
- continue
- if re_dns_search_key.match(key) and value.strip() != '':
- self.cobbler_dns_search = re_split_values.split(value.strip().lower())
- continue
- if re_ws_base_url_key.match(key) and value.strip() != '':
- self.cobbler_ws_base_url = value.strip().lower()
- continue
- if re_ws_docroot_key.match(key) and value.strip() != '':
- dpath = Path(value.strip())
- if dpath.is_absolute():
- self.cobbler_ws_docroot = dpath
- else:
- msg = _("Path for {what} {path!r} is not absolute.").format(
- what=_("Webserver document root"), path=str(dpath))
- LOG.error(msg)
- continue
- if re_ws_rel_filesdir_key.match(key) and value.strip() != '':
- self.cobbler_ws_rel_filesdir = Path(value.strip())
- continue
- if re_system_status.match(key) and value.strip() != '':
- val = value.strip().lower()
- if val in self.valid_system_status:
- self.system_status = val
- else:
- msg = _(
- "The value of {what!r} must be one of {valid!r}, "
- "but found {val!r}.").format(
- what='system_status',
- valid=self.valid_system_status, val=value)
- LOG.error(msg)
- continue
-
- # -------------------------------------------------------------------------
- def _eval_cobbler_distros(self, section_name, section):
-
- if self.verbose > 1:
- LOG.debug(_("Checking config section {!r} ...").format(section_name))
-
- for distro_id in section.keys():
- distro_info = section[distro_id]
- distro_id = distro_id.lower()
- distro = CobblerDistroInfo.init_from_config(
- distro_id, distro_info, verbose=self.verbose)
- self.cobbler_distros[distro_id] = distro
-
# -------------------------------------------------------------------------
def get_root_pwd_hash(self, method='sha256'):
"""Generates a password hash based on the root password."""
return pwd_hash
- # -------------------------------------------------------------------------
- def _eval_cobbler_repos(self, section_name, section):
-
- if self.verbose > 1:
- LOG.debug(_("Checking config section {!r} ...").format(section_name))
-
- for full_repo_name in section.keys():
- repo_data = section[full_repo_name]
- if isinstance(repo_data, dict):
- repo_info = {}
- if self.verbose > 2:
- LOG.debug(_("Found Cobbler repository {!r}.").format(full_repo_name))
- for key in repo_data.keys():
- value = repo_data[key]
- if key.lower() == 'reponame' and value.strip() != '':
- repo_info['reponame'] = value.strip()
- continue
- if key.lower() == 'filename' and value.strip() != '':
- repo_info['filename'] = value.strip()
- continue
- self.cobbler_repos[full_repo_name] = repo_info
- if self.verbose > 3:
- LOG.debug(_("Evaluated Cobbler repositories:") + '\n' + pp(self.cobbler_repos))
-
# -------------------------------------------------------------------------
def strip_unnessecary(self):
"""Stripping no more necessary stuff."""
--- /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 for the CrTplConfiguration class for cobbler configuration stuff.
+"""
+from __future__ import absolute_import, print_function
+
+# Standard modules
+import logging
+import re
+
+from pathlib import Path
+
+# Third party modules
+from fb_tools.common import pp
+
+# Own modules
+from ..errors import CrTplConfigError
+
+from .distro import CobblerDistroInfo
+
+from ..xlate import XLATOR
+
+__version__ = '0.1.0'
+
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
+# =============================================================================
+class ConfigCobbler():
+ """
+ A mixin class for extending the CrTplConfiguration class for cobbler dependent methods.
+ """
+
+ # -------------------------------------------------------------------------
+ def verify_cobbler_distros(self):
+
+ LOG.debug(_("Verifying cobbler distros ..."))
+
+ if not len(self.cobbler_distros):
+ msg = _("Did not found configured Cobbler distros.")
+ raise CrTplConfigError(msg)
+
+ for distro_id in self.cobbler_distros.keys():
+ distro = self.cobbler_distros[distro_id]
+
+ if not distro.distro:
+ msg = _("Did not found distro of configured Cobbler distro {!r}.").format(
+ distro_id)
+ raise CrTplConfigError(msg)
+
+ if not distro.ks_repo_url:
+ msg = _(
+ "Did not found the base install repo URL of configured Cobbler "
+ "distro {!r}.").format(distro_id)
+ raise CrTplConfigError(msg)
+
+ if not len(distro.repos):
+ msg = _(
+ "Did not found repo definitions for configured Cobbler "
+ "distro {!r}.").format(distro_id)
+ LOG.warn(msg)
+
+ if not distro.description:
+ distro.description = distro_id
+
+ LOG.debug(_("Searching for distro with ID {!r} ...").format(self.os_id))
+
+ if self.os_id not in self.cobbler_distros:
+ msg = _("Did not found distro {!r} in configured Cobbler distros.").format(self.os_id)
+ raise CrTplConfigError(msg)
+
+ self.current_distro = self.cobbler_distros[self.os_id]
+ self.cobbler_distro = self.current_distro.distro
+
+ LOG.info(_("Using OS {os!r} with cobbler distro {di!r}.").format(
+ os=self.os_id, di=self.cobbler_distro))
+
+ # -------------------------------------------------------------------------
+ def _eval_config_cobbler(self, section_name, section):
+
+ if self.verbose > 1:
+ LOG.debug(_("Checking config section {!r} ...").format(section_name))
+
+ re_port_key = re.compile(r'^\s*ssh[-_]?port\s*$', re.IGNORECASE)
+ re_user_key = re.compile(r'^\s*ssh[-_]?user\s*$', re.IGNORECASE)
+ re_timeout_key = re.compile(r'^\s*ssh[-_]?timeout\s*$', re.IGNORECASE)
+ re_rootdir_key = re.compile(r'^\s*root[-_]?dir(?:ectory)?\s*$', re.IGNORECASE)
+ re_split_values = re.compile(r'[,;\s]+')
+ re_pr_repos_key = re.compile(r'^\s*profile[-_]?repos?\s*$', re.IGNORECASE)
+ re_nameserver_key = re.compile(r'^\s*nameservers?\s*$', re.IGNORECASE)
+ re_dns_search_key = re.compile(r'^\s*dns[-_]?search\s*$', re.IGNORECASE)
+ re_ws_base_url_key = re.compile(
+ r'^\s*(?:ws|webserver)[-_]?base[-_]?url\s*$', re.IGNORECASE)
+ re_ws_docroot_key = re.compile(
+ r'^\s*(?:ws|webserver)[-_]?docroot\s*$', re.IGNORECASE)
+ re_ws_rel_filesdir_key = re.compile(
+ r'^\s*(?:ws|webserver)[-_]?rel(?:ative)?[-_]?filesdir\s*$', re.IGNORECASE)
+ re_system_status = re.compile(r'^\s*system[-_]?status\s*$', re.IGNORECASE)
+ re_cobbler_bin_key = re.compile(r'^\s*(?:cobbler[_-]?)?bin\s*$', re.IGNORECASE)
+
+ for key in section.keys():
+ value = section[key]
+
+ if key.lower() == 'distro' and value.strip() != '':
+ self.cobbler_distro = value.strip()
+ continue
+ if key.lower() == 'host' and value.strip() != '':
+ self.cobbler_host = value.strip().lower()
+ continue
+ if re_port_key.match(key) and value.strip() != '':
+ self.cobbler_ssh_port = int(value)
+ continue
+ if re_user_key.match(key):
+ self.cobbler_ssh_user = value.strip().lower()
+ continue
+ if re_timeout_key.match(key):
+ self.cobbler_ssh_timeout = int(value)
+ continue
+ if re_cobbler_bin_key.match(key) and value.strip() != '':
+ self.cobbler_bin = value.strip()
+ continue
+ if re_rootdir_key.match(key):
+ dpath = Path(value)
+ if dpath.is_absolute():
+ self.cobbler_rootdir = Path(value)
+ else:
+ msg = _("Path for {what} {path!r} is not absolute.").format(
+ what=_("Cobbler root directory"), path=str(dpath))
+ LOG.error(msg)
+ continue
+ if key.lower() == 'profile' and value.strip() != '':
+ self.cobbler_profile = value.strip().lower()
+ self.cobbler_profile_given = True
+ continue
+ if re_pr_repos_key.match(key) and value.strip() != '':
+ self.cobbler_profile_repos = re_split_values.split(value.strip())
+ continue
+ if re_nameserver_key.match(key) and value.strip() != '':
+ self.cobbler_nameservers = re_split_values.split(value.strip().lower())
+ continue
+ if re_dns_search_key.match(key) and value.strip() != '':
+ self.cobbler_dns_search = re_split_values.split(value.strip().lower())
+ continue
+ if re_ws_base_url_key.match(key) and value.strip() != '':
+ self.cobbler_ws_base_url = value.strip().lower()
+ continue
+ if re_ws_docroot_key.match(key) and value.strip() != '':
+ dpath = Path(value.strip())
+ if dpath.is_absolute():
+ self.cobbler_ws_docroot = dpath
+ else:
+ msg = _("Path for {what} {path!r} is not absolute.").format(
+ what=_("Webserver document root"), path=str(dpath))
+ LOG.error(msg)
+ continue
+ if re_ws_rel_filesdir_key.match(key) and value.strip() != '':
+ self.cobbler_ws_rel_filesdir = Path(value.strip())
+ continue
+ if re_system_status.match(key) and value.strip() != '':
+ val = value.strip().lower()
+ if val in self.valid_system_status:
+ self.system_status = val
+ else:
+ msg = _(
+ "The value of {what!r} must be one of {valid!r}, "
+ "but found {val!r}.").format(
+ what='system_status',
+ valid=self.valid_system_status, val=value)
+ LOG.error(msg)
+ continue
+
+ # -------------------------------------------------------------------------
+ def _eval_cobbler_repos(self, section_name, section):
+
+ if self.verbose > 1:
+ LOG.debug(_("Checking config section {!r} ...").format(section_name))
+
+ for full_repo_name in section.keys():
+ repo_data = section[full_repo_name]
+ if isinstance(repo_data, dict):
+ repo_info = {}
+ if self.verbose > 2:
+ LOG.debug(_("Found Cobbler repository {!r}.").format(full_repo_name))
+ for key in repo_data.keys():
+ value = repo_data[key]
+ if key.lower() == 'reponame' and value.strip() != '':
+ repo_info['reponame'] = value.strip()
+ continue
+ if key.lower() == 'filename' and value.strip() != '':
+ repo_info['filename'] = value.strip()
+ continue
+ self.cobbler_repos[full_repo_name] = repo_info
+ if self.verbose > 3:
+ LOG.debug(_("Evaluated Cobbler repositories:") + '\n' + pp(self.cobbler_repos))
+
+ # -------------------------------------------------------------------------
+ def _eval_cobbler_distros(self, section_name, section):
+
+ if self.verbose > 1:
+ LOG.debug(_("Checking config section {!r} ...").format(section_name))
+
+ for distro_id in section.keys():
+ distro_info = section[distro_id]
+ distro_id = distro_id.lower()
+ distro = CobblerDistroInfo.init_from_config(
+ distro_id, distro_info, verbose=self.verbose)
+ self.cobbler_distros[distro_id] = distro
+
+
+# =============================================================================
+if __name__ == "__main__":
+
+ pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list