]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding some more configuration options
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 7 Feb 2019 10:40:12 +0000 (11:40 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 7 Feb 2019 10:40:12 +0000 (11:40 +0100)
etc/create-vmware-template.ini.default
lib/cr_vmware_tpl/config.py

index b5feff69ade82bf34f1a64ccfb075fb75f7fd5f3..35453691fd800e83ba0e043b92e2c56b817c28e7 100644 (file)
 
 ;mac_address = 00:16:3e:54:ab:2b
 
+[Timeouts]
+
+; General timeout in seconds for create_vm, poweron_vm and shutdown_vm
+; if the particular timeouts are not configured
+;max_wait_for_general = 15
+
+; Timeout in seconds for creating a VM in VSphere
+;max_wait_for_create_vm = 15
+
+; Timeout in seconds for powering on a VM in VSphere
+;max_wait_for_poweron_vm = 15
+
+; Timeout in seconds for shutting down a VM in VSphere
+;max_wait_for_shutdown_vm = 15
+
+; Timeout in seconds for waiting of completing the installation of the template VM
 ;max_wait_for_finish_install = 3600
 
 
index d53750e75b71c73f1585ee1af89ed7ba8308c060..de72e351237fe5c5b38e7cb40a69621c4260ea9b 100644 (file)
@@ -17,7 +17,7 @@ import re
 # Own modules
 from fb_tools.config import ConfigError, BaseConfiguration
 
-__version__ = '1.0.0'
+__version__ = '1.1.1'
 LOG = logging.getLogger(__name__)
 
 
@@ -49,11 +49,14 @@ class CrTplConfiguration(BaseConfiguration):
     default_ram_mb = 4 * 1024
     default_network = '192.168.88.0_23'
     default_mac_address = '00:16:3e:54:ab:2b'
+    default_max_wait_for_general = 15
     default_max_wait_for_finish_install = 60 * 60
     default_max_nr_templates_stay = 4
     default_vmware_cfg_version = 'vmx-13'
     default_os_version = 'oracleLinux7_64Guest'
+    min_max_wait_for_finish_general = 2
     min_max_wait_for_finish_install = 3 * 60
+    max_max_wait_for_finish_general = 60 * 60
     max_max_wait_for_finish_install = 24 * 60 * 60
     limit_max_nr_templates_stay = 100
 
@@ -78,6 +81,10 @@ class CrTplConfiguration(BaseConfiguration):
         self.ram_mb = self.default_ram_mb
         self.network = self.default_network
         self.mac_address = self.default_mac_address
+        self.max_wait_for_general = self.default_max_wait_for_general
+        self.max_wait_for_create_vm = None
+        self.max_wait_for_poweron_vm = None
+        self.max_wait_for_shutdown_vm = None
         self.max_wait_for_finish_install = self.default_max_wait_for_finish_install
         self.max_nr_templates_stay = self.default_max_nr_templates_stay
         self.vmware_cfg_version = self.default_vmware_cfg_version
@@ -155,6 +162,9 @@ class CrTplConfiguration(BaseConfiguration):
         if section_name.lower() == 'template':
             self._eval_config_template(config, section_name)
             return
+        if section_name.lower() == 'timeouts':
+            self._eval_config_timeouts(config, section_name)
+            return
 
         if self.verbose > 1:
             LOG.debug("Unhandled configuration section {!r}.".format(section_name))
@@ -249,28 +259,92 @@ class CrTplConfiguration(BaseConfiguration):
                 self.vmware_cfg_version = value.strip()
             elif key.lower() == 'os_version':
                 self.os_version = value.strip()
-            elif key.lower() == 'max_wait_for_finish_install':
-                v = float(value)
-                if v < self.min_max_wait_for_finish_install:
-                    LOG.error((
-                        "Value {val} for max_wait_for_finish_install is less than "
-                        "{minval}, using {default} seconds.").format(
-                            val=v, minval=self.min_max_wait_for_finish_install,
-                            default=self.default_max_wait_for_finish_install))
-                elif v > self.max_max_wait_for_finish_install:
-                    LOG.error((
-                        "Value {val} for max_wait_for_finish_install is greater than "
-                        "{maxval}, using {default} seconds.").format(
-                            val=v, maxval=self.max_max_wait_for_finish_install,
-                            default=self.default_max_wait_for_finish_install))
-                else:
-                    self.max_wait_for_finish_install = v
+
+        self._eval_config_timeouts(config, section_name)
 
         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, config, section_name):
+
+        if self.verbose > 1:
+            LOG.debug("Checking config section {!r} for timeouts ...".format(section_name))
+
+        for (key, value) in config.items(section_name):
+            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)
+
+        for (key, value) in config.items(section_name):
+            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)
+            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)
+            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.max_wait_for_general)
+            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)
+
+        if self.max_wait_for_create_vm is None:
+            self.max_wait_for_create_vm = self.max_wait_for_general
+        if self.max_wait_for_poweron_vm is None:
+            self.max_wait_for_poweron_vm = self.max_wait_for_general
+        if self.max_wait_for_shutdown_vm is None:
+            self.max_wait_for_shutdown_vm = self.max_wait_for_general
+
+
+# =============================================================================
 if __name__ == "__main__":
 
     pass