from fb_tools.common import pp
-from fb_tools.app import BaseApplication
+from fb_tools.cfg_app import FbConfigApplication
from fb_tools.errors import FbAppError, ExpectedHandlerError
from .xlate import __mo_file__ as __xlate_mo_file__
from .xlate import XLATOR, LOCALE_DIR, DOMAIN
-__version__ = '1.4.0'
+__version__ = '1.5.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# =============================================================================
-class CrTplApplication(BaseApplication):
+class CrTplApplication(FbConfigApplication):
"""
Class for the application objects.
"""
"Creates in the given VSphere environment and cluster a template object, "
"which can be used to spawn different virtual machines.")
- self._cfg_file = None
- self.config = None
-
super(CrTplApplication, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
- description=desc, initialized=False,
+ cfg_class=CrTplConfiguration, description=desc, initialized=False,
)
self.initialized = True
- # -------------------------------------------------------------------------
- @property
- def cfg_file(self):
- """Configuration file."""
- return self._cfg_file
-
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
"""
res = super(CrTplApplication, self).as_dict(short=short)
- res['cfg_file'] = self.cfg_file
if 'xlate' not in res:
res['xlate'] = {}
self.initialized = False
- self.init_logging()
-
- self.perform_arg_parser()
-
- self.config = CrTplConfiguration(
- appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
- config_file=self.cfg_file)
-
- self.config.read()
- if self.config.verbose > self.verbose:
- self.verbose = self.config.verbose
- self.config.initialized = True
-
- if self.verbose > 3:
- LOG.debug(_("Read configuration:") + '\n' + pp(self.config.as_dict()))
+ super(CrTplApplication, self).post_init()
self.perform_arg_parser_vmware()
- if not self.config.vsphere_info.password:
+ if not self.cfg.vsphere_info.password:
prompt = (_('Enter password for host {h!r} and user {u!r}:') + ' ').format(
- h=self.config.vsphere_info.host, u=self.config.vsphere_info.user)
- self.config.vsphere_info.password = getpass.getpass(prompt=prompt)
+ h=self.cfg.vsphere_info.host, u=self.cfg.vsphere_info.user)
+ self.cfg.vsphere_info.password = getpass.getpass(prompt=prompt)
self.handler = CrTplHandler(
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
- simulate=self.simulate, force=self.force, config=self.config,
+ simulate=self.simulate, force=self.force, cfg=self.cfg,
terminal_has_colors=self.terminal_has_colors)
if self.args.rotate:
super(CrTplApplication, self).init_arg_parser()
- default_cfg_file = self.base_dir.joinpath('etc').joinpath(self.appname + '.ini')
-
self.arg_parser.add_argument(
'-A', '--abort', dest='abort', action='store_true',
help=_(
"Abort creation of VMWare template after successsful creation of template VM."),
)
- self.arg_parser.add_argument(
- '-c', '--config', '--config-file', dest='cfg_file', metavar=_('FILE'),
- action=CfgFileOptionAction,
- help=_("Configuration file (default: {!r}).").format(str(default_cfg_file))
- )
-
vmware_group = self.arg_parser.add_argument_group(_('VMWare options'))
vmware_group.add_argument(
)
vmware_group.add_argument(
- '-C', '--cluster', dest='cluster',
+ '-c', '--cluster', dest='cluster',
help=_(
"Host cluster in VSphere, where to create the template (Default: {!r}).").format(
CrTplConfiguration.default_vsphere_cluster)
# -------------------------------------------------------------------------
def perform_arg_parser(self):
- if self.args.cfg_file:
- self._cfg_file = self.args.cfg_file
+ if self.verbose > 2:
+ LOG.debug(_("Got command line arguments:") + '\n' + pp(self.args))
# -------------------------------------------------------------------------
def perform_arg_parser_vmware(self):
"""
if self.args.host:
- self.config.vsphere_info.host = self.args.host
+ self.cfg.vsphere_info.host = self.args.host
if self.args.port:
- self.config.vsphere_info.port = self.args.port
+ self.cfg.vsphere_info.port = self.args.port
if self.args.user:
- self.config.vsphere_info.user = self.args.user
+ self.cfg.vsphere_info.user = self.args.user
if self.args.password:
- self.config.vsphere_info.password = self.args.password
+ self.cfg.vsphere_info.password = self.args.password
if self.args.cluster:
- self.config.vsphere_cluster = self.args.cluster
+ self.cfg.vsphere_cluster = self.args.cluster
if self.args.folder:
- self.config.folder = self.args.folder
+ self.cfg.folder = self.args.folder
if self.args.os_id:
- self.config.os_id = self.args.os_id
- if not self.config.template_name_given:
- self.config.template_name = self.args.os_id + '-template'
- if not self.config.cobbler_profile_given:
- self.config.cobbler_profile = 'vmware-template-' + self.args.os_id
+ self.cfg.os_id = self.args.os_id
+ if not self.cfg.template_name_given:
+ self.cfg.template_name = self.args.os_id + '-template'
+ if not self.cfg.cobbler_profile_given:
+ self.cfg.cobbler_profile = 'vmware-template-' + self.args.os_id
if self.args.number is not None:
- self.config.max_nr_templates_stay = self.args.number
+ self.cfg.max_nr_templates_stay = self.args.number
# -------------------------------------------------------------------------
def _run(self):