]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Starting VM after creation
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 29 Mar 2018 13:46:02 +0000 (15:46 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 29 Mar 2018 13:46:02 +0000 (15:46 +0200)
lib/cr_vmware_tpl/handler.py

index ac0a8c48cabdde179d1aee36be71c8f41ea47aa7..3dd2096023feb217f9490a1c6c9ad25df112a257 100644 (file)
@@ -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))
+
 
 # =============================================================================