]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Asking for vSphere user credentials, if they are not configured
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 6 Sep 2021 14:15:32 +0000 (16:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 6 Sep 2021 14:15:32 +0000 (16:15 +0200)
lib/cr_tf/app.py
lib/cr_tf/handler.py

index 7836f8e4a86cdc3fcbbc2027519c1806ba2b1b28..d597af4db2240de4105230831a3a401b060f1af0 100644 (file)
@@ -29,6 +29,7 @@ from fb_tools.common import pp
 from fb_tools.app import BaseApplication
 
 from fb_tools.errors import ExpectedHandlerError, CommandNotFoundError
+from fb_tools.errors import TerraformHandlerError, TerraformVSphereError
 
 from fb_tools.config import ConfigError
 
@@ -45,7 +46,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.1.6'
+__version__ = '1.1.7'
 LOG = logging.getLogger(__name__)
 
 SIGNAL_NAMES = {
@@ -326,9 +327,6 @@ class CrTfApplication(BaseApplication):
             simulate=self.simulate, force=self.force, config=self.config,
             terminal_has_colors=self.terminal_has_colors)
 
-        self.handler.get_secret = self.get_secret
-        self.handler.exit = self.exit
-
         if self.args.stop_after:
             self.handler.stop_at_step = self.args.stop_after
 
@@ -486,12 +484,52 @@ class CrTfApplication(BaseApplication):
             a=self.appname, v=__pkg_version__))
 
         try:
-            self.handler(self.yaml_file)
+            if self.handler.first_call(yaml_file):
+                self.verify_vsphere_credentials()
+                self.handler(self.yaml_file)
         except ExpectedHandlerError as e:
             self.handler = None
             self.handle_error(str(e), _("Create Terraform environment"))
             self.exit(5)
 
+    # -------------------------------------------------------------------------
+    def verify_vsphere_credentials(self):
+
+        if not self.handler:
+            raise TerraformHandlerError(_("No handler object available."))
+
+        if not self.handler.vsphere_user:
+
+            msg = '\n' + _("Please input the {}:").format(self.colored(
+                    _('vSphere user name'), 'AQUA'))
+            print(msg)
+            self.handler.vsphere_user = input(_('vSphere user name') + ': ')
+            if not self.handler.vsphere_user:
+                msg = _("No {} given.").format(_('vSphere user name'))
+                raise ExpectedHandlerError(msg)
+
+            for vname in self.handler.vsphere.keys():
+                LOG.debug(_("Setting user for vSphere {vs!r} to {usr!r}.").format(
+                    vs=vname, usr=self.handler.vsphere_user))
+                # Dirty, but else a change of fb_tools would be necessary (later)
+                self.handler.vsphere[vname]._user = self.handler.vsphere_user
+
+        if not self.handler.vsphere_password:
+
+            prompt = _("User password")
+            item = _('Password for user {u!r} of vSphere {n} on {h!r}').format(
+                    u=vsphere_user, n=vname, h=self.config.vsphere[vname].host)
+            self.handler.vsphere_password = self.get_secret(prompt=prompt, item_name=item)
+            if not self.handler.vsphere_password:
+                msg = _("No {} given.").format(_('password of vSphere user'))
+                raise ExpectedHandlerError(msg)
+
+            for vname in self.handler.vsphere.keys():
+                LOG.debug(_("Setting passwort of vSphere {vs!r} user {usr!r}.").format(
+                    vs=vname, usr=self.handler.vsphere_user))
+                # Dirty, but else a change of fb_tools would be necessary (later)
+                self.handler.vsphere[vname]._password = self.handler.vsphere_password
+
     # -------------------------------------------------------------------------
     def post_run(self):
         """
index ed45dc4564ac976be5306fe365b7204d4275fa22..551b04a725c5f9fee8ccd0090bf8665b39f0cddc 100644 (file)
@@ -67,7 +67,7 @@ from .terraform.disk import TerraformDisk
 
 from .xlate import XLATOR
 
-__version__ = '3.5.3'
+__version__ = '3.5.4'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext