#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
+@summary: A module for providing a configuration the dns-deploy-zones applications.
+
+ It's based on class PdnsConfiguration.
+
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2023 by Frank Brehm, Berlin
-@summary: A module for providing a configuration the dns-deploy-zones applications.
- It's based on class PdnsConfiguration.
"""
from __future__ import absolute_import
# Standard module
+import copy
import logging
import re
-import copy
import socket
-
from pathlib import Path
# Third party modules
-
-# Own modules
-
from fb_tools.common import is_sequence, to_bool
-
-# from .config import ConfigError, BaseConfiguration
from fb_tools.multi_config import DEFAULT_ENCODING
-from .pdns import PdnsConfigError, PdnsConfiguration
+# Own modules
+# from .config import ConfigError, BaseConfiguration
from .mail import DEFAULT_CONFIG_DIR
-
+from .pdns import PdnsConfigError, PdnsConfiguration
from .. import pp
-
from ..xlate import XLATOR
-__version__ = '0.2.3'
+__version__ = '0.2.4'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# =============================================================================
class DnsDeployZonesConfigError(PdnsConfigError):
- """Base error class for all exceptions happened during
- execution this configured application"""
+ """Base error class for all exceptions happened during execution a configured application."""
pass
# =============================================================================
class DnsDeployZonesConfig(PdnsConfiguration):
"""
- A class for providing a configuration for an arbitrary PowerDNS Application
- and methods to read it from configuration files.
+ A class for providing a configuration for an arbitrary PowerDNS Application.
+
+ It provides also methods to read from configuration files.
"""
default_pidfile = Path('/run/dns-deploy-zones.pid')
append_appname_to_stems=True, additional_stems=None, config_dir=DEFAULT_CONFIG_DIR,
additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
ensure_privacy=True, use_chardet=True, initialized=False):
-
+ """Initialize the DnsDeployZonesConfig object."""
self.pidfile = self.default_pidfile
self.keep_backup = self.default_keep_backup
# -------------------------------------------------------------------------
@property
def named_internal(self):
- """Is the BIND nameserver on the current host a local resolver (True)
- or an authoritative nameserver for outside."""
+ """
+ Return, whether the BIND nameserver is used as a local resolver.
+
+ Otherwise the BIND nameserver is used as an authoritative nameserver for outside.
+ """
return self._named_internal
@named_internal.setter
# -------------------------------------------------------------------------
@property
def named_listen_on_v6(self):
- """Is the BIND nameserver on the current listening on some IPv6 addresses?"""
+ """Return, whether the BIND nameserver on the current listening on some IPv6 addresses."""
return self._named_listen_on_v6
@named_listen_on_v6.setter
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
- Transforms the elements of the object into a dict
+ Transform the elements of the object into a dict.
@param short: don't include local properties in resulting dict.
@type short: bool
@return: structure as dict
@rtype: dict
"""
-
res = super(DnsDeployZonesConfig, self).as_dict(short=short)
res['default_pidfile'] = self.default_pidfile
# -------------------------------------------------------------------------
def eval_section(self, section_name):
-
+ """Evaluate a particular configuration section."""
super(DnsDeployZonesConfig, self).eval_section(section_name)
sn = section_name.lower()
def _eval_named(self, section_name, section):
if self.verbose > 2:
- msg = _("Evaluating config section {!r}:").format(section_name)
+ msg = _('Evaluating config section {!r}:').format(section_name)
LOG.debug(msg + '\n' + pp(section))
re_config_dir = re.compile(r'^\s*(?:named[_-]?)?conf(?:ig)?[_-]?dir\s*$', re.IGNORECASE)
m = m.strip().lower()
if self.verbose > 1:
- LOG.debug(_("Checking given master address {!r} ...").format(m))
+ LOG.debug(_('Checking given master address {!r} ...').format(m))
addr_list = self.get_addresses(m)
masters |= addr_list
# -------------------------------------------------------------------------
def get_addresses(self, host):
-
+ """Try to evaluate all IP addresses of the given hostname."""
addr_list = set()
if self.verbose > 3:
- msg = _("Trying to evaluate address of host {!r} ...").format(host)
+ msg = _('Trying to evaluate address of host {!r} ...').format(host)
LOG.debug(msg)
try:
addr = addr_info[4][0]
addr_list.add(addr)
except socket.gaierror as e:
- msg = _("Invalid hostname or address {a!r} found in masters: {e}")
+ msg = _('Invalid hostname or address {a!r} found in masters: {e}')
msg = msg.format(a=host, e=e)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
LOG.error(msg)
return set()
if self.verbose > 3:
- msg = _("Got addresses {a!r} for host {h!r}.")
+ msg = _('Got addresses {a!r} for host {h!r}.')
LOG.debug(msg.format(a=addr_list, h=host))
return addr_list
path = Path(val)
if not path.is_absolute():
- msg = _("The path to {what} must be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must be an absolute path, found {path!r}.')
msg = msg.format(what='rndc', path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what='rndc', path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what='rndc', path=val)
LOG.debug(msg)
self.rndc = path
path = Path(val)
if not path.is_absolute():
- msg = _("The path to {what} must be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must be an absolute path, found {path!r}.')
msg = msg.format(what='systemctl', path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what='systemctl', path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what='systemctl', path=val)
LOG.debug(msg)
self.systemctl = path
if not val:
return
- what = _("the named config directory")
+ what = _('the named config directory')
path = Path(val)
if not path.is_absolute():
- msg = _("The path to {what} must be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must be an absolute path, found {path!r}.')
msg = msg.format(what=what, path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what=what, path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what=what, path=val)
LOG.debug(msg)
self.named_conf_dir = path
if not val:
return
- what = _("the named config file for zones")
+ what = _('the named config file for zones')
path = Path(val)
if path.is_absolute():
- msg = _("The path to {what} must not be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must not be an absolute path, found {path!r}.')
msg = msg.format(what=what, path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what=what, path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what=what, path=val)
LOG.debug(msg)
self.named_zones_cfg_file = path
if not val:
return
- what = _("the named base directory")
+ what = _('the named base directory')
path = Path(val)
if not path.is_absolute():
- msg = _("The path to {what} must be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must be an absolute path, found {path!r}.')
msg = msg.format(what=what, path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what=what, path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what=what, path=val)
LOG.debug(msg)
self.named_basedir = path
if not val:
return
- what = _("the directory for slave zones of named")
+ what = _('the directory for slave zones of named')
path = Path(val)
if path.is_absolute():
- msg = _("The path to {what} must not be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must not be an absolute path, found {path!r}.')
msg = msg.format(what=what, path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what=what, path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what=what, path=val)
LOG.debug(msg)
self.named_slavedir = path
if not val:
return
- what = "named-checkconf"
+ what = 'named-checkconf'
path = Path(val)
if not path.is_absolute():
- msg = _("The path to {what} must be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must be an absolute path, found {path!r}.')
msg = msg.format(what=what, path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what=what, path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what=what, path=val)
LOG.debug(msg)
self.named_checkconf = path
def _eval_app(self, section_name, section):
if self.verbose > 2:
- msg = _("Evaluating config section {!r}:").format(section_name)
+ msg = _('Evaluating config section {!r}:').format(section_name)
LOG.debug(msg + '\n' + pp(section))
re_pidfile = re.compile(r'^\s*pid[_-]?file$', re.IGNORECASE)
if not val:
return
- what = _("the PID file")
+ what = _('the PID file')
path = Path(val)
if not path.is_absolute():
- msg = _("The path to {what} must be an absolute path, found {path!r}.")
+ msg = _('The path to {what} must be an absolute path, found {path!r}.')
msg = msg.format(what=what, path=val)
if self.raise_on_error:
raise DnsDeployZonesConfigError(msg)
return
if self.verbose > 2:
- msg = _("Found path to {what}: {path!r}.").format(what=what, path=val)
+ msg = _('Found path to {what}: {path!r}.').format(what=what, path=val)
LOG.debug(msg)
self.pidfile = path
self.keep_backup = to_bool(val)
# -------------------------------------------------------------------------
- def eval(self):
- """Evaluating read configuration and storing them in object properties."""
-
+ def eval(self): # noqa: A003
+ """Evaluate read configuration and storing it in object properties."""
super(DnsDeployZonesConfig, self).eval()
addr_list = set()
if self.masters:
if self.verbose > 2:
- LOG.debug(_("Using configured masters:") + '\n' + pp(self.masters))
+ LOG.debug(_('Using configured masters:') + '\n' + pp(self.masters))
else:
- LOG.warn(_("No valid masters found in configuration."))
+ LOG.warn(_('No valid masters found in configuration.'))
if self.verbose > 2:
- msg = _("Evaluated configuration:")
- msg += " " + pp(self.as_dict())
+ msg = _('Evaluated configuration:')
+ msg += ' ' + pp(self.as_dict())
# =============================================================================
-if __name__ == "__main__":
+if __name__ == '__main__':
pass