]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Reading in cobbler repo definitions from config
authorFrank Brehm <frank@brehm-online.com>
Fri, 24 Jun 2022 12:43:22 +0000 (14:43 +0200)
committerFrank Brehm <frank@brehm-online.com>
Fri, 24 Jun 2022 12:43:22 +0000 (14:43 +0200)
lib/cr_vmware_tpl/config.py

index 68b54e316f6fb68e70d92412db748c5dc2e1b64a..e3f160c4271958940bf84b460db726e65e393463 100644 (file)
@@ -18,7 +18,7 @@ import crypt
 from pathlib import Path
 
 # Own modules
-from fb_tools.common import is_sequence
+from fb_tools.common import is_sequence, pp
 from fb_tools.obj import FbGenericBaseObject
 from fb_tools.collections import CIStringSet
 from fb_tools.multi_config import MultiConfigError, BaseMultiConfig
@@ -477,6 +477,7 @@ class CrTplConfiguration(BaseMultiConfig):
         self.cobbler_ws_docroot = self.default_cobbler_ws_docroot
         self.cobbler_ws_rel_filesdir = self.default_cobbler_ws_rel_filesdir
         self.cobbler_distros = {}
+        self.cobbler_repos = {}
 
         self.current_distro = None
 
@@ -706,6 +707,7 @@ class CrTplConfiguration(BaseMultiConfig):
     def eval_section(self, section_name):
 
         re_cobbler_distros = re.compile(r'^\s*cobbler[_-]?distros\s*$', re.IGNORECASE)
+        re_cobbler_repos = re.compile(r'^\s*cobbler[_-]?repos\s*$', re.IGNORECASE)
 
         LOG.debug(_("Evaluating section {!r} ...").format(section_name))
 
@@ -729,6 +731,9 @@ class CrTplConfiguration(BaseMultiConfig):
         if re_cobbler_distros.match(section_name):
             self._eval_cobbler_distros(section_name, section)
             return
+        if re_cobbler_repos.match(section_name):
+            self._eval_cobbler_repos(section_name, section)
+            return
 
         if self.verbose > 1:
             LOG.debug(_("Unhandled configuration section {!r}.").format(section_name))
@@ -1075,6 +1080,30 @@ class CrTplConfiguration(BaseMultiConfig):
 
         return pwd_hash
 
+    # -------------------------------------------------------------------------
+    def _eval_cobbler_repos(self, section_name, section):
+
+        if self.verbose > 1:
+            LOG.debug(_("Checking config section {!r} ...").format(section_name))
+
+        for full_repo_name in section.keys():
+            repo_data = section[full_repo_name]
+            if isinstance(repo_data, dict):
+                repo_info = {}
+                if self.verbose > 2:
+                    LOG.debug(_("Found Cobbler repository {!r}.").format(full_repo_name))
+                for key in repo_data.keys():
+                    value = repo_data[key]
+                    if key.lower() == 'reponame' and value.strip() != '':
+                        repo_info['reponame'] = value.strip()
+                        continue
+                    if key.lower() == 'filename' and value.strip() != '':
+                        repo_info['filename'] = value.strip()
+                        continue
+                self.cobbler_repos[full_repo_name] = repo_info
+        if self.verbose > 3:
+            LOG.debug(_("Evaluated Cobbler repositories:") + '\n' + pp(self.cobbler_repos))
+
 
 # =============================================================================
 if __name__ == "__main__":