default_mac_address = '00:16:3e:54:ab:2b'
default_max_wait_for_finish_install = 60 * 60
default_max_nr_templates_stay = 4
+ default_vmware_cfg_version = 'vmx-13'
+ default_os_version = 'oracleLinux7_64Guest'
min_max_wait_for_finish_install = 3 * 60
max_max_wait_for_finish_install = 24 * 60 * 60
limit_max_nr_templates_stay = 100
self.mac_address = self.default_mac_address
self.max_wait_for_finish_install = self.default_max_wait_for_finish_install
self.max_nr_templates_stay = self.default_max_nr_templates_stay
+ self.vmware_cfg_version = self.default_vmware_cfg_version
+ self.os_version = self.default_os_version
self.excluded_datastores = []
v = value.strip().lower()
if v:
self.mac_address = v
+ elif key.lower() == 'vmware_cfg_version':
+ self.vmware_cfg_version = value.strip()
+ elif key.lower() == 'os_version':
+ self.os_version = value.strip()
elif key.lower() == 'max_wait_for_finish_install':
v = float(value)
if v < self.min_max_wait_for_finish_install:
self.tpl_vm_folder = None
self.tpl_data_store = None
self.tpl_network = None
- self.tpl_cluster = None
self.tpl_vm = None
self.ts_start_install = None
self.ts_finish_install = None
self.check_for_temp_tpl_vm(no_error=True)
self.select_data_store()
+ if self.rotate_only:
+ LOG.warn("Only executing of template rotating.")
+ else:
+ self.create_vm()
+
return 0
if self.rotate_only:
LOG.warn("Only executing of template rotating.")
else:
- self.check_network()
- self.create_vm()
+# self.check_network()
+# self.create_vm()
self.tpl_vm = self.get_temp_tpl_vm()
if not self.tpl_vm:
raise HandlerError(
return tpl_list
- # -------------------------------------------------------------------------
- def check_network(self):
-
- content = self.service_instance.RetrieveContent()
- dc = self.get_obj(content, [vim.Datacenter], self.config.dc)
-
- LOG.debug("Checking existence of network {!r} ...".format(self.config.network))
-
- net = None
- for child in dc.networkFolder.childEntity:
- net = self._get_network(child)
- if net:
- break
-
- if not net:
- raise NetworkNotExistingError(self.config.network)
- LOG.debug("Found network {!r}.".format(self.config.network))
- self.tpl_network = net
-
- # -------------------------------------------------------------------------
- def _get_network(self, child, depth=1):
-
- if hasattr(child, 'childEntity'):
- if depth > self.max_depth:
- return None
- for sub_child in child.childEntity:
- net = self._get_network(sub_child, depth + 1)
- if net:
- return net
- return None
-
- if isinstance(child, (vim.Network, vim.DistributedVirtualSwitch)):
- if child.summary.name == self.config.network:
- return child
-
- return None
-
# -------------------------------------------------------------------------
def select_data_store(self):
tstamp = datetime.datetime.now(tz=TZ).strftime('%Y-%m-%d_%H-%M')
datastore_path = (
- '[' + self.tpl_data_store.summary.name + '] template-' + tstamp + '/')
+ '[' + self.tpl_data_store.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))
memoryMB=self.config.ram_mb, memoryHotAddEnabled=True,
numCPUs=self.config.num_cpus, cpuHotAddEnabled=True, cpuHotRemoveEnabled=True,
files=vm_file_info,
- guestId='oracleLinux64Guest',
- version='vmx-11',
+ guestId=self.config.os_version,
+ version=self.config.vmware_cfg_version,
bootOptions=boot_opts,
)
- if self.verbose > 2:
+ if self.verbose > 1:
LOG.debug("Generated VM config:\n{}".format(pp(config)))
+ tpl_vm_folder = self.vsphere.get_vm_folder(self.config.folder)
+ if self.verbose > 1:
+ LOG.debug("VM-Folder object for template VM: {c} - {n!r}\n{t}".format(
+ c=tpl_vm_folder, n=tpl_vm_folder.name, t=pp(tpl_vm_folder.childType)))
+
+ if self.simulate:
+ LOG.info("Simulation mode - VM {!r} will not be created.".format(
+ self.config.template_vm))
+ return
+
LOG.debug("Start Creating VM ...")
- task = self.tpl_vm_folder.CreateVM_Task(
- config=config, pool=self.tpl_cluster.resourcePool)
+ task = tpl_vm_folder.CreateVM_Task(config=config, pool=self.cluster.resource_pool)
self.wait_for_tasks([task])