From 96f257ae786dd49ed9c8e60a38d5551498623f49 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 23 Jun 2020 18:16:05 +0200 Subject: [PATCH] Applying flake8 rules --- lib/cr_vmware_tpl/cobbler.py | 14 +++++--------- lib/cr_vmware_tpl/config.py | 8 +++++--- lib/cr_vmware_tpl/handler.py | 23 ++++++++++++++++------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index e12e8e7..b1bba83 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -40,7 +40,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.6.2' +__version__ = '0.6.3' LOG = logging.getLogger(__name__) @@ -190,7 +190,6 @@ class Cobbler(BaseHandler): def scp_to(self, local_file, remote_file): ssh = None - proc = None try: @@ -313,8 +312,8 @@ class Cobbler(BaseHandler): elif proc.stdout: err = proc.stdout msg = _( - "{dsc} {rdir!r} on host {host!r} could not be created: {err}").format( - dsc=dsc, rdir=str(rdir), host=self.host, err=err) + "{dsc} {rdir!r} on host {host!r} could not be created: {err}").format( + dsc=dsc, rdir=str(rdir), host=self.host, err=err) raise ExpectedCobblerError(msg) # ------------------------------------------------------------------------- @@ -323,7 +322,6 @@ class Cobbler(BaseHandler): 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: @@ -339,7 +337,6 @@ class Cobbler(BaseHandler): profile_list = [] proc = self.exec_cobbler(('profile', 'list'), no_simulate=True) - lines = proc.stdout.splitlines() for line in proc.stdout.splitlines(): profile = line.strip() if profile: @@ -464,7 +461,6 @@ class Cobbler(BaseHandler): """Ensure correctnes of an existing profile.""" profile = self.config.cobbler_profile - distro = self.config.cobbler_distro LOG.debug(_("Checking existing profile {!r} ...").format(profile)) remote_file = ( @@ -551,7 +547,6 @@ class Cobbler(BaseHandler): """Creating a new profile.""" profile = self.config.cobbler_profile - distro = self.config.cobbler_distro LOG.info(_("Creating new profile {!r} ...").format(profile)) @@ -868,7 +863,7 @@ class Cobbler(BaseHandler): cur_ip = str(ip) except ValueError as e: msg = _("Found invalid IP address {ip!r} in leases file: {err}").format( - ip=match.group(1), err=e) + ip=match.group(1), err=e) LOG.error(msg) continue @@ -885,6 +880,7 @@ class Cobbler(BaseHandler): return assigments[mac] return None + # ============================================================================= if __name__ == "__main__": diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 3c6a696..db34fe2 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -22,7 +22,7 @@ from fb_tools.config import ConfigError, BaseConfiguration from .xlate import XLATOR -__version__ = '1.5.7' +__version__ = '1.5.8' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -588,8 +588,9 @@ class CrTplConfiguration(BaseConfiguration): else: msg = _( "The value of {what!r} must be one of {valid!r}, " - "but found {val!r}.").format(what='system_status', - valid=self.valid_system_status, val=value) + "but found {val!r}.").format( + what='system_status', + valid=self.valid_system_status, val=value) LOG.error(msg) continue @@ -615,6 +616,7 @@ class CrTplConfiguration(BaseConfiguration): return pwd_hash + # ============================================================================= if __name__ == "__main__": diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 35a807f..e99e391 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -38,11 +38,11 @@ from fb_tools.vsphere.iface import VsphereVmInterface from .config import CrTplConfiguration -from .cobbler import CobblerError, Cobbler +from .cobbler import Cobbler from .xlate import XLATOR -__version__ = '1.7.5' +__version__ = '1.7.6' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -288,9 +288,6 @@ class CrTplHandler(BaseHandler): LOG.info(_("Using MAC address of template VM: {!r}").format(self.tpl_macaddress)) tpl_sysname = 'template-' + self.tpl_vm_hostname - status = 'development' - if self.config.vsphere_host == 'vcs01.ppbrln.internal': - status = 'production' self.cobbler.add_system( name=tpl_sysname, fqdn=self.tpl_vm_fqdn, mac_address=self.tpl_macaddress) @@ -648,6 +645,18 @@ class CrTplHandler(BaseHandler): ssh = None + logfiles = ( + '/var/log/boot.log', + '/var/log/cron', + '/var/log/dnf*.log', + '/var/log/hawkey.log', + '/var/log/messages', + '/var/log/secure', + '/var/log/wtmp', + '/var/log/vmware-*.log*', + '/var/log/yum*.log', + ) + cmd = textwrap.dedent("""\ printf "Current host FQDN: " hostname -f @@ -670,7 +679,7 @@ class CrTplHandler(BaseHandler): echo "File /root/anakonda-ks.cfg not found." fi - for f in /var/log/boot.log /var/log/cron /var/log/dnf*.log /var/log/hawkey.log /var/log/messages /var/log/secure /var/log/wtmp /var/log/vmware-*.log* ; do + for f in @@@LOGFILES@@@ ; do if [ -f "${f}" ] ; then echo "Truncating ${f} ..." cp /dev/null "${f}" @@ -695,7 +704,7 @@ class CrTplHandler(BaseHandler): echo fi - """) + """).replace('@@@LOGFILES@@@', ' '.join(logfiles)) try: -- 2.39.5