from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.2.0'
+__version__ = '0.2.1'
LOG = logging.getLogger(__name__)
default_pdns_api_port = 8081
default_pdns_api_root_path = '/api/v1/servers/localhost'
default_named_conf = '/etc/named.conf'
+ default_named_zones_cfg_dir = '/etc/named'
default_named_basedir = '/var/named'
default_named_datadir = os.path.join(default_named_basedir, 'data')
default_named_slavedir = os.path.join(default_named_basedir, 'slaves')
self.is_internal = False
self.named_listen_on_v6 = False
self.named_conf = self.default_named_conf
+ self.named_zones_cfg_dir = self.default_named_zones_cfg_dir
self.zone_masters = copy.copy(self.default_zone_masters)
self.named_user = 'named'
else:
self.pdns_api_port = port
- if 'root_path' in section:
- path = section['root_path']
- if not os.path.isabs(path):
- msg = (
- "The root path of the PowerDNS must be an absolute pathname "
- "(found [{}]/root_path => {!r} in configuration.").format(section_name, path)
- LOG.error(msg)
- self.config_has_errors = True
- else:
- self.pdns_api_root_path = path
+ self._check_path_config(
+ section, section_name, 'root_path',
+ 'pdns_api_root_path', True, 'root path of the PowerDNS')
if 'key' in section:
key = section['key'].strip()
if 'query_log' in section:
self.query_log = to_bool(section['query_log'])
+ if 'listen_on_v6' in section and section['listen_on_v6'] is not None:
+ self.named_listen_on_v6 = to_bool(section['listen_on_v6'])
+
+ if 'dnssec' in section and section['dnssec'] is not None:
+ self.named_dnssec = to_bool(section['dnssec'])
+
+ self._check_path_config(section, section_name, 'named_conf', 'named_conf', True)
+ self._check_path_config(section, section_name, 'zones_cfg_dir', 'named_zones_cfg_dir', True)
+ self._check_path_config(section, section_name, 'base_dir', 'named_basedir', True)
+ self._check_path_config(section, section_name, 'data_dir', 'named_datadir', False)
+ self._check_path_config(section, section_name, 'slave_dir', 'named_slavedir', False)
+ self._check_path_config(
+ section, section_name, 'iscdlv_key_file', 'named_iscdlv_key_file', True)
+ self._check_path_config(section, section_name, 'run_dir', 'named_rundir', True)
+ self._check_path_config(section, section_name, 'log_dir', 'named_logdir', True)
+
+ if 'show_bind_version' in section and section['show_bind_version'] is not None:
+ self.named_show_bind_version = to_bool(section['show_bind_version'])
+
+ if 'version_to_show' in section and section['version_to_show'] is not None:
+ self.named_version2show = section['version_to_show'].strip()
+
+ if 'named_user' in section and section['named_user'] is not None:
+ self.named_user = section['named_user'].strip()
+ if 'named_group' in section and section['named_group'] is not None:
+ self.named_group = section['named_group'].strip()
+
if 'masters' in section:
self._get_masters_from_cfg(section['masters'], section_name)
+ # -------------------------------------------------------------------------
+ def _check_path_config(self, section, section_name, key, class_prop, absolute=True, desc=None):
+
+ if key not in section:
+ return
+
+ d = ''
+ if desc:
+ d = ' ' + str(desc).strip()
+
+ path = section[key].strip()
+ if not path:
+ msg = "No path given for{} [{}]/{} in configuration.".format(
+ d, section_name, key)
+ LOG.error(msg)
+ self.config_has_errors = True
+ return
+
+ if absolute and not os.path.isabs(path):
+ msg = "Path {!r} for{} [{}]/{} in configuration must be an absolute path.".format(
+ path, d, section_name, key)
+ LOG.error(msg)
+ self.config_has_errors = True
+ return
+
+ setattr(self, class_prop, path)
+
# -------------------------------------------------------------------------
def _get_masters_from_cfg(self, value, section_name):