From add8db57c58310bc80bb991d94cfcbc24c96e313 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 29 Mar 2018 15:46:02 +0200 Subject: [PATCH] Starting VM after creation --- lib/cr_vmware_tpl/handler.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index ac0a8c4..3dd2096 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -35,7 +35,7 @@ from .obj import PpBaseObject from .config import CrTplConfiguration -__version__ = '0.4.3' +__version__ = '0.4.4' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -157,6 +157,7 @@ class CrTplHandler(PpBaseObject): self.tpl_data_store = None self.tpl_network = None self.tpl_cluster = None + self.tpl_vm = None if initialized: self.initialized = True @@ -198,6 +199,11 @@ class CrTplHandler(PpBaseObject): self.select_data_store() self.check_network() self.create_vm() + self.tpl_vm = self.get_temp_tpl_vm() + if not self.tpl_vm: + raise HandlerError( + "Could not find VM after creating.") + self.poweron_vm() finally: LOG.debug("Disconnecting from vSphere host {h}:{p} ...".format( h=self.config.vsphere_host, p=self.config.vsphere_port)) @@ -365,6 +371,8 @@ class CrTplHandler(PpBaseObject): if vm: return vm + return None + # ------------------------------------------------------------------------- def _get_temp_tpl_vm(self, child, depth=1): @@ -586,6 +594,15 @@ class CrTplHandler(PpBaseObject): self.wait_for_tasks([task]) + # ------------------------------------------------------------------------- + def poweron_vm(self): + + LOG.info("Powering on VM {!r} ...".format(self.config.template_vm)) + + task = self.tpl_vm.PowerOnVM_Task() + self.wait_for_tasks([task]) + LOG.debug("VM {!r} successful powered on.".format(self.config.template_vm)) + # ============================================================================= -- 2.39.5