]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Checking for availability of the given distro
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 27 May 2020 15:15:56 +0000 (17:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 27 May 2020 15:15:56 +0000 (17:15 +0200)
lib/cr_vmware_tpl/cobbler.py
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/handler.py

index 8b6dac49bb27d59d1b1f5e72f4b755a81b3fad15..51ee93df9d5f6cd560a16e1140612471a0e76502 100644 (file)
@@ -31,7 +31,7 @@ from .config import CrTplConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '0.2.3'
+__version__ = '0.2.4'
 
 LOG = logging.getLogger(__name__)
 
@@ -165,6 +165,20 @@ class Cobbler(BaseHandler):
 
         return cobbler_version
 
+    # -------------------------------------------------------------------------
+    def get_distro_list(self):
+        """Trying to get a list of all configured distros."""
+
+        distro_list = []
+        proc = self.exec_cobbler(('distro', 'list'), no_simulate=True)
+        lines = proc.stdout.splitlines()
+        for line in proc.stdout.splitlines():
+            distro = line.strip()
+            if distro:
+                distro_list.append(distro)
+        distro_list.sort(key=str.lower)
+        return distro_list
+
 
 # =============================================================================
 if __name__ == "__main__":
index c1e60a02b81cfe97074e5fcc4a2fcdbb46d53350..f58aca7202c397ee987258c08cc164893fabd0bc 100644 (file)
@@ -19,7 +19,7 @@ from fb_tools.config import ConfigError, BaseConfiguration
 
 from .xlate import XLATOR
 
-__version__ = '1.4.0'
+__version__ = '1.4.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -70,6 +70,7 @@ class CrTplConfiguration(BaseConfiguration):
     default_cobbler_ssh_port = 22
     default_cobbler_ssh_user = 'root'
     default_cobbler_ssh_timeout = 30
+    default_cobbler_distro = 'CentOS-8.1-x86_64'
 
     ssh_privkey = 'id_rsa_cr_vmw_tpl'
 
@@ -106,6 +107,7 @@ class CrTplConfiguration(BaseConfiguration):
 
         self.private_ssh_key = None
 
+        self.cobbler_distro = self.default_cobbler_distro
         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
@@ -393,6 +395,9 @@ class CrTplConfiguration(BaseConfiguration):
         re_timeout_key = re.compile(r'^\s*ssh-_]?timeout\s*$', re.IGNORECASE)
 
         for (key, value) in config.items(section_name):
+            if key.lower() == 'distro' and value.strip() != '':
+                self.cobbler_distro = value.strip()
+                continue
             if key.lower() == 'host' and value.strip() != '':
                 self.cobbler_host = value.strip().lower()
                 continue
index 98a106c588be80ba805057f687940f0f0eda0927..e59e020eca91efe4bb1121c7c5de5cbf3d5bd987 100644 (file)
@@ -40,7 +40,7 @@ from .cobbler import CobblerError, Cobbler
 
 from .xlate import XLATOR
 
-__version__ = '1.4.3'
+__version__ = '1.4.4'
 
 LOG = logging.getLogger(__name__)
 TZ = pytz.timezone('Europe/Berlin')
@@ -173,6 +173,7 @@ class CrTplHandler(BaseHandler):
 
         LOG.debug(_("Starting handling ..."))
         self.cobbler.get_cobbler_version()
+        self.check_for_cobbler_distro()
 
         return 0
 
@@ -232,6 +233,21 @@ class CrTplHandler(BaseHandler):
 
         return 0
 
+    # -------------------------------------------------------------------------
+    def check_for_cobbler_distro(self):
+        LOG.debug(_(
+            "Checking, whether distro {!r} is available "
+            "on the cobbler host.").format(self.config.cobbler_distro))
+
+        distro_list = self.cobbler.get_distro_list()
+        if self.config.cobbler_distro not in distro_list:
+            msg = _("Did not found distro {!r} on the cobbler host.").format(
+                self.config.cobbler_distro)
+            raise ExpectedHandlerError(msg)
+        if self.verbose > 1:
+            msg = _("Distro {!r} is available on the cobbler host.").format(
+                self.config.cobbler_distro)
+
     # -------------------------------------------------------------------------
     def check_for_temp_tpl_vm(self, no_error=False):