From: Frank Brehm Date: Tue, 5 Nov 2019 14:52:40 +0000 (+0100) Subject: Raising on different VSphere definitions X-Git-Tag: 1.3.4~17 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=42057bd71b813cb8a0726a020b21d74de6e7205a;p=pixelpark%2Fcreate-terraform.git Raising on different VSphere definitions --- diff --git a/lib/cr_tf/handler.py b/lib/cr_tf/handler.py index 7b2ca8a..de43fdf 100644 --- a/lib/cr_tf/handler.py +++ b/lib/cr_tf/handler.py @@ -61,7 +61,7 @@ from .terraform.disk import TerraformDisk from .xlate import XLATOR -__version__ = '3.0.1' +__version__ = '3.0.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -460,7 +460,7 @@ class CreateTerraformHandler(BaseHandler): print() LOG.info(_("Initialising VSPhere handlers.")) - self.init_vspheres() + self.init_vspheres(yaml_file) self.exec_collect_folders(yaml_file) self.assign_default_vmw_values() @@ -607,11 +607,27 @@ class CreateTerraformHandler(BaseHandler): raise AbortExecution('pdns-zones') # -------------------------------------------------------------------------· - def init_vspheres(self): + def init_vspheres(self, yaml_file): if self.stop_at_step == 'vmw-init': self.incr_verbosity() + # Test for multiple VSphere references + found_vspheres = [] + for vm in self.vms: + vname = vm.vsphere + if vname not in found_vspheres: + found_vspheres.append(vname) + if len(found_vspheres) > 1: + msg = _( + "There is only one, unique VSPhere definition allowed in a project file. " + "In {f!r} were found {nr} different VSPhere definitions:").format( + f=yaml_file, nr=len(found_vspheres)) + msg += '\n' + for vname in sorted(found_vspheres, key=string.lower): + msg += ' * {!r}'.format(vname) + raise ExpectedHandlerError(msg) + self._init_vspheres() LOG.info(_("Finished step {!r}.").format('vmw-init'))