import paramiko
from paramiko.ssh_exception import SSHException
+from packaging.version import Version
+
# Own modules
from fb_tools.common import pp, to_str, is_sequence
-
from fb_tools.errors import HandlerError, ExpectedHandlerError
-
from fb_tools.handling_obj import CompletedProcess
-
from fb_tools.handler import BaseHandler
+from fb_tools.xlate import format_list
from . import print_section_start, print_section_end
from .xlate import XLATOR
-__version__ = '0.7.0'
+__version__ = '0.7.1'
LOG = logging.getLogger(__name__)
self.ssh_timeout = CrTplConfiguration.default_cobbler_ssh_timeout
self.root_dir = CrTplConfiguration.default_cobbler_rootdir
self.config = config
+ self.cobbler_version = None
super(Cobbler, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
first_line = proc.stdout.splitlines()[0]
cobbler_version = re.sub(r'^\s*cobbler\s+', '', first_line, flags=re.IGNORECASE).strip()
+ self.cobbler_version = Version(cobbler_version)
+
LOG.info(_("Version of {} is:").format("Cobbler") + " {!r}".format(cobbler_version))
+ if self.cobbler_version.major not in (2, 3):
+ msg = _("Unsupported version {ver!r} of {co}, valid versions of {co} are {valid}.")
+ msg = msg.format(ver=cobbler_version, co='Cobbler', valid=format_list(['2.X', '3.X']))
+ raise ExpectedCobblerError(msg)
+
+ self.config.cobbler_major_version = self.cobbler_version.major
+
self.check_remote_directory(self.config.cobbler_rootdir, _('Cobbler root directory'))
+ if self.verbose > 3:
+ LOG.debug("Current configuration:\n" + pp(self.config.as_dict()))
+
return cobbler_version
# -------------------------------------------------------------------------
# Own modules
from fb_tools.config import ConfigError, BaseConfiguration
+from fb_tools.xlate import format_list
from fb_vmware.config import VSPhereConfigInfo
from .xlate import XLATOR
-__version__ = '1.7.1'
+__version__ = '1.7.2'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
default_cobbler_distro = 'CentOS-8.2-x86_64'
default_cobbler_rootdir = Path('/var/lib/cobbler')
default_cobbler_profile = 'vmware-template-' + default_os_id
- default_cobbler_ks_dir = default_cobbler_rootdir / 'kickstarts'
- default_cobbler_profile_ks = default_cobbler_ks_dir / (default_cobbler_profile + '.ks')
default_cobbler_profile_repos = ['pp-centos8-baseos']
default_cobbler_nameservers = [
'93.188.109.11',
default_cobbler_ws_docroot = Path('/var/www/html')
default_cobbler_ws_rel_filesdir = Path('custom/vmware-template-files')
+ default_cobbler2_templates_dir_rel = 'kickstarts'
+ default_cobbler2_collections_dir_rel = 'config'
+ default_cobbler2_profiles_dir_rel = 'profiles.d'
+
+ default_cobbler3_templates_dir_rel = 'templates'
+ default_cobbler3_collections_dir_rel = 'collections'
+ default_cobbler3_profiles_dir_rel = 'profiles'
+
ssh_privkey = 'id_rsa_cr_vmw_tpl'
mac_address_template = "00:16:3e:53:{:02x}:{:02x}"
self.private_ssh_key = None
+ self._cobbler_major_version = 3
+
self.cobbler_bin = self.default_cobbler_bin
self.cobbler_distro = self.default_cobbler_distro
self.cobbler_host = self.default_cobbler_host
self.cobbler_ssh_timeout = self.default_cobbler_ssh_timeout
self.cobbler_rootdir = self.default_cobbler_rootdir
self.cobbler_profile = self.default_cobbler_profile
- self.cobbler_ks_dir = self.default_cobbler_ks_dir
- self.cobbler_profile_ks = self.default_cobbler_profile_ks
self.cobbler_profile_repos = copy.copy(self.default_cobbler_profile_repos)
self.cobbler_nameservers = copy.copy(self.default_cobbler_nameservers)
self.cobbler_dns_search = copy.copy(self.default_cobbler_dns_search)
if initialized:
self.initialized = True
+ # -------------------------------------------------------------------------
+ @property
+ def cobbler_major_version(self):
+ """The major version of the used cobbler installation. Valid values are 2 and 3."""
+ return self._cobbler_major_version
+
+ @cobbler_major_version.setter
+ def cobbler_major_version(self, value):
+ if value not in (2, 3):
+ msg = _("Unsupported version {ver!r} of {co}, valid versions of {co} are {valid}.")
+ msg = msg.format(ver=value, co='Cobbler', valid=format_list(['2', '3']))
+ raise CrTplConfigError(msg)
+
+ self._cobbler_major_version = value
+
+ # -------------------------------------------------------------------------
+ @property
+ def cobbler_collections_dir(self):
+ """The absolute pathname of all Cobbler collections."""
+ if self.cobbler_major_version == 2:
+ return self.cobbler_rootdir / self.default_cobbler2_collections_dir_rel
+ return self.cobbler_rootdir / self.default_cobbler3_collections_dir_rel
+
+ # -------------------------------------------------------------------------
+ @property
+ def cobbler_ks_dir(self):
+ """The absolute pathname of the directory of the kickstart/template/autoinstall files."""
+ if self.cobbler_major_version == 2:
+ return self.cobbler_rootdir / self.default_cobbler2_templates_dir_rel
+ return self.cobbler_rootdir / self.default_cobbler3_templates_dir_rel
+
+ # -------------------------------------------------------------------------
+ @property
+ def cobbler_profile_dir(self):
+ """The absolute pathname of the directory of Cobbler profile configuration files."""
+ if self.cobbler_major_version == 2:
+ return self.cobbler_collections_dir / self.default_cobbler2_profiles_dir_rel
+ return self.cobbler_collections_dir / self.default_cobbler3_profiles_dir_rel
+
+ # -------------------------------------------------------------------------
+ @property
+ def cobbler_profile_ks(self):
+ """The absolute pathname of the profile kickstart file."""
+ return self.cobbler_ks_dir / (self.cobbler_profile + '.ks')
+
# -------------------------------------------------------------------------
@property
def data_size_mb(self):
"""
res = super(CrTplConfiguration, self).as_dict(short=short)
+ res['cobbler_major_version'] = self.cobbler_major_version
+ res['cobbler_collections_dir'] = self.cobbler_collections_dir
+ res['cobbler_ks_dir'] = self.cobbler_ks_dir
+ res['cobbler_profile_dir'] = self.cobbler_profile_dir
+ res['cobbler_profile_ks'] = self.cobbler_profile_ks
res['data_size_mb'] = self.data_size_mb
res['data_size_kb'] = self.data_size_kb
res['data_size'] = self.data_size
if not self.cobbler_profile_given:
self.cobbler_profile = 'vmware-template-' + self.os_id
- self.cobbler_ks_dir = self.cobbler_rootdir / 'kickstarts'
- self.cobbler_profile_ks = self.cobbler_ks_dir / (self.cobbler_profile + '.ks')
-
# -------------------------------------------------------------------------
def eval_config_section(self, config, section_name):