]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Making changes on config because of Cobbler 3.X
authorFrank Brehm <frank@brehm-online.com>
Mon, 20 Jun 2022 14:20:25 +0000 (16:20 +0200)
committerFrank Brehm <frank@brehm-online.com>
Mon, 20 Jun 2022 14:20:25 +0000 (16:20 +0200)
bin/create-vmware-template
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/config.py

index 38e7507ca2a237f4f4a3c50265c870ca5d19ccc1..63745de486ba9161b593942dd74e67d04b063cb8 100755 (executable)
@@ -52,7 +52,7 @@ app.initialized = True
 if app.verbose > 2:
     print("{c}-Object:\n{a}".format(c=app.__class__.__name__, a=app))
 
-app()
+app()
 
 sys.exit(0)
 
index 8ed38c95a5c5ef1d3bcf49f98fd6c8e1e9a239e9..098e9f316bcad4db71f63b840eef43d695849441 100644 (file)
@@ -26,15 +26,15 @@ from pathlib import Path
 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
 
@@ -42,7 +42,7 @@ from .config import CrTplConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '0.7.0'
+__version__ = '0.7.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -87,6 +87,7 @@ class Cobbler(BaseHandler):
         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,
@@ -250,10 +251,22 @@ class Cobbler(BaseHandler):
 
         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
 
     # -------------------------------------------------------------------------
index 260157bc0d85b75b050576e892211d747936b350..a77757ab907f70254dc566c880c40c38564e431f 100644 (file)
@@ -19,12 +19,13 @@ from pathlib import Path
 
 # 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
@@ -83,8 +84,6 @@ class CrTplConfiguration(BaseConfiguration):
     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',
@@ -100,6 +99,14 @@ class CrTplConfiguration(BaseConfiguration):
     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}"
@@ -150,6 +157,8 @@ class CrTplConfiguration(BaseConfiguration):
 
         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
@@ -158,8 +167,6 @@ class CrTplConfiguration(BaseConfiguration):
         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)
@@ -186,6 +193,51 @@ class CrTplConfiguration(BaseConfiguration):
         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):
@@ -242,6 +294,11 @@ class CrTplConfiguration(BaseConfiguration):
         """
 
         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
@@ -282,9 +339,6 @@ class CrTplConfiguration(BaseConfiguration):
         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):