]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding and using handler method wait_for_finish_install()
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 11 Apr 2018 12:37:05 +0000 (14:37 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 11 Apr 2018 12:37:05 +0000 (14:37 +0200)
lib/cr_vmware_tpl/handler.py

index 69564c2d14c077c51df537e375749afae240e1fe..8d0afafee979aa02b2043a95acf8536107726f9f 100644 (file)
@@ -37,7 +37,7 @@ from .obj import PpBaseObject
 
 from .config import CrTplConfiguration
 
-__version__ = '0.5.1'
+__version__ = '0.6.1'
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
 
@@ -160,6 +160,11 @@ class CrTplHandler(PpBaseObject):
         self.tpl_network = None
         self.tpl_cluster = None
         self.tpl_vm = None
+        self.ts_start_install = None
+        self.ts_finish_install = None
+        self.initial_sleep = 60
+        self.interval_poll = 0.5
+        self.interval_dot = 2
 
         if initialized:
             self.initialized = True
@@ -206,6 +211,7 @@ class CrTplHandler(PpBaseObject):
                 raise HandlerError(
                     "Could not find VM after creating.")
             self.poweron_vm()
+            self.wait_for_finish_install()
         finally:
             LOG.debug("Disconnecting from vSphere host {h}:{p} ...".format(
                 h=self.config.vsphere_host, p=self.config.vsphere_port))
@@ -603,8 +609,28 @@ class CrTplHandler(PpBaseObject):
 
         task = self.tpl_vm.PowerOnVM_Task()
         self.wait_for_tasks([task])
+        self.ts_start_install = time.time()
         LOG.debug("VM {!r} successful powered on.".format(self.config.template_vm))
 
+    # -------------------------------------------------------------------------
+    def wait_for_finish_install(self):
+
+        LOG.info("Waiting for finishing installation ...")
+
+        LOG.debug("Waiting initially for {} seconds.")
+
+        cur_time = time.time()
+        cur_duration = cur_time - self.ts_start_install
+        last_dot = cur_time
+
+        while cur_duration <= self.initial_sleep:
+            time.sleep(self.interval_poll)
+            cur_time = time.time()
+            if (cur_time - last_dot) >= self.interval_dot:
+                sys.stdout.write('.')
+                sys.stdout.flush()
+                last_dot = cur_time
+            cur_duration = cur_time - self.ts_start_install
 
 # =============================================================================