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

index 35453691fd800e83ba0e043b92e2c56b817c28e7..4b2ab55c0a99186b52aab2e5f664012d44c206d4 100644 (file)
 ;max_wait_for_poweron_vm = 15
 
 ; Timeout in seconds for shutting down a VM in VSphere
-;max_wait_for_shutdown_vm = 15
+;max_wait_for_shutdown_vm = 60
+
+; Timeout in seconds for purging a VM in VSphere in case of fatal errors
+;max_wait_for_purge_vm = 15
 
 ; Timeout in seconds for waiting of completing the installation of the template VM
 ;max_wait_for_finish_install = 3600
index de72e351237fe5c5b38e7cb40a69621c4260ea9b..4e8998daaf67a0cf6e161ee46ab0abf1ff33d216 100644 (file)
@@ -17,7 +17,7 @@ import re
 # Own modules
 from fb_tools.config import ConfigError, BaseConfiguration
 
-__version__ = '1.1.1'
+__version__ = '1.2.0'
 LOG = logging.getLogger(__name__)
 
 
@@ -50,6 +50,7 @@ class CrTplConfiguration(BaseConfiguration):
     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_shutdown = 600
     default_max_wait_for_finish_install = 60 * 60
     default_max_nr_templates_stay = 4
     default_vmware_cfg_version = 'vmx-13'
@@ -84,7 +85,8 @@ class CrTplConfiguration(BaseConfiguration):
         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_shutdown_vm = self.default_max_wait_for_shutdown
+        self.max_wait_for_purge_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
@@ -151,6 +153,24 @@ class CrTplConfiguration(BaseConfiguration):
 
         return res
 
+    # -------------------------------------------------------------------------
+    def eval_config(self, config):
+        """Evaluating of all found configuration options."""
+
+        super(CrTplConfiguration, self).eval_config(config)
+
+        if self.verbose > 1:
+            LOG.debug("Checking for unconfigured options ...")
+
+        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_purge_vm is None:
+            self.max_wait_for_purge_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
+
     # -------------------------------------------------------------------------
     def eval_config_section(self, config, section_name):
 
@@ -260,8 +280,6 @@ class CrTplConfiguration(BaseConfiguration):
             elif key.lower() == 'os_version':
                 self.os_version = value.strip()
 
-        self._eval_config_timeouts(config, section_name)
-
         return
 
     # -------------------------------------------------------------------------
@@ -328,6 +346,12 @@ class CrTplConfiguration(BaseConfiguration):
                     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)
+            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)
             elif key.lower() == 'max_wait_for_finish_install':
                 self._eval_timeout_value(
@@ -336,13 +360,6 @@ class CrTplConfiguration(BaseConfiguration):
                     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__":
index b9d67c621b83766d43d6cd076ad7b741ca3578a6..f94eda5873e8f63da36e21f635ca3b4024590292 100644 (file)
@@ -36,7 +36,7 @@ from fb_tools.vsphere.iface import VsphereVmInterface
 
 from .config import CrTplConfiguration
 
-__version__ = '1.1.0'
+__version__ = '1.2.0'
 
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
@@ -94,7 +94,6 @@ class CrTplHandler(BaseHandler):
         self.ssh_port = 22
         self.ssh_user = 'root'
         self.ssh_timeout = 30
-        self.max_wait_for_shutdown = 600
         self.rotate_only = False
         self.abort = False
         self.postinstall_errors = None
@@ -186,7 +185,7 @@ class CrTplHandler(BaseHandler):
                 else:
                     raise HandlerError("Could not find VM after creating.")
 
-            self.vsphere.poweron_vm(self.tpl_vm)
+            self.vsphere.poweron_vm(self.tpl_vm, max_wait=self.config.max_wait_for_poweron_vm)
             self.ts_start_install = time.time()
             self.wait_for_finish_install()
 
@@ -197,7 +196,7 @@ class CrTplHandler(BaseHandler):
             else:
                 self.post_install_tasks_ssh()
                 if self.postinstall_errors:
-                    self.vsphere.purge_vm(self.tpl_vm)
+                    self.vsphere.purge_vm(self.tpl_vm, max_wait=self.config.max_wait_for_purge_vm)
                     return 10
                 else:
                     self.poweroff_vm()
@@ -313,7 +312,7 @@ class CrTplHandler(BaseHandler):
 
         self.vsphere.create_vm(
             name=self.config.template_vm, vm_folder=tpl_vm_folder, vm_config_spec=vm_spec,
-            pool=self.cluster.resource_pool, max_wait=15)
+            pool=self.cluster.resource_pool, max_wait=self.config.max_wait_for_create_vm)
 
     # -------------------------------------------------------------------------
     def wait_for_finish_install(self):
@@ -707,7 +706,7 @@ class CrTplHandler(BaseHandler):
                 LOG.info("Template VM {h!r} was shutting down in {t:0.1f} seconds.".format(
                     h=self.config.template_vm, t=cur_diff))
                 return
-            if cur_diff >= self.max_wait_for_shutdown:
+            if cur_diff >= self.config.max_wait_for_shutdown_vm:
                 break
 
         print('', flush=True)