]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Making the flake8 happy
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Sep 2023 09:50:11 +0000 (11:50 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 22 Sep 2023 09:50:11 +0000 (11:50 +0200)
lib/cr_vmware_tpl/app.py
lib/cr_vmware_tpl/cobbler/__init__.py
lib/cr_vmware_tpl/cobbler/distro.py
lib/cr_vmware_tpl/cobbler/files.py
lib/cr_vmware_tpl/cobbler/profile.py
lib/cr_vmware_tpl/cobbler/system.py
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/errors.py

index 50117c3ee8711aaafbd6267bdac575ff3548da31..896d42f2300d44501727e7f2b7d091c8fdce6b06 100644 (file)
@@ -27,12 +27,10 @@ from fb_tools.common import pp
 
 from fb_tools.cfg_app import FbConfigApplication
 
-from fb_tools.errors import FbAppError, ExpectedHandlerError
+from fb_tools.errors import ExpectedHandlerError
 
 from .config import CrTplConfiguration
 
-from .errors import CrTplAppError
-
 from .handler import CrTplHandler
 
 from .xlate import __module_dir__ as __xlate_module_dir__
@@ -40,7 +38,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__
 from .xlate import __mo_file__ as __xlate_mo_file__
 from .xlate import XLATOR, LOCALE_DIR, DOMAIN
 
-__version__ = '1.5.3'
+__version__ = '1.5.4'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
index 39fee8e3b8348df24a205f75c996c252cba7e416..274274b66bd81159c1546ab6947980145f30672e 100644 (file)
@@ -13,11 +13,7 @@ import logging
 import re
 import datetime
 import pipes
-import hashlib
-import textwrap
 import ipaddress
-import tempfile
-import os
 
 from pathlib import Path
 
@@ -27,13 +23,9 @@ from paramiko.ssh_exception import SSHException
 
 from packaging.version import Version
 
-import jinja2
-
-from six.moves import configparser
-
 # Own modules
 
-from fb_tools.common import pp, to_str, is_sequence, to_bool
+from fb_tools.common import pp, to_str, is_sequence
 from fb_tools.handling_obj import CompletedProcess
 from fb_tools.handler import BaseHandler
 from fb_tools.xlate import format_list
@@ -43,15 +35,13 @@ from .files import CobblerFiles
 from .profile import CobblerProfile
 from .system import CobblerSystem
 
-from .. import print_section_start, print_section_end
-
 from ..config import CrTplConfiguration
 
 from ..errors import CobblerError, ExpectedCobblerError
 
 from ..xlate import XLATOR
 
-__version__ = '0.11.3'
+__version__ = '0.11.4'
 
 LOG = logging.getLogger(__name__)
 
index 811f9093ed0a9b4a0a856a2fbf0109b3dc3d121a..1533940b55ee2a091f6cc82b2426c8b525df4341 100644 (file)
@@ -12,14 +12,13 @@ from __future__ import absolute_import, print_function
 import logging
 
 # Third party modules
-from fb_tools.common import pp, to_str, is_sequence, to_bool
-from fb_tools.xlate import format_list
+from fb_tools.common import pp
 
 # Own modules
 
 from ..xlate import XLATOR
 
-__version__ = '0.1.1'
+__version__ = '0.1.2'
 
 LOG = logging.getLogger(__name__)
 
index a3b67a26d6cfb4c82c3f5cf92eb2695503404ebc..10e403aee9f8534aaacefbbfaf593920bf79acce 100644 (file)
@@ -17,9 +17,6 @@ import textwrap
 import paramiko
 from paramiko.ssh_exception import SSHException
 
-from fb_tools.common import pp, to_str, is_sequence, to_bool
-from fb_tools.xlate import format_list
-
 # Own modules
 
 from .. import print_section_start, print_section_end
@@ -28,7 +25,7 @@ from ..errors import ExpectedCobblerError
 
 from ..xlate import XLATOR
 
-__version__ = '0.1.0'
+__version__ = '0.1.1'
 
 LOG = logging.getLogger(__name__)
 
index 7a85f0d75e3bcf8a2618bb15b9a5834656d44037..b8e649b1323d010bc118723b6948025e9284e65a 100644 (file)
@@ -20,15 +20,14 @@ import jinja2
 
 from six.moves import configparser
 
-from fb_tools.common import pp, to_str, is_sequence, to_bool
-from fb_tools.xlate import format_list
+from fb_tools.common import pp, to_bool
 
 # Own modules
 from .. import print_section_start, print_section_end
-from ..errors import CobblerError, ExpectedCobblerError
+from ..errors import ExpectedCobblerError
 from ..xlate import XLATOR
 
-__version__ = '0.1.0'
+__version__ = '0.1.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -41,6 +40,8 @@ class CobblerProfile():
     A mixin class for extending the Cobbler class for profile dependend methods.
     """
 
+    profile_comment_tpl = "Profile for creating a {} VM."
+
     # -------------------------------------------------------------------------
     def get_profile_list(self):
         """Trying to get a list of all configured cobbler profiles."""
@@ -165,19 +166,43 @@ class CobblerProfile():
     def _change_profile(self, profile_vars):
 
         profile = self.cfg.cobbler_profile
-        distro = self.cfg.cobbler_distro
         distro_info = self.cfg.current_distro
-        status = self.cfg.system_status
 
         LOG.debug(_("Checking existing profile {n!r} ({d}) ...").format(
             n=profile, d=distro_info.description))
 
-        repos = []
-        if distro_info.repos:
-            repos = distro_info.repos.as_list()
-        repos_str = ' '.join(repos)
+        args = self._get_profile_change_attribs(profile_vars)
+        if not args:
+            LOG.debug(_("No need for changing profile {!r}").format(profile))
+            return
+
+        args = ['profile', 'edit', '--name', profile] + args
+
+        if self.verbose > 1:
+            LOG.debug('Arguments for changing profile:\n' + pp(args))
+        return
+
+        proc = self.exec_cobbler(args)
+
+        if proc.returncode:
+            err = _('No error message')
+            if proc.stderr:
+                err = proc.stderr
+            elif proc.stdout:
+                err = proc.stdout
+            msg = _("Error editing a cobbler profile - returncode was {rc}: {err}").format(
+                rc=proc.returncode, err=err)
+            raise ExpectedCobblerError(msg)
+
+    # -------------------------------------------------------------------------
+    def _get_profile_change_attribs(self, profile_vars):
+
+        distro = self.cfg.cobbler_distro
+        distro_info = self.cfg.current_distro
+        repos_str = distro_info.repos_string
+        comment = self.profile_comment_tpl.format(distro_info.description)
+        status = self.cfg.system_status
 
-        comment = "Profile for creating a {} VM.".format(distro_info.description)
         name_servers = '[' + ', '.join(
             map(lambda x: "'" + x + "'", self.cfg.cobbler_nameservers)) + ']'
         dns_search = '[' + ', '.join(
@@ -197,14 +222,9 @@ class CobblerProfile():
             args.append('--enable-menu')
             args.append('1')
 
-        if self.cfg.cobbler_major_version == 3:
-            if profile_vars['autoinstall'] != str(self.cfg.cobbler_profile_ks.name):
-                args.append('--autoinstall')
-                args.append(str(self.cfg.cobbler_profile_ks.name))
-        else:
-            if profile_vars['kickstart'] != str(self.cfg.cobbler_profile_ks):
-                args.append('--kickstart')
-                args.append(str(self.cfg.cobbler_profile_ks))
+        if profile_vars['autoinstall'] != str(self.cfg.cobbler_profile_ks.name):
+            args.append('--autoinstall')
+            args.append(str(self.cfg.cobbler_profile_ks.name))
 
         if self.verbose > 1:
             msg = _("Checking for repos:") + ' ' + repos_str
@@ -231,31 +251,7 @@ class CobblerProfile():
             args.append('--name-servers-search')
             args.append(' '.join(self.cfg.cobbler_dns_search))
 
-        ks_meta_ok = True
-        ks_meta_vars = {}
-        if 'autoinstall_meta' in profile_vars:
-            ks_meta_vars = self.xform_ks_meta(profile_vars['autoinstall_meta'])
-        if 'ROOT_PWD_HASH' not in ks_meta_vars:
-            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('ROOT_PWD_HASH'))
-            ks_meta_ok = False
-        if ('SWAP_SIZE_MB' not in ks_meta_vars or
-                ks_meta_vars['SWAP_SIZE_MB'] != str(self.cfg.swap_size_mb)):
-            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('SWAP_SIZE_MB'))
-            ks_meta_ok = False
-        if ('SYSTEM_STATUS' not in ks_meta_vars or
-                ks_meta_vars['SYSTEM_STATUS'] != status):
-            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('SYSTEM_STATUS'))
-            ks_meta_ok = False
-        if ('WS_REL_FILESDIR' not in ks_meta_vars or
-                ks_meta_vars['WS_REL_FILESDIR'] != str(self.cfg.cobbler_ws_rel_filesdir)):
-            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('WS_REL_FILESDIR'))
-            ks_meta_ok = False
-        if ('COBBLER_URL' not in ks_meta_vars or
-                ks_meta_vars['COBBLER_URL'] != "http://{}".format(self.cfg.cobbler_host)):
-            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('COBBLER_URL'))
-            ks_meta_ok = False
-
-        if not ks_meta_ok:
+        if not self._check_profile_ks_metavars(profile_vars):
             ks_meta_list = []
             ks_meta_list.append("ROOT_PWD_HASH={}".format(self.cfg.get_root_pwd_hash()))
             ks_meta_list.append("SWAP_SIZE_MB={}".format(self.cfg.swap_size_mb))
@@ -269,29 +265,45 @@ class CobblerProfile():
             args.append(ks_meta)
 
         if self.verbose:
-            LOG.debug("Args for 'profile edit:\n{}".format(pp(args)))
+            LOG.debug(_("Arguments for editing the profile:") + '\n' + pp(args))
 
-        if not args:
-            LOG.debug(_("No need for changing profile {!r}").format(profile))
-            return
+        return args
 
-        args = ['profile', 'edit', '--name', profile] + args
+    # -------------------------------------------------------------------------
+    def _check_profile_ks_metavars(self, profile_vars):
 
-        if self.verbose > 1:
-            LOG.debug('Arguments for changing profile:\n' + pp(args))
-        return
+        status = self.cfg.system_status
 
-        proc = self.exec_cobbler(args)
+        ks_meta_ok = True
+        ks_meta_vars = {}
 
-        if proc.returncode:
-            err = _('No error message')
-            if proc.stderr:
-                err = proc.stderr
-            elif proc.stdout:
-                err = proc.stdout
-            msg = _("Error editing a cobbler profile - returncode was {rc}: {err}").format(
-                rc=proc.returncode, err=err)
-            raise ExpectedCobblerError(msg)
+        if 'autoinstall_meta' in profile_vars:
+            ks_meta_vars = self.xform_ks_meta(profile_vars['autoinstall_meta'])
+
+        if 'ROOT_PWD_HASH' not in ks_meta_vars:
+            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('ROOT_PWD_HASH'))
+            ks_meta_ok = False
+
+        if 'SWAP_SIZE_MB' not in ks_meta_vars or \
+                ks_meta_vars['SWAP_SIZE_MB'] != str(self.cfg.swap_size_mb):
+            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('SWAP_SIZE_MB'))
+            ks_meta_ok = False
+
+        if 'SYSTEM_STATUS' not in ks_meta_vars or \
+                ks_meta_vars['SYSTEM_STATUS'] != status:
+            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('SYSTEM_STATUS'))
+            ks_meta_ok = False
+
+        if 'WS_REL_FILESDIR' not in ks_meta_vars or \
+                ks_meta_vars['WS_REL_FILESDIR'] != str(self.cfg.cobbler_ws_rel_filesdir):
+            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('WS_REL_FILESDIR'))
+            ks_meta_ok = False
+        if 'COBBLER_URL' not in ks_meta_vars or \
+                ks_meta_vars['COBBLER_URL'] != "http://{}".format(self.cfg.cobbler_host):
+            LOG.debug(_('Profile ks_meta {!r} is not ok.').format('COBBLER_URL'))
+            ks_meta_ok = False
+
+        return ks_meta_ok
 
     # -------------------------------------------------------------------------
     def add_profile(self):
@@ -302,7 +314,7 @@ class CobblerProfile():
         LOG.info(_("Creating new profile {!r} ...").format(profile))
 
         distro_info = self.cfg.current_distro
-        comment = "Profile for creating a {} VM.".format(distro_info.description)
+        comment = self.profile_comment_tpl.format(distro_info.description)
         status = self.cfg.system_status
 
         LOG.debug("Using kickstart file {!r}".format(self.cfg.cobbler_profile_ks))
index 407950ccdf327b7f34e39e4f8c585cc16cafa11b..4522e711b30313c8df372eeb6746b3e1b5849ced 100644 (file)
@@ -10,25 +10,16 @@ from __future__ import absolute_import, print_function
 
 # Standard modules
 import logging
-import os
-import tempfile
-
-from pathlib import Path
 
 # Third party modules
 import jinja2
 
-from six.moves import configparser
-
-from fb_tools.common import pp, to_str, is_sequence, to_bool
-from fb_tools.xlate import format_list
-
 # Own modules
 from .. import print_section_start, print_section_end
-from ..errors import CobblerError, ExpectedCobblerError
+from ..errors import ExpectedCobblerError
 from ..xlate import XLATOR
 
-__version__ = '0.1.0'
+__version__ = '0.1.1'
 
 LOG = logging.getLogger(__name__)
 
index e799a576f4bfa97369c4e74f96dc01928a773ee3..53d27d30d0244063501964c5823efb28dd5a1d1b 100644 (file)
@@ -35,7 +35,7 @@ from .errors import CrTplConfigError
 
 from .xlate import XLATOR
 
-__version__ = '2.3.1'
+__version__ = '2.3.3'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -332,7 +332,7 @@ class LdapConnectionInfo(FbBaseObject):
                 new.admin_filter = value
                 continue
 
-            if key.lower() in ['is_admin', 'readonly', 'tier', 'sync-source' ]:
+            if key.lower() in ['is_admin', 'readonly', 'tier', 'sync-source']:
                 continue
 
             msg = _("Unknown LDAP configuration key {key} found in section {sec!r}.").format(
@@ -543,6 +543,14 @@ class CobblerDistroInfo(FbGenericBaseObject):
             return
         self._ks_template = template
 
+    # -------------------------------------------------------------------------
+    @property
+    def repos_string(self):
+        """Returns all repos as a string of their space concatinated names."""
+        if self.repos:
+            return ' '.join(self.repos.as_list())
+        return ''
+
     # -------------------------------------------------------------------------
     def __repr__(self):
         """Typecasting into a string for reproduction."""
@@ -583,6 +591,7 @@ class CobblerDistroInfo(FbGenericBaseObject):
         res['ks_repo_url'] = self.ks_repo_url
         res['ks_template'] = self.ks_template
         res['name'] = self.name
+        res['repos_string'] = self.repos_string
         res['shortname'] = self.shortname
 
         return res
@@ -1661,7 +1670,7 @@ class CrTplConfiguration(BaseMultiConfig):
     def strip_unnessecary(self):
         """Stripping no more necessary stuff."""
         LOG.debug(_("Stripping no more necessary stuff from configuration ..."))
+
         if self.verbose > 1:
             LOG.debug(_("Stripping {!r} ...").format('cfg.cobbler-distros'))
         if 'cobbler-distros' in self.cfg:
index 4b89feecacd72dcc4e16cac29d6aa4a7ecb20132..d38ae965295dcb121d96149a2963b39e39028a8a 100644 (file)
@@ -14,7 +14,6 @@ from __future__ import absolute_import
 # Third party modules
 
 from fb_tools.errors import FbAppError
-from fb_tools.errors import FbHandlerError
 from fb_tools.errors import HandlerError, ExpectedHandlerError
 from fb_tools.multi_config import MultiConfigError