From cd4f0b93f2fe9e44138c02997cc822bcb13698a4 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 26 Mar 2018 15:38:48 +0200 Subject: [PATCH] Cleaning up definition of template VM --- lib/cr_vmware_tpl/handler.py | 39 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 946f746..ac0a8c4 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -16,9 +16,11 @@ import ssl import re import random import time +import datetime # Third party modules import six +import pytz from pyVmomi import vim, vmodl @@ -33,9 +35,9 @@ from .obj import PpBaseObject from .config import CrTplConfiguration -__version__ = '0.4.2' +__version__ = '0.4.3' LOG = logging.getLogger(__name__) - +TZ = pytz.timezone('Europe/Berlin') # ============================================================================= class HandlerError(PpError, RuntimeError): @@ -344,6 +346,9 @@ class CrTplHandler(PpBaseObject): if self.verbose > 1: LOG.debug("Temporary VM {!r} exists, raising TempVmExistsError.".format( self.config.template_vm)) + if self.verbose > 2: + LOG.debug("Info about Temporary VM {n!r}:\n{o}".format( + n=self.config.template_vm, o=pp(vm.config))) raise TempVmExistsError(self.config.template_vm) LOG.debug("Temporary VM {!r} does not exists, will be created.".format( @@ -474,12 +479,17 @@ class CrTplHandler(PpBaseObject): LOG.info("Creating VM {!r} ...".format(self.config.template_vm)) - datastore_path = '[' + self.tpl_data_store.summary.name + '] ' + self.config.template_vm + tstamp = datetime.datetime.now(tz=TZ).strftime('%Y-%m-%d_%H-%M') + + datastore_path = ( + '[' + self.tpl_data_store.summary.name + '] template-' + tstamp + '/') LOG.debug("Datastore path: {!r}".format(datastore_path)) + vm_path_name = datastore_path + self.config.template_vm + '.vmx' + LOG.debug("VM path name: {!r}".format(vm_path_name)) vm_file_info = vim.vm.FileInfo( - logDirectory=None, snapshotDirectory=None, - suspendDirectory=None, vmPathName=datastore_path) + logDirectory=datastore_path, snapshotDirectory=datastore_path, + suspendDirectory=datastore_path, vmPathName=vm_path_name) dev_changes = [] @@ -488,7 +498,6 @@ class CrTplHandler(PpBaseObject): scsi_ctr_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add scsi_ctr_spec.device = vim.vm.device.VirtualLsiLogicController() scsi_ctr_spec.device.key = 0 - #scsi_ctr_spec.device.controllerKey = 1000 scsi_ctr_spec.device.unitNumber = 1 scsi_ctr_spec.device.sharedBus = 'noSharing' controller = scsi_ctr_spec.device @@ -501,10 +510,9 @@ class CrTplHandler(PpBaseObject): disk_spec.device = vim.vm.device.VirtualDisk() disk_spec.device.backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo() disk_spec.device.backing.diskMode = 'persistent' - disk_spec.device.backing.fileName = '{ds}/{vm}-sda.vmdk'.format( - ds=datastore_path, vm=self.config.template_vm) - disk_spec.device.unitNumber = 1 - disk_spec.device.key = 1 + disk_spec.device.backing.fileName = '{}template-sda.vmdk'.format(datastore_path) + disk_spec.device.unitNumber = 0 + #disk_spec.device.key = 1 disk_spec.device.capacityInKB = self.config.data_size_kb disk_spec.device.controllerKey = controller.key @@ -526,7 +534,7 @@ class CrTplHandler(PpBaseObject): nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo() nic_spec.device.connectable.startConnected = True nic_spec.device.connectable.allowGuestControl = True - nic_spec.device.wakeOnLanEnabled = False + nic_spec.device.wakeOnLanEnabled = True nic_spec.device.addressType = 'assigned' nic_spec.device.macAddress = self.config.mac_address @@ -559,8 +567,13 @@ class CrTplHandler(PpBaseObject): name=self.config.template_vm, deviceChange=dev_changes, flags=vm_flags, extraConfig=extra_opts, memoryMB=self.config.ram_mb, memoryHotAddEnabled=True, - numCPUs=self.config.num_cpus, cpuHotAddEnabled=True, - files=vm_file_info) + numCPUs=self.config.num_cpus, cpuHotAddEnabled=True, cpuHotRemoveEnabled=True, + files=vm_file_info, + guestId = 'oracleLinux64Guest', + version = 'vmx-11', + #guestFullName='Oracle Enterprise Linux 7 (64 Bit)', + #alternateGuestName='OEL 7/64', + ) #files=vm_file_info, guestId='OracleLinux7_Guest') #files=vm_file_info, guestId='OracleLinux7_Guest', version='oel7-4') -- 2.39.5