from .cobbler import ConfigCobbler
from .ldap import LdapConnectionInfo, LdapConnectionDict
+from .timeouts import ConfigTimeouts
-__version__ = '3.1.0'
+__version__ = '3.1.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# =============================================================================
-class CrTplConfiguration(BaseMultiConfig, ConfigCobbler):
+class CrTplConfiguration(BaseMultiConfig, ConfigCobbler, ConfigTimeouts):
"""
A class for providing a configuration for the CrTplApplication class
and methods to read it from configuration files.
return
- # -------------------------------------------------------------------------
- def _eval_timeout_value(self, prop_name, value, min_val, max_val, default_val):
-
- if self.verbose > 2:
- LOG.debug(_("Checking value {v!r} for {p} ...").format(v=value, p=prop_name))
- if self.verbose > 3:
- LOG.debug(_(
- "Minimal value: {min_val}, maximum value: {max_val}, "
- "default value: {def_val}.").format(
- min_val=min_val, max_val=max_val, def_val=default_val))
-
- v = float(value)
-
- if v < min_val:
- msg = _(
- "Value {val} for {prop} is less than {min_val}, "
- "using {def_val} seconds.").format(val=v, min_val=min_val, def_val=default_val)
- LOG.error(msg)
- return
-
- if v < min_val:
- msg = _(
- "Value {val} for {prop} is greater than {max_val}, "
- "using {def_val} seconds.").format(val=v, max_val=max_val, def_val=default_val)
- LOG.error(msg)
- return
-
- if self.verbose > 2:
- msg = _("Setting timeout {p!r} to {v:0.1f} seconds.").format(p=prop_name, v=v)
- LOG.debug(msg)
- setattr(self, prop_name, v)
-
- # -------------------------------------------------------------------------
- def _eval_config_timeouts(self, section_name, section):
-
- if self.verbose > 1:
- LOG.debug(_("Checking config section {!r} ...").format(section_name))
-
- for key in section.keys():
- value = section[key]
-
- if key.lower() == 'max_wait_for_general':
- self._eval_timeout_value(
- prop_name='max_wait_for_general', value=value,
- min_val=self.min_max_wait_for_finish_general,
- max_val=self.max_max_wait_for_finish_general,
- default_val=self.default_max_wait_for_general)
- continue
-
- if key.lower() == 'max_wait_for_create_vm':
- self._eval_timeout_value(
- prop_name='max_wait_for_create_vm', value=value,
- min_val=self.min_max_wait_for_finish_general,
- max_val=self.max_max_wait_for_finish_general,
- default_val=self.max_wait_for_general)
- continue
- elif key.lower() == 'max_wait_for_poweron_vm':
- self._eval_timeout_value(
- prop_name='max_wait_for_poweron_vm', value=value,
- min_val=self.min_max_wait_for_finish_general,
- max_val=self.max_max_wait_for_finish_general,
- default_val=self.max_wait_for_general)
- continue
- elif key.lower() == 'max_wait_for_shutdown_vm':
- self._eval_timeout_value(
- prop_name='max_wait_for_shutdown_vm', value=value,
- min_val=self.min_max_wait_for_finish_general,
- max_val=self.max_max_wait_for_finish_general,
- default_val=self.default_max_wait_for_shutdown)
- continue
- elif key.lower() == 'max_wait_for_purge_vm':
- self._eval_timeout_value(
- prop_name='max_wait_for_purge_vm', value=value,
- min_val=self.min_max_wait_for_finish_general,
- max_val=self.max_max_wait_for_finish_general,
- default_val=self.max_wait_for_general)
- continue
- elif key.lower() == 'max_wait_for_finish_install':
- self._eval_timeout_value(
- prop_name='max_wait_for_finish_install', value=value,
- min_val=self.min_max_wait_for_finish_install,
- max_val=self.max_max_wait_for_finish_install,
- default_val=self.default_max_wait_for_finish_install)
- continue
-
# -------------------------------------------------------------------------
def get_root_pwd_hash(self, method='sha256'):
"""Generates a password hash based on the root password."""
--- /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 timeout configuration stuff.
+"""
+from __future__ import absolute_import, print_function
+
+# Standard modules
+import logging
+
+# Third party modules
+
+# Own modules
+from ..xlate import XLATOR
+
+__version__ = '0.1.0'
+
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
+# =============================================================================
+class ConfigTimeouts():
+ """
+ A mixin class for extending the CrTplConfiguration class for timeout dependent methods.
+ """
+
+ # -------------------------------------------------------------------------
+ def _eval_timeout_value(self, prop_name, value, min_val, max_val, default_val):
+
+ if self.verbose > 2:
+ LOG.debug(_("Checking value {v!r} for {p} ...").format(v=value, p=prop_name))
+ if self.verbose > 3:
+ LOG.debug(_(
+ "Minimal value: {min_val}, maximum value: {max_val}, "
+ "default value: {def_val}.").format(
+ min_val=min_val, max_val=max_val, def_val=default_val))
+
+ v = float(value)
+
+ if v < min_val:
+ msg = _(
+ "Value {val} for {prop} is less than {min_val}, "
+ "using {def_val} seconds.").format(val=v, min_val=min_val, def_val=default_val)
+ LOG.error(msg)
+ return
+
+ if v < min_val:
+ msg = _(
+ "Value {val} for {prop} is greater than {max_val}, "
+ "using {def_val} seconds.").format(val=v, max_val=max_val, def_val=default_val)
+ LOG.error(msg)
+ return
+
+ if self.verbose > 2:
+ msg = _("Setting timeout {p!r} to {v:0.1f} seconds.").format(p=prop_name, v=v)
+ LOG.debug(msg)
+ setattr(self, prop_name, v)
+
+ # -------------------------------------------------------------------------
+ def _eval_config_timeouts(self, section_name, section):
+
+ if self.verbose > 1:
+ LOG.debug(_("Checking config section {!r} ...").format(section_name))
+
+ for key in section.keys():
+ value = section[key]
+
+ if key.lower() == 'max_wait_for_general':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_general', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.default_max_wait_for_general)
+ continue
+
+ if key.lower() == 'max_wait_for_create_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_create_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.max_wait_for_general)
+ continue
+ elif key.lower() == 'max_wait_for_poweron_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_poweron_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.max_wait_for_general)
+ continue
+ elif key.lower() == 'max_wait_for_shutdown_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_shutdown_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.default_max_wait_for_shutdown)
+ continue
+ elif key.lower() == 'max_wait_for_purge_vm':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_purge_vm', value=value,
+ min_val=self.min_max_wait_for_finish_general,
+ max_val=self.max_max_wait_for_finish_general,
+ default_val=self.max_wait_for_general)
+ continue
+ elif key.lower() == 'max_wait_for_finish_install':
+ self._eval_timeout_value(
+ prop_name='max_wait_for_finish_install', value=value,
+ min_val=self.min_max_wait_for_finish_install,
+ max_val=self.max_max_wait_for_finish_install,
+ default_val=self.default_max_wait_for_finish_install)
+ continue
+
+
+# =============================================================================
+if __name__ == "__main__":
+
+ pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list