from pathlib import Path
# Third party modules
-
-# Own modules
-from . import __version__ as __pkg_version__
-from . import CFGFILE_BASENAME
-
from fb_tools.common import pp
-
from fb_tools.app import BaseApplication
-
from fb_tools.errors import ExpectedHandlerError, CommandNotFoundError
-
from fb_tools.config import ConfigError
-
from fb_tools.common import generate_password
-from .errors import TerraformHandlerError, TerraformVSphereError
+# Own modules
+from . import __version__ as __pkg_version__
+from . import CFGFILE_BASENAME
+
+from .errors import TerraformHandlerError
from .config import CrTfConfiguration
from .xlate import __mo_file__ as __xlate_mo_file__
from .xlate import XLATOR, LOCALE_DIR, DOMAIN
-__version__ = '1.3.1'
+__version__ = '1.3.2'
LOG = logging.getLogger(__name__)
SIGNAL_NAMES = {
self._cfg_dir = self.base_dir / 'etc'
self._cfg_file = self.base_dir.parent / CFGFILE_BASENAME
+ # -------------------------------------------------------------------------
+ def _warn_about_missing_cfg(self):
+
+ cur_dir = Path.cwd()
+
+ default_conf_file = self.cfg_dir / (CFGFILE_BASENAME + '.default')
+ default_cfg_file_rel = os.path.relpath(str(default_conf_file), str(cur_dir))
+
+ cfg1 = self.base_dir.parent / CFGFILE_BASENAME
+ cfg1 = os.path.relpath(str(cfg1), str(cur_dir))
+
+ cfg2 = self.base_dir.parent / 'etc' / CFGFILE_BASENAME
+ cfg2 = os.path.relpath(str(cfg2), str(cur_dir))
+
+ cfg3 = self.cfg_dir / CFGFILE_BASENAME
+ cfg3 = os.path.relpath(str(cfg3), str(cur_dir))
+
+ # cfg_file_rel = os.path.relpath(str(self.cfg_file), str(cur_dir))
+ msg = (_(
+ "Config file {f!r} not found, using defaults.\n"
+ "To avoid this message, you may copy {d!r} to {c1!r}, {c2!r} or {c3!r} "
+ "and fill out all necessary entries, e.g. the passwords and API keys.").format(
+ f=CFGFILE_BASENAME, d=default_cfg_file_rel, c1=cfg1, c2=cfg2, c3=cfg3))
+ LOG.warn(msg)
+
+ # -------------------------------------------------------------------------
+ def _read_cfg(self):
+
+ if self.cfg_file.exists():
+ try:
+ self.config.read()
+ except ConfigError as e:
+ LOG.error(_("Error in configuration:") + " " + str(e))
+ self.exit(1)
+ if self.verbose > 3:
+ LOG.debug(_("Read configuration:") + '\n' + pp(self.config.as_dict()))
+
# -------------------------------------------------------------------------
def post_init(self):
"""
This method could be overwritten by descendant classes, these
methhods should allways include a call to post_init() of the
parent class.
-
"""
self.initialized = False
self.perform_arg_parser()
if not self.cfg_file.exists():
- cur_dir = Path(os.getcwd())
- default_conf_file = self.cfg_dir / (CFGFILE_BASENAME + '.default')
- default_cfg_file_rel = os.path.relpath(str(default_conf_file), str(cur_dir))
-
- cfg1 = self.base_dir.parent / CFGFILE_BASENAME
- cfg1 = os.path.relpath(str(cfg1), str(cur_dir))
-
- cfg2 = self.base_dir.parent / 'etc' / CFGFILE_BASENAME
- cfg2 = os.path.relpath(str(cfg2), str(cur_dir))
-
- cfg3 = self.cfg_dir / CFGFILE_BASENAME
- cfg3 = os.path.relpath(str(cfg3), str(cur_dir))
-
- cfg_file_rel = os.path.relpath(str(self.cfg_file), str(cur_dir))
- msg = (_(
- "Config file {f!r} not found, using defaults.\n"
- "To avoid this message, you may copy {d!r} to {c1!r}, {c2!r} or {c3!r} "
- "and fill out all necessary entries, e.g. the passwords and API keys.").format(
- f=CFGFILE_BASENAME, d=default_cfg_file_rel, c1=cfg1, c2=cfg2, c3=cfg3))
- LOG.warn(msg)
+ self._warn_about_missing_cfg()
self.config = CrTfConfiguration(
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
self.config.init_vsphere_defaults()
- if self.cfg_file.exists():
- try:
- self.config.read()
- except ConfigError as e:
- LOG.error(_("Error in configuration:") + " " + str(e))
- self.exit(1)
- if self.verbose > 3:
- LOG.debug(_("Read configuration:") + '\n' + pp(self.config.as_dict()))
+ self._read_cfg()
if self.config.verbose > self.verbose:
self.verbose = self.config.verbose
need_nl = True
msg = '\n' + _("Please input the {}.").format(self.colored(
- _('vSphere user name'), 'AQUA'))
+ _('vSphere user name'), 'AQUA'))
print(msg)
self.handler.vsphere_user = input(self.colored(_('Name'), 'AQUA') + ': ')
if not self.handler.vsphere_user:
if need_nl:
print('')
prompt = self.colored(_("User password of {!r}").format(
- self.handler.vsphere_user), 'AQUA')
+ self.handler.vsphere_user), 'AQUA')
item = _('Password for user {u!r} of vSphere {n} on {h!r}').format(
- u=self.handler.vsphere_user, n=vname, h=self.config.vsphere[vname].host)
+ u=self.handler.vsphere_user, n=vname, h=self.config.vsphere[vname].host)
item = self.colored(item, 'AQUA')
self.handler.vsphere_password = self.get_secret(prompt=prompt, item_name=item)
if not self.handler.vsphere_password: