]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Raising on different VSphere definitions
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 5 Nov 2019 14:52:40 +0000 (15:52 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 5 Nov 2019 14:52:40 +0000 (15:52 +0100)
lib/cr_tf/handler.py

index 7b2ca8ad7744a63d70808dc220974ede5f9aa4f4..de43fdf355a4bdee0ce421cf11f3eab1f66c62bf 100644 (file)
@@ -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'))