]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Using cache for validating VMs.
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 23 May 2024 13:37:42 +0000 (15:37 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 23 May 2024 13:37:42 +0000 (15:37 +0200)
example/stage-cb-rhel9-01.yaml
lib/create_terraform/handler/vmware.py

index 9e5ecf34730a77489f6d17c252dd71bea70c4df8..b2275329f8939e467cf138fbc6059bb2ffa8ff6a 100644 (file)
@@ -48,4 +48,9 @@ vms:
       - size: 100
     interfaces:
       - address_v4: 192.168.95.109
+  - name: stage-cb-node04.pixelpark.net
+    data_disks:
+      - size: 100
+    interfaces:
+      - address_v4: 192.168.95.113
 
index 1e5e7da5bbc9dd741657d1159facc95c7d205b3c..b648641f57030f0551103c10cebb40b91d162b83 100644 (file)
@@ -33,7 +33,7 @@ from ..slim_vm import SlimVm
 
 from ..xlate import XLATOR
 
-__version__ = '0.3.0'
+__version__ = '0.3.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -369,7 +369,6 @@ class CrTfHandlerVmwMixin():
                 self.eval_errors).format(n=self.eval_errors)
             raise ExpectedHandlerError(msg)
 
-        self.get_all_vms()
         self.validate_vms()
 
         LOG.info(_("Finished step {!r}.").format('validate-yaml'))
@@ -457,7 +456,7 @@ class CrTfHandlerVmwMixin():
 
         total_vms = 0
         slim_vms = []
-        slim_verbose = 2
+        slim_verbose = 3
 
         for vsphere_name in self.vsphere:
 
@@ -524,7 +523,7 @@ class CrTfHandlerVmwMixin():
                 re_vm = re.compile(pat_vm, re.IGNORECASE)
 
                 for vm in self.vsphere_vm_cache[vsphere_name]:
-                    if self.verbose >= 2:
+                    if self.verbose >= 3:
                         LOG.debug(_('Checking VM {n!r} against pattern {p!r} ...').format(
                             n=vm.name, p=pat_vm))
                     if re_vm.match(vm.name):
@@ -617,26 +616,29 @@ class CrTfHandlerVmwMixin():
             vsphere_name = vm.vsphere
             vsphere = self.vsphere[vsphere_name]
 
-            vm_paths = None
-            if vsphere_name in self.all_vms:
-                if vm.fqdn in self.all_vms[vsphere_name]:
-                    vm_paths = self.all_vms[vsphere_name][vm.fqdn]
+            existing_vm = None
+
+            if vsphere_name in self.vsphere_vm_cache:
+                for this_vm in self.vsphere_vm_cache[vsphere_name]:
+                    if this_vm.name == vm.fqdn:
+                        existing_vm = this_vm
+                        break
+
+            if existing_vm:
 
-            if vm_paths:
                 msg = _('[{m}]  - VM is already existing in VSphere {v!r}, path {p!r}.').format(
-                    m=self.colored('Existing', 'YELLOW'), v=vsphere_name, p=pp(vm_paths))
+                    m=self.colored('Existing', 'YELLOW'), v=vsphere_name, p=pp(existing_vm.path))
                 print(msg, end='', flush=True)
                 if self.verbose:
                     print()
 
-                vm_info = vsphere.get_vm(vm.fqdn, vsphere_name=vsphere_name, as_obj=True)
                 if self.verbose > 2:
-                    LOG.debug(_("VM info:") + "\n" + pp(vm_info.as_dict(bare=True)))
-                ds = vm_info.config_path_storage
+                    LOG.debug(_("VM info:") + "\n" + pp(existing_vm.as_dict(bare=True)))
+                ds = existing_vm.config_path_storage
                 LOG.debug(_("Datastore of VM {vm!r}: {ds!r}.").format(vm=vm.name, ds=ds))
                 vm.datastore = ds
                 vm.already_existing = True
-                self.existing_vms.append(vm_info)
+                self.existing_vms.append(existing_vm)
 
             else: