]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Retrieving MAC address of created template VM
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 9 Jun 2020 13:01:33 +0000 (15:01 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 9 Jun 2020 13:01:33 +0000 (15:01 +0200)
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/handler.py

index 24be0b4ed975595f506333c5c7eb8e41c02709c8..eea20fb0223c8f7d86fb0b5dbca73215db833334 100644 (file)
@@ -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
index cd9672a95bf8bd0839246512ae4794c4a5feb46a..e0af74e2819542a4a6b938a06226efe5f4c8b692 100644 (file)
@@ -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()