]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Adding and executing method assign_default_vmw_values() to class CreateTerraformHandler
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 1 Oct 2019 11:52:28 +0000 (13:52 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 1 Oct 2019 11:52:28 +0000 (13:52 +0200)
lib/cr_tf/handler.py

index 4ccddaa2e41de745da871128ee2f68df9de1f01c..7b31fb4ac087949639fc73ca716dcf65fd6f591f 100644 (file)
@@ -59,7 +59,7 @@ from .terraform.disk import TerraformDisk
 
 from .xlate import XLATOR
 
-__version__ = '2.9.2'
+__version__ = '2.9.3'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -459,6 +459,7 @@ class CreateTerraformHandler(BaseHandler):
             LOG.info(_("Initialising VSPhere handlers."))
             self.init_vspheres()
             self.exec_collect_folders(yaml_file)
+            self.assign_default_vmw_values()
 
             print()
             LOG.info(_("Retrieving information from vSphere."))
@@ -659,13 +660,39 @@ class CreateTerraformHandler(BaseHandler):
             except VSphereExpectedError as e:
                 raise ExpectedHandlerError(str(e))
 
+    # -------------------------------------------------------------------------·
+    def assign_default_vmw_values(self):
+        """Assigning not defined templates and clusters of VMs by their
+            appropriate default values."""
+
+        LOG.debug(_(
+            "Assigning not defined templates and clusters of VMs by their "
+            "appropriate default values."))
+
+        for vm in self.vms:
+
+            if not vm.cluster:
+                cl = self.config.vsphere[vm.vsphere].cluster
+                if self.verbose > 1:
+                    LOG.debug(_("Setting cluster of {n!r} to {c!r} ...").format(
+                        n=vm.name, c=cl))
+                vm.cluster = cl
+
+            if not vm.vm_template:
+                tpl = self.config.vsphere[vm.vsphere].template_name
+                if self.verbose > 1:
+                    LOG.debug(_("Setting template of {n!r} to {t!r} ...").format(
+                        n=vm.name, t=tpl))
+                vm.vm_template = tpl
+
     # -------------------------------------------------------------------------·
     def exec_vmw_clusters(self):
 
         if self.stop_at_step == 'vmw-clusters':
             self.incr_verbosity()
 
-        self.vsphere.get_clusters()
+        for vname in self.vsphere:
+            self.vsphere[vname].get_clusters()
 
         LOG.info(_("Finished step {!r}.").format('vmw-clusters'))
         if self.stop_at_step == 'vmw-clusters':