]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Generating named config file for slave zones
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 8 Aug 2017 12:25:18 +0000 (14:25 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 8 Aug 2017 12:25:18 +0000 (14:25 +0200)
pp_lib/config_named_app.py

index dd78cd517b313371bc45b4113055765c1e1c698f..47b676093060c0bea906279e101bffc19a1b5009 100644 (file)
@@ -39,7 +39,7 @@ from .cfg_app import PpCfgAppError, PpConfigApplication
 
 from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
 
-__version__ = '0.5.6'
+__version__ = '0.6.1'
 LOG = logging.getLogger(__name__)
 
 
@@ -815,6 +815,7 @@ class PpConfigNamedApp(PpConfigApplication):
         self.generate_acl_file()
         self.generate_named_conf()
         self.generate_log_cfg_file()
+        self.generate_slave_cfg_file()
 
         time.sleep(2)
 
@@ -1161,7 +1162,6 @@ class PpConfigNamedApp(PpConfigApplication):
 
             content += '\n'.join(lines) + '\n'
 
-
         content += '\n};\n'
         content += '\n// vim: ts=8 filetype=named noet noai\n'
 
@@ -1171,6 +1171,71 @@ class PpConfigNamedApp(PpConfigApplication):
         if self.verbose > 2:
             LOG.debug("Generated {!r}:\n{}".format(self.temp_log_cfg_file, content.strip()))
 
+    # -------------------------------------------------------------------------
+    def generate_slave_cfg_file(self):
+
+        LOG.info("Generating {} ...".format(self.default_named_zones_cfg_file))
+
+        cur_date = datetime.datetime.now().isoformat(' ')
+        re_rev = re.compile(r'^rev\.', re.IGNORECASE)
+        re_trail_dot = re.compile(r'\.+$')
+
+        lines = []
+        lines.append('###############################################################')
+        lines.append('')
+        lines.append(' Bind9 configuration file for slave sones')
+        lines.append(' {}'.format(self.named_zones_cfg_file))
+        lines.append('')
+        lines.append(' Generated at: {}'.format(cur_date))
+        lines.append('')
+        lines.append('###############################################################')
+        header = textwrap.indent('\n'.join(lines), '//', lambda line: True) + '\n'
+
+        content = header
+
+        for zone in self.zones:
+
+            account = str(zone['account']).lower().strip()
+
+            zname = re_trail_dot.sub('', zone['name'])
+            show_name = zone['canonical_name']
+            show_name = re_rev.sub('Reverse ', show_name)
+            show_name = re_trail_dot.sub('', show_name)
+            if account.startswith('intern') or account.startswith('local'):
+                if not self.is_internal:
+                    LOG.debug("Ignoring zone {!r}, because it's an internal zone.".format(zname))
+                    continue
+            else:
+                if self.is_internal:
+                    LOG.debug("Ignoring zone {!r}, because it's a public zone.".format(zname))
+                    continue
+
+            zfile = os.path.join(
+                self.named_slavedir_rel, re_trail_dot.sub('', zone['canonical_name']) + '.zone')
+
+            lines = []
+            lines.append('')
+            lines.append('// {}'.format(show_name))
+            lines.append('zone "{}" in {{'.format(zname))
+            lines.append('\tmasters {')
+            for master in self.zone_masters:
+                lines.append('\t\t{};'.format(master))
+            lines.append('\t};')
+            lines.append('\ttype slave;')
+            lines.append('\tfile "{}";'.format(zfile))
+            lines.append('};')
+
+            content += '\n'.join(lines) + '\n'
+
+        content += '\n// vim: ts=8 filetype=named noet noai\n'
+
+        with open(self.temp_zones_cfg_file, 'w', **self.open_args) as fh:
+            fh.write(content)
+
+        if self.verbose > 2:
+            LOG.debug("Generated {!r}:\n{}".format(self.temp_zones_cfg_file, content.strip()))
+
+
     # -------------------------------------------------------------------------
     def get_api_zones(self):
 
@@ -1243,6 +1308,9 @@ class PpConfigNamedApp(PpConfigApplication):
             if match:
                 prefix = self._get_ipv4_prefix(match.group(1))
                 if prefix:
+                    if prefix == '127.0.0':
+                        LOG.debug("Pure local zone {!r} will not be considered.".format(prefix))
+                        continue
                     uni_name = 'rev.' + prefix
 
             if not uni_name: