From 948c034227246dfc707ce60be7f05dfd40ccaf01 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 1 Oct 2019 13:52:28 +0200 Subject: [PATCH] Adding and executing method assign_default_vmw_values() to class CreateTerraformHandler --- lib/cr_tf/handler.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/cr_tf/handler.py b/lib/cr_tf/handler.py index 4ccddaa..7b31fb4 100644 --- a/lib/cr_tf/handler.py +++ b/lib/cr_tf/handler.py @@ -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': -- 2.39.5