]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Extending class CobblerDistroInfo by attribute arch in module cr_vmware_tpl.config. 2.5.1
authorFrank Brehm <frank@brehm-online.com>
Thu, 23 Jun 2022 11:11:57 +0000 (13:11 +0200)
committerFrank Brehm <frank@brehm-online.com>
Thu, 23 Jun 2022 11:11:57 +0000 (13:11 +0200)
lib/cr_vmware_tpl/__init__.py
lib/cr_vmware_tpl/config.py

index 42284eb16dc93ff5761747bef1e689b130d39143..1b8d05667f8bff178f4eb23239e71d39b8b8c70c 100644 (file)
@@ -3,9 +3,10 @@
 
 import time
 
-__version__ = '2.5.0'
+__version__ = '2.5.1'
 
 DEFAULT_CONFIG_DIR = 'pixelpark'
+DEFAULT_DISTRO_ARCH = 'x86_64'
 
 # -------------------------------------------------------------------------
 def print_section_start(name, header=None, collapsed=False):
index 1a66e2dcebbb715896b0316bc8d785b196752a48..9fb0a230516c8f07e7067511a8bf746f3736aaa7 100644 (file)
@@ -27,11 +27,11 @@ from fb_tools.xlate import format_list
 
 from fb_vmware.config import VSPhereConfigInfo
 
-from . import DEFAULT_CONFIG_DIR
+from . import DEFAULT_CONFIG_DIR, DEFAULT_DISTRO_ARCH
 
 from .xlate import XLATOR
 
-__version__ = '1.9.1'
+__version__ = '1.9.2'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -51,15 +51,20 @@ class CobblerDistroInfo(FbGenericBaseObject):
     """Class for encapsulation all necessary data of a Repo definition in Cobbler."""
 
     re_dashes = re.compile(r'[_-]')
+    valid_arch = (
+        'i386', 'x86_64', 'ia64', 'ppc', 'ppc64', 'ppc64el', 'ppc64le',
+        's390', 's390x', 'arm', 'aarch64')
 
     # -------------------------------------------------------------------------
     def __init__(
-            self, name, shortname=None, distro=None, description=None, repos=None, snippets=None):
+            self, name, shortname=None, distro=None, description=None, arch=DEFAULT_DISTRO_ARCH,
+            repos=None, snippets=None):
 
         self._name = None
         self._shortname = None
         self._distro = None
         self._description = None
+        self._arch = DEFAULT_DISTRO_ARCH
         self.repos = CIStringSet()
         self.snippets = CIStringSet()
 
@@ -67,6 +72,7 @@ class CobblerDistroInfo(FbGenericBaseObject):
         self.shortname = shortname
         self.distro = distro
         self.description = description
+        self.arch = arch
 
         if repos:
             if is_sequence(repos):
@@ -141,6 +147,24 @@ class CobblerDistroInfo(FbGenericBaseObject):
 
         self._distro = dis
 
+    # -------------------------------------------------------------------------
+    @property
+    def arch(self):
+        """The name of the underlaying (real) cobbler distro."""
+        return getattr(self, '_arch', DEFAULT_DISTRO_ARCH)
+
+    @arch.setter
+    def arch(self, value):
+
+        arch = value.strip().lower()
+        if arch not in self.valid_arch:
+            msg = _(
+                "Invalid architecture {a!r} for distro {n!r} given. Valid architectures are {v}.")
+            msg = msg.format(a=value, n=self.name, v=format_list(self.valid_arch, do_repr=True))
+            raise ValueError(msg)
+
+        self._arch = arch
+
     # -------------------------------------------------------------------------
     @property
     def description(self):
@@ -170,6 +194,7 @@ class CobblerDistroInfo(FbGenericBaseObject):
         fields.append("name={!r}".format(self.name))
         fields.append("shortname={!r}".format(self._shortname))
         fields.append("distro={!r}".format(self.distro))
+        fields.append("arch={!r}".format(self.arch))
         fields.append("description={!r}".format(self.description))
 
         out += ", ".join(fields) + ")>"
@@ -193,15 +218,25 @@ class CobblerDistroInfo(FbGenericBaseObject):
         res['name'] = self.name
         res['shortname'] = self.shortname
         res['distro'] = self.distro
+        res['arch'] = self.arch
         res['description'] = self.description
 
         return res
 
+    # -------------------------------------------------------------------------
+    def __eq__(self, other):
+
+        if not isinstance(other, CobblerDistroInfo):
+            return False
+
+        return self.name == other.name
+
     # -------------------------------------------------------------------------
     def __copy__(self):
 
         new = self.__class__(
-            self.name, shortname=self.shortname, distro=self.distro, description=self.description)
+            self.name, shortname=self.shortname, distro=self.distro, arch=arch,
+            description=self.description)
 
         for repo in self.repos:
             new.repos.add(repo)
@@ -232,6 +267,10 @@ class CobblerDistroInfo(FbGenericBaseObject):
                 new.description = value
                 continue
 
+            if key.lower() == 'arch' and value.strip() != '':
+                new.arch = value
+                continue
+
             if key.lower() == 'repos':
                 if is_sequence(value):
                     for repo in value:
@@ -412,6 +451,8 @@ class CrTplConfiguration(BaseMultiConfig):
         self.cobbler_ws_rel_filesdir = self.default_cobbler_ws_rel_filesdir
         self.cobbler_distros = {}
 
+        self.current_distro = None
+
         self.system_status = self.default_system_status
 
         self.excluded_datastores = []
@@ -622,7 +663,8 @@ class CrTplConfiguration(BaseMultiConfig):
             msg = _("Did not found distro {!r} in configured Cobbler distros.").format(self.os_id)
             raise CrTplConfigError(msg)
 
-        self.cobbler_distro = self.cobbler_distros[self.os_id].distro
+        self.current_distro = self.cobbler_distros[self.os_id]
+        self.cobbler_distro = self.current_distro.distro
 
         LOG.info(_("Using OS {os!r} with cobbler distro {di!r}.").format(
             os=self.os_id, di=self.cobbler_distro))