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
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 = {
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
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):
"""