From fe832ed7cf946f621a67fb2f896e0865b1acb677 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 11 Apr 2018 14:37:05 +0200 Subject: [PATCH] Adding and using handler method wait_for_finish_install() --- lib/cr_vmware_tpl/handler.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 69564c2..8d0afaf 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -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 # ============================================================================= -- 2.39.5