From 4c1b53987c34d7d826b1dd98bdcdcf2d86ab2e5b Mon Sep 17 00:00:00 2001
From: John Eckersberg <jeckersb@redhat.com>
Date: Mon, 5 May 2008 11:11:01 -0400
Subject: [PATCH] add zone-specific bind templating

---
 cobbler/modules/manage_bind.py |   29 ++++++++++++++++++++++-------
 cobbler/webui/master.py        |    7 ++++---
 docs/cobbler.pod               |    2 +-
 setup.py                       |    4 ++++
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/cobbler/modules/manage_bind.py b/cobbler/modules/manage_bind.py
index 900a832..e14122a 100644
--- a/cobbler/modules/manage_bind.py
+++ b/cobbler/modules/manage_bind.py
@@ -184,21 +184,20 @@ zone "%(arpa)s." {
 
     def __write_zone_files(self):
         """
-        Write out the forward and reverse zone files for all the zones
-        defined in manage_forward_zones and manage_reverse_zones
+        Write out the forward and reverse zone files for all configured zones
         """
-        template_file = "/etc/cobbler/zone.template"
+        default_template_file = "/etc/cobbler/zone.template"
         cobbler_server = self.settings.server
         serial = int(time.time())
         forward = self.__config_forward_zones()
         reverse = self.__config_reverse_zones()
 
         try:
-            f2 = open(template_file,"r")
+            f2 = open(default_template_file,"r")
         except:
-            raise CX(_("error reading template from file: %s") % template_file)
-        template_data = ""
-        template_data = f2.read()
+            raise CX(_("error reading template from file: %s") % default_template_file)
+        default_template_data = ""
+        default_template_data = f2.read()
         f2.close()
 
         for (zone, hosts) in forward.iteritems():
@@ -208,6 +207,14 @@ zone "%(arpa)s." {
                 'host_record': ''
             }
 
+            # grab zone-specific template if it exists
+            try:
+               fd = open('/etc/cobbler/zone_templates/%s' % zone)
+               template_data = fd.read()
+               fd.close()
+            except:
+               template_data = default_template_data
+
             for host in hosts:
                 txt = '%s\tIN\tA\t%s\n' % host
                 metadata['host_record'] = metadata['host_record'] + txt
@@ -221,6 +228,14 @@ zone "%(arpa)s." {
                 'host_record': ''
             }
 
+            # grab zone-specific template if it exists
+            try:
+               fd = open('/etc/cobbler/zone_templates/%s' % zone)
+               template_data = fd.read()
+               fd.close()
+            except:
+               template_data = default_template_data
+
             for host in hosts:
                 txt = '%s\tIN\tPTR\t%s\n' % host
                 metadata['host_record'] = metadata['host_record'] + txt
diff --git a/cobbler/webui/master.py b/cobbler/webui/master.py
index 7e54a2d..cdde14d 100644
--- a/cobbler/webui/master.py
+++ b/cobbler/webui/master.py
@@ -33,9 +33,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '2.0.1'
 __CHEETAH_versionTuple__ = (2, 0, 1, 'final', 0)
-__CHEETAH_genTime__ = 1209057202.737108
-__CHEETAH_genTimestamp__ = 'Thu Apr 24 13:13:22 2008'
-__CHEETAH_srcLastModified__ = 'Thu Apr 24 12:59:37 2008'
+__CHEETAH_genTime__ = 1209998447.8930521
+__CHEETAH_genTimestamp__ = 'Mon May  5 10:40:47 2008'
+__CHEETAH_src__ = 'webui_templates/master.tmpl'
+__CHEETAH_srcLastModified__ = 'Thu May  1 13:51:29 2008'
 __CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
diff --git a/docs/cobbler.pod b/docs/cobbler.pod
index 311a94c..018c3f4 100644
--- a/docs/cobbler.pod
+++ b/docs/cobbler.pod
@@ -563,7 +563,7 @@ Choose either "management = isc_and_bind" or "management = dnsmasq" in /etc/cobb
 
 This feature is off by default.  If using BIND, you may restrict the scope of zones managed with the options 'manage_forward_zones' and 'manage_reverse_zones'.  (See the Wiki for more information on this).
 
-If using BIND, Cobbler will use /etc/cobbler/bind.template and /etc/cobbler/zone.template as a starting point for the named.conf and individual zone files, respectively.  These files must be user edited for the user's particular networking environment.  Read the file and understand how BIND works before proceeding.
+If using BIND, Cobbler will use /etc/cobbler/bind.template and /etc/cobbler/zone.template as a starting point for the named.conf and individual zone files, respectively.  You may drop zone-specific template files in /etc/cobbler/zone_templates/name-of-zone which will override the default.  These files must be user edited for the user's particular networking environment.  Read the file and understand how BIND works before proceeding.
 
 If using dnsmasq, the template is /etc/cobbler/dnsmasq.template.  Read this file and understand how dnsmasq works before proceeding.
 
diff --git a/setup.py b/setup.py
index 442da5b..07d9880 100644
--- a/setup.py
+++ b/setup.py
@@ -41,6 +41,7 @@ if __name__ == "__main__":
         vw_systems    = "/var/www/cobbler/systems"
         vw_profiles   = "/var/www/cobbler/profiles"
         vw_links      = "/var/www/cobbler/links"
+        zone_templates = "/etc/cobbler/zone_templates"
         tftp_cfg      = "/tftpboot/pxelinux.cfg"
         tftp_images   = "/tftpboot/images"
         rotpath       = "/etc/logrotate.d"
@@ -134,6 +135,9 @@ if __name__ == "__main__":
                                 (vw_profiles,       []),
                                 (vw_links,          []),
 
+                                # zone-specific templates directory
+                                (zone_templates,    []),
+
                                 # tftp directories that we own
                                 (tftp_cfg,          []),
                                 (tftp_images,       []),
-- 
1.5.4.1

