--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2020 by Frank Brehm, Berlin
+@summary: A handler module for executing cobbler actions
+"""
+from __future__ import absolute_import, print_function
+
+# Standard module
+import logging
+import re
+
+# Third party modules
+import paramiko
+
+# Own modules
+
+from fb_tools.common import pp, to_str
+
+from fb_tools.errors import HandlerError, ExpectedHandlerError
+
+from fb_tools.handler import BaseHandler
+
+from .config import CrTplConfiguration
+
+from .xlate import XLATOR
+
+__version__ = '0.0.1'
+
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
+
+# =============================================================================
+class CobblerError(HandlerError):
+ """Exception class for unexpected exceptions."""
+ pass
+
+# =============================================================================
+class Cobbler(BaseHandler):
+ """
+ A handler class for executing cobbler actions.
+ """
+
+ # -------------------------------------------------------------------------
+ def __init__(
+ self, appname=None, verbose=0, version=__version__, base_dir=None,
+ config=None, terminal_has_colors=False, simulate=None, force=None, initialized=False):
+
+ self.host = CrTplConfiguration.default_cobbler_host
+ self.ssh_port = CrTplConfiguration.default_cobbler_ssh_port
+ self.ssh_user = CrTplConfiguration.default_cobbler_ssh_user
+ self.private_ssh_key = None
+ self.ssh = None
+ self.ssh_timeout = CrTplConfiguration.default_cobbler_ssh_timeout
+
+ super(Cobbler, self).__init__(
+ appname=appname, verbose=verbose, version=version, base_dir=base_dir,
+ terminal_has_colors=terminal_has_colors, simulate=simulate,
+ force=force, initialized=False,
+ )
+
+ self.private_ssh_key = str(self.base_dir.joinpath('keys', CrTplConfiguration.ssh_privkey))
+
+ if config:
+ self.private_ssh_key = config.private_ssh_key
+ self.host = config.cobbler_host
+ self.ssh_port = config.cobbler_ssh_port
+ self.ssh_user = config.cobbler_ssh_user
+ self.ssh_timeout = config.cobbler_ssh_timeout
+
+ if initialized:
+ self.initialized = True
+
+
+# =============================================================================
+if __name__ == "__main__":
+
+ pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list
from .xlate import XLATOR
-__version__ = '1.3.1'
+__version__ = '1.4.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
max_max_wait_for_finish_install = 24 * 60 * 60
limit_max_nr_templates_stay = 100
+ default_cobbler_host = 'cobbler.pixelpark.com'
+ default_cobbler_ssh_port = 22
+ default_cobbler_ssh_user = 'root'
+ default_cobbler_ssh_timeout = 30
+
+ ssh_privkey = 'id_rsa_cr_vmw_tpl'
+
mac_address_template = "00:16:3e:53:{:02x}:{:02x}"
# -------------------------------------------------------------------------
self.vmware_cfg_version = self.default_vmware_cfg_version
self.os_version = self.default_os_version
+ self.private_ssh_key = None
+
+ self.cobbler_host = self.default_cobbler_host
+ self.cobbler_ssh_port = self.default_cobbler_ssh_port
+ self.cobbler_ssh_user = self.default_cobbler_ssh_user
+ self.cobbler_ssh_timeout = self.default_cobbler_ssh_timeout
+
self.excluded_datastores = []
super(CrTplConfiguration, self).__init__(
encoding=encoding, config_dir=config_dir, config_file=config_file, initialized=False,
)
+ self.private_ssh_key = str(self.base_dir.joinpath('keys', self.ssh_privkey))
+
if initialized:
self.initialized = True
if section_name.lower() == 'timeouts':
self._eval_config_timeouts(config, section_name)
return
+ if section_name.lower() == 'cobbler':
+ self._eval_config_cobbler(config, section_name)
+ return
if self.verbose > 1:
LOG.debug(_("Unhandled configuration section {!r}.").format(section_name))
max_val=self.max_max_wait_for_finish_install,
default_val=self.default_max_wait_for_finish_install)
+ # -------------------------------------------------------------------------
+ def _eval_config_cobbler(self, config, section_name):
+
+ if self.verbose > 1:
+ LOG.debug(_("Checking config section {!r} ...").format(section_name))
+
+ re_port_key = re.compile(r'^\s*ssh[-_]?port\s*$', re.IGNORECASE)
+ re_user_key = re.compile(r'^\s*ssh[-_]?user\s*$', re.IGNORECASE)
+ re_timeout_key = re.compile(r'^\s*ssh-_]?timeout\s*$', re.IGNORECASE)
+
+ for (key, value) in config.items(section_name):
+ if key.lower() == 'host' and value.strip() != '':
+ self.cobbler_host = value.strip().lower()
+ continue
+ if re_port_key.match(key) and value.strip() != '':
+ self.cobbler_ssh_port = int(value)
+ continue
+ if re_user_key.match(key):
+ self.cobbler_ssh_user = value.strip().lower()
+ continue
+ if re_timeout_key.match(key):
+ self.cobbler_ssh_timeout = int(value)
# =============================================================================
if __name__ == "__main__":
"""
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
-@copyright: © 2018 by Frank Brehm, Berlin
+@copyright: © 2020 by Frank Brehm, Berlin
@summary: A handler module for creating the VMWare template
"""
from __future__ import absolute_import, print_function