]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Separating timeout dependend methods from cr_vmware_tpl.config to cr_vmware_tpl.confi...
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Sep 2023 11:54:17 +0000 (13:54 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Sep 2023 11:54:17 +0000 (13:54 +0200)
lib/cr_vmware_tpl/config/__init__.py
lib/cr_vmware_tpl/config/timeouts.py [new file with mode: 0644]

index aa32c0444682efc89f11564b8e5c9fdde6aa29b4..2a73e85e6af2279f1146342ad28b2b2fdea50dd3 100644 (file)
@@ -36,8 +36,9 @@ from ..xlate import XLATOR
 
 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
@@ -45,7 +46,7 @@ ngettext = XLATOR.ngettext
 
 
 # =============================================================================
-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.
@@ -675,91 +676,6 @@ class CrTplConfiguration(BaseMultiConfig, ConfigCobbler):
 
         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."""
diff --git a/lib/cr_vmware_tpl/config/timeouts.py b/lib/cr_vmware_tpl/config/timeouts.py
new file mode 100644 (file)
index 0000000..2ae9492
--- /dev/null
@@ -0,0 +1,125 @@
+#!/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