From c579540460e3a86525b4839df90baa4b484216e8 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 9 Jun 2020 15:01:33 +0200 Subject: [PATCH] Retrieving MAC address of created template VM --- lib/cr_vmware_tpl/config.py | 4 ++-- lib/cr_vmware_tpl/handler.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 24be0b4..eea20fb 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -62,8 +62,8 @@ class CrTplConfiguration(BaseConfiguration): default_max_wait_for_shutdown = 600 default_max_wait_for_finish_install = 60 * 60 default_max_nr_templates_stay = 4 - default_vmware_cfg_version = 'vmx-14' - default_os_version = 'oracleLinux7_64Guest' + default_vmware_cfg_version = 'vmx-15' + default_os_version = 'centos8_64Guest' min_max_wait_for_finish_general = 2 min_max_wait_for_finish_install = 3 * 60 max_max_wait_for_finish_general = 60 * 60 diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index cd9672a..e0af74e 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -22,6 +22,8 @@ import signal import pytz import paramiko +from pyVmomi import vim + # Own modules from fb_tools.common import pp, to_str @@ -40,7 +42,7 @@ from .cobbler import CobblerError, Cobbler from .xlate import XLATOR -__version__ = '1.5.3' +__version__ = '1.5.4' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -98,6 +100,7 @@ class CrTplHandler(BaseHandler): self.tpl_network = None self.tpl_vm = None self.tpl_vm_hostname = None + self.tpl_macaddress = None self.ts_start_install = None self.ts_finish_install = None self.initial_sleep = 60 @@ -250,12 +253,28 @@ class CrTplHandler(BaseHandler): else: self.create_vm() self.tpl_vm = self.vsphere.get_vm(self.tpl_vm_fqdn, as_vmw_obj=True) - if not self.tpl_vm: + if self.tpl_vm: + LOG.debug(_("Created VM as {cls}: {vm!r}").format( + cls=self.tpl_vm.__class__.__name__, vm=self.tpl_vm)) + for device in self.tpl_vm.config.hardware.device: + if isinstance(device, vim.vm.device.VirtualEthernetCard): + self.tpl_macaddress = device.macAddress + LOG.debug(_("Found Ethernet card as {}.").format( + device.__class__.__name__)) + if self.verbose > 2: + LOG.debug(_("Found Ethernet card:") + "\n{}".format(device)) + if not self.tpl_macaddress: + msg = _("Did not found MAC address of ethernet card.") + raise HandlerError(msg) + else: if self.simulate: LOG.warn(_("Simulation mode - VM not created in real.")) + self.tpl_macaddress = self.config.default_mac_address else: raise HandlerError(_("Could not find VM after creating.")) + LOG.info(_("Using MAC address of template VM: {!r}").format(self.tpl_macaddress)) + # self.vsphere.poweron_vm(self.tpl_vm, max_wait=self.config.max_wait_for_poweron_vm) # self.ts_start_install = time.time() # self.wait_for_finish_install() -- 2.39.5