import re
import random
import time
+import datetime
# Third party modules
import six
+import pytz
from pyVmomi import vim, vmodl
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):
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(
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 = []
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
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
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
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')