]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Finishing creating template
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 2 Nov 2018 13:43:26 +0000 (14:43 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 2 Nov 2018 13:43:26 +0000 (14:43 +0100)
lib/cr_vmware_tpl/handler.py

index 2b8451c5ce4aca0a453eb8d53ea9b60b743e8a8e..ffd2ec2a67839855df04a5626c3b3170c1b1e0cb 100644 (file)
@@ -45,7 +45,7 @@ from fb_tools.vsphere.iface import VsphereVmInterface
 
 from .config import CrTplConfiguration
 
-__version__ = '0.10.10'
+__version__ = '0.10.11'
 
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
@@ -502,12 +502,20 @@ class CrTplHandler(BaseHandler):
             echo
             echo "Removing /root/original-ks.cfg ..."
             rm -v /root/original-ks.cfg
+        else
+            echo
+            echo "-----------------------------------------------------------"
+            echo "File /root/original-ks.cfg not found."
         fi
 
         if [ -v /root/anaconda-ks.cfg ] ; then
             echo
             echo "Removing /root/anaconda-ks.cfg ..."
             rm -v /root/anaconda-ks.cfg
+        else
+            echo
+            echo "-----------------------------------------------------------"
+            echo "File /root/anakonda-ks.cfg not found."
         fi
 
         if [ -f /var/log/post-install.log ] ; then
@@ -520,6 +528,10 @@ class CrTplHandler(BaseHandler):
             echo
             echo "Removing /var/log/post-install.log ..."
             rm -v /var/log/post-install.log
+        else
+            echo
+            echo "-----------------------------------------------------------"
+            echo "File /var/log/post-install.log not found."
         fi
 
         """)
@@ -560,7 +572,7 @@ class CrTplHandler(BaseHandler):
 
         wait_for_shutdown = 15
 
-        LOG.debug("Waiting for {} seconds for shutting down:".format(wait_for_shutdown))
+        LOG.info("Waiting for {} seconds before shutting down:".format(wait_for_shutdown))
         print('   ==> ', end='', flush=True)
 
         start_waiting = time.time()
@@ -568,12 +580,16 @@ class CrTplHandler(BaseHandler):
         cur_duration = 0
         last_dot = cur_time
 
+        i = 0
         while cur_duration <= wait_for_shutdown:
             time.sleep(0.1)
             cur_time = time.time()
             if (cur_time - last_dot) >= 1:
                 print('.', end='', flush=True)
                 last_dot = cur_time
+                i += 1
+                if not i % 60:
+                    print('\n       ', end='', flush=True)
             cur_duration = cur_time - start_waiting
         print('', flush=True)
 
@@ -609,16 +625,16 @@ class CrTplHandler(BaseHandler):
         """)
 
         vm = self.get_temp_tpl_vm()
-        guest_state = vm.guest.guestState
-        LOG.debug("Current state of template VM is {!r}".format(guest_state))
-        if guest_state.strip().lower() == "notrunning":
+        power_state = vm.runtime.powerState
+        LOG.debug("Current state of template VM is {!r}".format(power_state))
+        if power_state.strip().lower() == "poweredoff":
             LOG.info("Template VM is already shut off.")
             return
 
-        if guest_state.strip().lower() != "running":
+        if power_state.strip().lower() != "poweredon":
             raise ExpectedHandlerError(
                 "Cannot shut down VM {h!r}, is currently in state {s!r}.".format(
-                    h=self.config.template_vm, s=guest_state))
+                    h=self.config.template_vm, s=power_state))
 
         LOG.info("Powering off VM {!r} per SSH ...".format(self.config.template_vm))
 
@@ -662,13 +678,15 @@ class CrTplHandler(BaseHandler):
         LOG.debug("Waiting for successful shut down of VM ...")
         if self.verbose <= 3:
             print('   ==> ', end='', flush=True)
+        if self.verbose > 3:
+            LOG.debug("Current state of template VM is {!r}".format(power_state))
 
-        while guest_state.strip().lower() != "notrunning":
+        while power_state.strip().lower() != "poweredoff":
 
             time.sleep(0.2)
 
             dot = '.'
-            if guest_state.lower().strip() != 'running':
+            if power_state.lower().strip() != 'poweredon':
                 dot = 'S'
 
             cur_time = time.time()
@@ -683,11 +701,11 @@ class CrTplHandler(BaseHandler):
                 last_dot = cur_time
 
             vm = self.get_temp_tpl_vm()
-            guest_state = vm.guest.guestState
+            power_state = vm.runtime.powerState
             if self.verbose > 3:
                 LOG.debug("Still waiting for completing shutdown, current state is {!r}.".format(
-                    guest_state))
-            if guest_state.strip().lower() == "notrunning":
+                    power_state))
+            if power_state.strip().lower() == "poweredoff":
                 print('', flush=True)
                 LOG.info("Template VM {h!r} was shutting down in {t:0.1f} seconds.".format(
                     h=self.config.template_vm, t=cur_diff))
@@ -698,7 +716,7 @@ class CrTplHandler(BaseHandler):
         print('', flush=True)
         raise ExpectedHandlerError(
             "VM {h!r} was not shut down after {t:0.1f} seconds, current state is {s!r}.".format(
-                h=self.config.template_vm, t=cur_diff, s=guest_state))
+                h=self.config.template_vm, t=cur_diff, s=power_state))
 
     # -------------------------------------------------------------------------
     def change_mac_address(self):