From: Frank Brehm Date: Thu, 25 Jul 2024 12:46:14 +0000 (+0200) Subject: Cleanup handling of failing VSphere username and password. X-Git-Tag: 1.11.0^2~5 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=3a9e4522809418adfe9297265ded60f0c158b8ab;p=pixelpark%2Fcreate-terraform.git Cleanup handling of failing VSphere username and password. --- diff --git a/lib/create_terraform/app.py b/lib/create_terraform/app.py index 37864bb..64a5981 100644 --- a/lib/create_terraform/app.py +++ b/lib/create_terraform/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.4.1' +__version__ = '1.5.0' LOG = logging.getLogger(__name__) SIGNAL_NAMES = { @@ -527,58 +527,7 @@ class CrTfApplication(BaseApplication): if not self.handler: raise TerraformHandlerError(_("No handler object available.")) - need_nl = False - - if not self.handler.vsphere_user: - - need_nl = True - msg = '\n' + _("Please input the {}.").format(self.colored( - _('vSphere user name'), 'AQUA')) - print(msg) - self.handler.vsphere_user = input(self.colored(_('Name'), 'AQUA') + ': ') - if not self.handler.vsphere_user: - msg = _("No {} given.").format(_('vSphere user name')) - raise ExpectedHandlerError(msg) - - for vsphere_name in self.handler.vsphere.keys(): - LOG.debug(_("Setting user for vSphere {vs!r} to {usr!r}.").format( - vs=vsphere_name, usr=self.handler.vsphere_user)) - # Dirty, but else a change of fb_tools would be necessary (later) - self.handler.vsphere[vsphere_name]._user = self.handler.vsphere_user - print('') - need_nl = False - - if not self.handler.vsphere_password: - - # Get the name of the first (and hopefully only) VSphere - vsphere_name = None - for vn in self.handler.vsphere.keys(): - vsphere_name = vn - break - - if need_nl: - print('') - prompt = self.colored(_("User password of {!r}").format( - self.handler.vsphere_user), 'AQUA') - item = _('Password for user {u!r} of vSphere {n} on {h!r}').format( - u=self.handler.vsphere_user, n=vsphere_name, - h=self.config.vsphere[vsphere_name].host) - item = self.colored(item, 'AQUA') - 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 vsphere_name in self.handler.vsphere.keys(): - LOG.debug(_("Setting passwort of vSphere {vs!r} user {usr!r}.").format( - vs=vsphere_name, usr=self.handler.vsphere_user)) - # Dirty, but else a change of fb_tools would be necessary (later) - self.handler.vsphere[vsphere_name]._password = self.handler.vsphere_password - print('') - need_nl = False - - if need_nl: - print('') + return # ------------------------------------------------------------------------- def post_run(self): diff --git a/lib/create_terraform/handler/__init__.py b/lib/create_terraform/handler/__init__.py index b83bc3a..dff853a 100644 --- a/lib/create_terraform/handler/__init__.py +++ b/lib/create_terraform/handler/__init__.py @@ -32,8 +32,8 @@ from fb_tools.handling_obj import HandlingObject, CalledProcessError from fb_tools.handler import BaseHandler # Own modules +from ..errors import ConsulApiNotFoundError from .dns import CrTfHandlerDnsMixin -from .errors import ConsulApiNotFoundError from .files import CrTfHandlerFilesMixin from .first import CrTfHandlerFirstMixin from .read import CrTfHandlerReadMixin @@ -50,7 +50,7 @@ from ..errors import AbortExecution from ..xlate import XLATOR -__version__ = '4.3.1' +__version__ = '4.3.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -148,9 +148,6 @@ class CreateTerraformHandler( self.vsphere_vm_cache = {} - self.vsphere_user = None - self.vsphere_password = None - self.used_networks = {} self.used_dc_clusters = {} self.used_datastores = {} diff --git a/lib/create_terraform/handler/vmware.py b/lib/create_terraform/handler/vmware.py index e52f5b3..ed8fa7c 100644 --- a/lib/create_terraform/handler/vmware.py +++ b/lib/create_terraform/handler/vmware.py @@ -31,7 +31,7 @@ from ..slim_vm import SlimVm from ..xlate import XLATOR -__version__ = '1.0.1' +__version__ = '1.1.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -127,14 +127,6 @@ class CrTfHandlerVmwMixin(): msg = _("VSPhere {!r} not defined in configuration.").format(vsphere_name) raise ExpectedHandlerError(msg) - if not self.vsphere_user and self.config.vsphere[vsphere_name].user: - LOG.debug(_("Setting {st} to {what!r}.").format( - st='handler.vsphere_user', what=self.config.vsphere[vsphere_name].user)) - self.vsphere_user = self.config.vsphere[vsphere_name].user - if not self.vsphere_password and self.config.vsphere[vsphere_name].password: - LOG.debug(_("Setting {}.").format('handler.vsphere_password')) - self.vsphere_password = self.config.vsphere[vsphere_name].password - try: params = { 'appname': self.appname, @@ -153,8 +145,8 @@ class CrTfHandlerVmwMixin(): connect_info = VSPhereConfigInfo( appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, - host=vs_host, port=vs_port, dc=vs_dc, user=self.vsphere_user, - password=self.vsphere_password, initialized=True) + host=vs_host, port=vs_port, dc=vs_dc, user=self.config.vsphere[vsphere_name].user, + configured_password=self.config.vsphere[vsphere_name].password, initialized=True) params['connect_info'] = connect_info show_params['connect_info'] = connect_info.as_dict() @@ -167,6 +159,7 @@ class CrTfHandlerVmwMixin(): LOG.debug(msg) vsphere = VsphereConnection(**params) + vsphere._check_credentials() self.vsphere[vsphere_name] = vsphere except VSphereExpectedError as e: diff --git a/locale/de_DE/LC_MESSAGES/create_terraform.po b/locale/de_DE/LC_MESSAGES/create_terraform.po index 41f5ed9..d70cf31 100644 --- a/locale/de_DE/LC_MESSAGES/create_terraform.po +++ b/locale/de_DE/LC_MESSAGES/create_terraform.po @@ -63,23 +63,23 @@ msgstr "Gelesene Konfiguration:" #: lib/create_terraform/app.py:292 msgid "Removing allowed puppet environments ..." -msgstr "Ungültige Puppet-Umgebung {!r}." +msgstr "Entferne erlaubte Puppet-Umgebungen …" #: lib/create_terraform/app.py:296 msgid "Removing puppet environment {!r} ..." -msgstr "Setze Puppet Umgebung auf {!r}." +msgstr "Entferne Puppet Umgebung {!r} …" #: lib/create_terraform/app.py:300 msgid "Adding allowed puppet environments ..." -msgstr "Ungültige Puppet-Umgebung {!r}." +msgstr "Füge erlaubte Puppet-Umgebungen hinzu …" #: lib/create_terraform/app.py:304 msgid "Adding puppet environment {!r} ..." -msgstr "Ungültige Puppet-Umgebung {!r}." +msgstr "Füge Puppet-Umgebung {!r} hinzu …" #: lib/create_terraform/app.py:309 msgid "Allowed puppet environments:" -msgstr "Ungültige Puppet-Umgebung {!r}." +msgstr "Erlaubte Puppet-Umgebungen:" #: lib/create_terraform/app.py:321 msgid "PowerDNS API key for {!r}"