]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Integrating spinners
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 25 Jul 2024 15:46:41 +0000 (17:46 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 25 Jul 2024 15:46:41 +0000 (17:46 +0200)
lib/create_terraform/handler/__init__.py
lib/create_terraform/handler/vmware.py
locale/de_DE/LC_MESSAGES/create_terraform.po

index dff853a30b874897671990189d40cd3d8013c96b..74c3501c10dbd2c6822243c4a743a5a5f85156f2 100644 (file)
@@ -12,6 +12,7 @@ from __future__ import absolute_import, print_function
 import copy
 import os
 import logging
+import random
 import re
 import stat
 import sys
@@ -30,6 +31,7 @@ from fb_tools.common import pp, to_bool, to_str
 from fb_tools.errors import HandlerError, ExpectedHandlerError
 from fb_tools.handling_obj import HandlingObject, CalledProcessError
 from fb_tools.handler import BaseHandler
+from fb_tools.spinner import CycleList
 
 # Own modules
 from ..errors import ConsulApiNotFoundError
@@ -50,7 +52,7 @@ from ..errors import AbortExecution
 
 from ..xlate import XLATOR
 
-__version__ = '4.3.2'
+__version__ = '4.4.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -606,6 +608,20 @@ class CreateTerraformHandler(
         print(_("and enter: {}").format(self.colored('terraform apply', 'GREEN')))
         print()
 
+    # -------------------------------------------------------------------------
+    def get_spinner_name(self):
+        """
+        Return the name of a valid spinner.
+
+        If the configured spinner is 'random', then a random name from the list
+        of all available spinners will be returned.
+        """
+        if self.config and self.config.spinner != 'random':
+            return self.config.spinner
+
+        randomizer = random.SystemRandom()
+        return randomizer.choice(list(CycleList.keys()))
+
     # -------------------------------------------------------------------------
     def exit(self, retval=-1, msg=None):
         """Exit the current application."""
index ed8fa7c77fbf5ec8ab1c7f46346030955276beb2..d2fe83dc102a90fc21beea4ead29eb076a45bdce 100644 (file)
@@ -19,10 +19,13 @@ from operator import attrgetter
 
 # Third party modules
 from fb_tools.common import pp
-from fb_tools.errors import HandlerError, ExpectedHandlerError
-from fb_vmware.errors import VSphereExpectedError
+from fb_tools.errors import ExpectedHandlerError
+from fb_tools.errors import HandlerError
+from fb_tools.spinner import Spinner
+
 from fb_vmware.config import VSPhereConfigInfo
 from fb_vmware.connect import VsphereConnection
+from fb_vmware.errors import VSphereExpectedError
 
 # Own modules
 from ..errors import AbortExecution
@@ -31,7 +34,7 @@ from ..slim_vm import SlimVm
 
 from ..xlate import XLATOR
 
-__version__ = '1.1.0'
+__version__ = '1.2.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -252,10 +255,17 @@ class CrTfHandlerVmwMixin():
             self.incr_verbosity()
 
         nr_total = 0
+        spinner_name = self.get_spinner_name()
 
         for vsphere_name in self.vsphere:
-            LOG.debug(_("Searching for datastores in VSPhere {!r} ...").format(vsphere_name))
-            self.vsphere[vsphere_name].get_datastores()
+            msg = _('Searching for datastores in VSPhere {!r} ...').format(vsphere_name)
+            if self.verbose:
+                LOG.debug(msg)
+                self.vsphere[vsphere_name].get_datastores()
+            else:
+                with Spinner(msg + ' ', spinner_name):
+                    self.vsphere[vsphere_name].get_datastores()
+
             nr_total += len(self.vsphere[vsphere_name].datastores.keys())
 
         if nr_total:
@@ -272,14 +282,19 @@ class CrTfHandlerVmwMixin():
     def exec_vmw_ds_clusters(self):
 
         nr_total = 0
+        spinner_name = self.get_spinner_name()
 
         if self.stop_at_step == 'vmw-ds-clusters':
             self.incr_verbosity()
 
         for vsphere_name in self.vsphere:
-            LOG.debug(_("Searching for datastore clusters in VSPhere {!r} ...").format(
-                vsphere_name))
-            self.vsphere[vsphere_name].get_ds_clusters()
+            msg = _("Searching for datastore clusters in VSPhere {!r} ...").format(vsphere_name)
+            if self.verbose:
+                LOG.debug(msg)
+                self.vsphere[vsphere_name].get_ds_clusters()
+            else:
+                with Spinner(msg + ' ', spinner_name):
+                    self.vsphere[vsphere_name].get_ds_clusters()
             nr_total += len(self.vsphere[vsphere_name].ds_clusters.keys())
 
         if nr_total:
@@ -301,9 +316,17 @@ class CrTfHandlerVmwMixin():
         if self.stop_at_step == 'vmw-networks':
             self.incr_verbosity()
 
+        spinner_name = self.get_spinner_name()
+
         for vsphere_name in self.vsphere:
-            LOG.debug(_("Searching for networks in VSPhere {!r} ...").format(vsphere_name))
-            self.vsphere[vsphere_name].get_networks()
+            msg = _("Searching for networks in VSPhere {!r} ...").format(vsphere_name)
+            if self.verbose:
+                LOG.debug(msg)
+                self.vsphere[vsphere_name].get_networks()
+            else:
+                with Spinner(msg + ' ', spinner_name):
+                    self.vsphere[vsphere_name].get_networks()
+
             if self.eval_errors:
                 msg = ngettext(
                     "Found one error in exploring vSphere {v!r} resources.",
@@ -438,14 +461,26 @@ class CrTfHandlerVmwMixin():
         total_vms = 0
         slim_vms = []
         slim_verbose = 3
+        re_vm = re.compile(r'.*')
+
+        spinner_name = self.get_spinner_name()
+
+        def _do_get_vms(vsphere_name):
+            return self.vsphere[vsphere_name].get_vms(re_vm, as_obj=True, stop_at_found=False)
 
         for vsphere_name in self.vsphere:
 
             if vsphere_name not in self.vsphere_vm_cache:
                 self.vsphere_vm_cache[vsphere_name] = []
 
-            re_vm = re.compile(r'.*')
-            vm_list = self.vsphere[vsphere_name].get_vms(re_vm, as_obj=True, stop_at_found=False)
+            msg =  _('Getting all VSPhere VMs and templates from {!r} ...').format(vsphere_name)
+
+            if self.verbose:
+                LOG.debug(msg)
+                vm_list = _do_get_vms(vsphere_name)
+            else:
+                with Spinner(msg + ' ', spinner_name):
+                    vm_list = _do_get_vms(vsphere_name)
 
             for vm in vm_list:
                 self.vsphere_vm_cache[vsphere_name].append(vm)
index d70cf31a4795ff9645959c250e5fa8807da0a778..1c8367c982edc6fa441c9e7e65ba77f1fdac53b8 100644 (file)
@@ -1331,7 +1331,7 @@ msgstr[1] "Insgesamt {n} Fehler bei der Validierung der VM-Netzwerkschnittstelle
 
 #: lib/create_terraform/handler/vmware.py:443
 msgid "Exploring and caching all vSphere VMs and templates ..."
-msgstr "Ermittle und cache alle vSpheres VMs und -Vorlagen …"
+msgstr "Ermittle und cache alle vSphere VMs und -Vorlagen …"
 
 #: lib/create_terraform/handler/vmware.py:464
 msgid "Found one VM or template in vSphere."