from .config import CrTplConfiguration
-__version__ = '0.7.2'
+__version__ = '0.7.3'
LOG = logging.getLogger(__name__)
TZ = pytz.timezone('Europe/Berlin')
self.wait_for_finish_install()
self.post_install_tasks_ssh()
self.poweroff_vm()
+ self.rename_and_change_vm()
finally:
LOG.debug("Disconnecting from vSphere host {h}:{p} ...".format(
h=self.config.vsphere_host, p=self.config.vsphere_port))
start_shutdown = time.time()
cur_diff = 0
vm.ShutdownGuest()
+ cur_time = start_shutdown
+ last_dot = cur_time
+ i = 0
LOG.debug("Waiting for successful shut down of VM ...")
+ if self.verbose <= 2:
+ print(' ==> ', end='', flush=True)
+
while guest_state.strip().lower() != "notrunning":
+
time.sleep(0.2)
+
cur_time = time.time()
cur_diff = cur_time - start_shutdown
+ if (self.verbose <= 2) and ((cur_time - last_dot) >= self.interval_dot):
+ print('.', end='', flush=True)
+ i += 1
+ if i >= 60:
+ print('', flush=True)
+ print(' ', end='', flush=True)
+ i = 0
+ last_dot = cur_time
+
vm = self.get_temp_tpl_vm()
guest_state = vm.guest.guestState
+ if self.verbose > 2:
+ LOG.debug("Still waiting for completing shutdown, current state is {!r}.".format(
+ guest_state))
if guest_state.strip().lower() == "notrunning":
+ 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))
return
if cur_diff >= self.max_wait_for_shutdown:
break
+ 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))
+ # -------------------------------------------------------------------------
+ def rename_and_change_vm(self):
+
+ LOG.info("Renaming VM {o!r} => {n!r} ...".format(
+ o=self.config.template_vm, n=self.config.template_name)
+
+ vm = self.get_temp_tpl_vm()
+ task = vm.Rename_Task(self.config.template_name)
+ self.wait_for_tasks([task])
+ LOG.debug("Successful renamed VM into {!r}.".format(self.config.template_name))
+
+ LOG.info("Changing VM {!r} into a VMWare template ...".format(self.config.template_name))
+ vm.MarkAsTemplate()
+ LOG.debug("Object {!r} is now a VMWare template.".format(self.config.template_name))
# =============================================================================