]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Last actions on the living VM.
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 22 Jun 2020 15:40:49 +0000 (17:40 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 22 Jun 2020 15:40:49 +0000 (17:40 +0200)
lib/cr_vmware_tpl/handler.py

index 951a4b7b38c8f04d512269f6a8d96325583ec2a1..75c7a14cd95b563fba348971d4e96e1b88bf40bd 100644 (file)
@@ -42,7 +42,7 @@ from .cobbler import CobblerError, Cobbler
 
 from .xlate import XLATOR
 
-__version__ = '1.6.8'
+__version__ = '1.7.1'
 
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
@@ -303,13 +303,13 @@ class CrTplHandler(BaseHandler):
             if self.abort:
                 LOG.warn(_("Aborting after creation of template VM."))
                 LOG.warn(_("You are responsible yourself to cleaning up the VM!!!"))
-#            else:
-#                self.post_install_tasks_ssh()
-#                if self.postinstall_errors:
-#                    self.vsphere.purge_vm(self.tpl_vm, max_wait=self.config.max_wait_for_purge_vm)
-#                    return 10
-#                else:
-#                    self.poweroff_vm()
+            else:
+                self.post_install_tasks_ssh()
+                if self.postinstall_errors:
+                    self.vsphere.purge_vm(self.tpl_vm, max_wait=self.config.max_wait_for_purge_vm)
+                    return 10
+                else:
+                    self.poweroff_vm()
 #                    self.change_mac_address()
 
         return 0
@@ -654,47 +654,30 @@ class CrTplHandler(BaseHandler):
         printf "Current host FQDN: "
         hostname -f
 
+        echo
+        echo "-----------------------------------------------------------"
         if [ -f /root/original-ks.cfg ] ; then
-            echo
-            echo "Kickstart configuration:"
-            echo
-            echo "-----------------------------------------------------------"
-            cat /root/original-ks.cfg
-            echo "-----------------------------------------------------------"
-            echo
-            echo "Removing /root/original-ks.cfg ..."
-            rm -v /root/original-ks.cfg
+            echo "Moving /root/original-ks.cfg => /var/log/anaconda/ ..."
+            mv -v /root/original-ks.cfg /var/log/anaconda/
         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
+        echo
+        echo "-----------------------------------------------------------"
+        if [ -f /root/anaconda-ks.cfg ] ; then
+            echo "Moving /root/anaconda-ks.cfg => /var/log/anaconda/ ..."
+            mv -v /root/anaconda-ks.cfg /var/log/anaconda/
         else
-            echo
-            echo "-----------------------------------------------------------"
             echo "File /root/anakonda-ks.cfg not found."
         fi
 
-        if [ -f /var/log/post-install.log ] ; then
-            echo
-            echo "Post install log:"
-            echo
-            echo "-----------------------------------------------------------"
-            cat /var/log/post-install.log
-            echo "-----------------------------------------------------------"
-            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
+        for f in /var/log/boot.log /var/log/cron /var/log/dnf*.log /var/log/hawkey.log /var/log/messages /var/log/secure /var/log/wtmp /var/log/vmware-*.log* ; do
+            if [ -f "${f}" ] ; then
+                echo "Truncating ${f} ..."
+                cp /dev/null "${f}"
+            fi
+        done
 
         """)
 
@@ -708,9 +691,9 @@ class CrTplHandler(BaseHandler):
             ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
 
             LOG.debug(_("Connecting to {h!r}, port {p} as {u!r} per SSH ...").format(
-                h=self.config.template_vm, p=self.ssh_port, u=self.ssh_user))
+                h=self.tpl_ip, p=self.ssh_port, u=self.ssh_user))
             ssh.connect(
-                self.config.template_vm, port=self.ssh_port, timeout=self.ssh_timeout,
+                self.tpl_ip, port=self.ssh_port, timeout=self.ssh_timeout,
                 username=self.ssh_user, key_filename=self.private_ssh_key)
 
             LOG.debug(_("Executing postinstall tasks ..."))
@@ -755,7 +738,7 @@ class CrTplHandler(BaseHandler):
             cur_duration = cur_time - start_waiting
         print('', flush=True)
 
-        LOG.info(_("Last actions before powering off VM {!r} ...").format(self.config.template_vm))
+        LOG.info(_("Last actions before powering off VM {!r} ...").format(self.tpl_ip))
 
         ssh = None
 
@@ -796,9 +779,9 @@ class CrTplHandler(BaseHandler):
         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=power_state))
+                    h=self.tpl_ip, s=power_state))
 
-        LOG.info(_("Powering off VM {!r} per SSH ...").format(self.config.template_vm))
+        LOG.info(_("Powering off VM {!r} per SSH ...").format(self.tpl_ip))
 
         try:
 
@@ -810,9 +793,9 @@ class CrTplHandler(BaseHandler):
             ssh.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
 
             LOG.debug(_("Connecting to {h!r}, port {p} as {u!r} per SSH ...").format(
-                h=self.config.template_vm, p=self.ssh_port, u=self.ssh_user))
+                h=self.tpl_ip, p=self.ssh_port, u=self.ssh_user))
             ssh.connect(
-                self.config.template_vm, port=self.ssh_port, timeout=self.ssh_timeout,
+                self.tpl_ip, port=self.ssh_port, timeout=self.ssh_timeout,
                 username=self.ssh_user, key_filename=self.private_ssh_key)
 
             LOG.debug(_("Executing {} ...").format('poweroff'))
@@ -872,7 +855,7 @@ class CrTplHandler(BaseHandler):
                 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))
+                    h=self.tpl_ip, t=cur_diff))
                 return
             if cur_diff >= self.config.max_wait_for_shutdown_vm:
                 break
@@ -880,7 +863,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=power_state))
+                h=self.tpl_ip, t=cur_diff, s=power_state))
 
     # -------------------------------------------------------------------------
     def change_mac_address(self):