From 3261809501745a92f7349c2229f67006b1b7eea6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 9 Jan 2024 13:05:18 +0100 Subject: [PATCH] Error if no valif VMs found in YAML file --- lib/cr_tf/app.py | 8 +++++++- lib/cr_tf/handler/read.py | 6 +++++- lib/cr_tf/handler/vmware.py | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/cr_tf/app.py b/lib/cr_tf/app.py index 87832c6..999319b 100644 --- a/lib/cr_tf/app.py +++ b/lib/cr_tf/app.py @@ -42,7 +42,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__ from .xlate import __mo_file__ as __xlate_mo_file__ from .xlate import XLATOR, LOCALE_DIR, DOMAIN -__version__ = '1.3.2' +__version__ = '1.3.3' LOG = logging.getLogger(__name__) SIGNAL_NAMES = { @@ -540,6 +540,12 @@ class CrTfApplication(BaseApplication): if not self.handler.vsphere_password: + # Get the name of the first (and hopefully only) VSphere + vname = None + for vn in self.handler.vsphere.keys(): + vname = vn + break + if need_nl: print('') prompt = self.colored(_("User password of {!r}").format( diff --git a/lib/cr_tf/handler/read.py b/lib/cr_tf/handler/read.py index 3cf9ff4..cb4f667 100644 --- a/lib/cr_tf/handler/read.py +++ b/lib/cr_tf/handler/read.py @@ -25,7 +25,7 @@ from ..terraform.vm import TerraformVm from ..xlate import XLATOR -__version__ = '0.1.0' +__version__ = '0.1.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -51,6 +51,10 @@ class CrTfHandlerReadMixin(): self.eval_errors).format(n=self.eval_errors, f=str(yaml_file)) raise ExpectedHandlerError(msg) + if not self.vms: + msg = _("Did not found any VMs to deploy in file {!r}.").format(str(yaml_file)) + raise ExpectedHandlerError(msg) + LOG.info(_("Finished step {!r}.").format('read-yaml')) if self.stop_at_step == 'read-yaml': raise AbortExecution('read-yaml') diff --git a/lib/cr_tf/handler/vmware.py b/lib/cr_tf/handler/vmware.py index 979a6ac..da1d59e 100644 --- a/lib/cr_tf/handler/vmware.py +++ b/lib/cr_tf/handler/vmware.py @@ -31,7 +31,7 @@ from ..errors import AbortExecution from ..xlate import XLATOR -__version__ = '0.1.2' +__version__ = '0.1.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -102,6 +102,7 @@ class CrTfHandlerVmwMixin(): if self.stop_at_step == 'vmw-init': self.incr_verbosity() + LOG.debug(_("Initialize VSPhere ...")) # Test for multiple VSphere references found_vspheres = [] for vm in self.vms: @@ -131,13 +132,17 @@ class CrTfHandlerVmwMixin(): if vm.vsphere in self.vsphere: continue vname = vm.vsphere + LOG.debug(_("Initializing VSphere {!r} ...").format(vname)) if vname not in self.config.vsphere: msg = _("VSPhere {!r} not defined in configuration.").format(vname) raise ExpectedHandlerError(msg) if not self.vsphere_user and self.config.vsphere[vname].user: + LOG.debug(_("Setting {st} to {what!r}.").format( + st='handler.vsphere_user', what=self.config.vsphere[vname].user)) self.vsphere_user = self.config.vsphere[vname].user if not self.vsphere_password and self.config.vsphere[vname].password: + LOG.debug(_("Setting {}.").format('handler.vsphere_password')) self.vsphere_password = self.config.vsphere[vname].password try: -- 2.39.5