main.py
changeset 5 86b05c0ab5cd
parent 2 e66102ab7048
--- a/main.py	Thu Apr 02 22:52:26 2009 +0300
+++ b/main.py	Thu Apr 02 23:59:31 2009 +0300
@@ -1,6 +1,6 @@
 #!/usr/bin/env python2.5
 
-import data, dhcp_conf, dhcp
+import data, dhcp, bind_conf, bind
 
 import optparse, itertools
 
@@ -14,7 +14,9 @@
 
     # define our options
     parser = optparse.OptionParser(usage=usage)
-    parser.add_option('--dhcpd-conf',    dest='dhcpd_conf', metavar='PATH', help="path to dhcpd.conf", default='/etc/dhcp3/dhcpd.conf')
+    parser.add_option('--dhcpd-conf',   dest='dhcpd_conf',      metavar="PATH", help="path to dhcpd.conf", default='/etc/dhcp3/dhcpd.conf')
+    parser.add_option('--bind-zone',    dest='bind_zone',       metavar="PATH", help="path to bind zone file", default=None)
+    parser.add_option('--autoserial',   dest='autoserial_path', metavar="PATH", help="path to autoserial file", default='autoserial')
     
     # parse them
     options, args = parser.parse_args(args=argv[1:])
@@ -30,7 +32,7 @@
         Write the DHCP config module using the data loaded from the given module
     """
     
-    # build the config f file
+    # build the config file
     config = dhcp.Config(path=options.dhcpd_conf,
         settings        = settings.dhcp_settings,
         options         = settings.dhcp_options,
@@ -42,6 +44,28 @@
     # write it out
     config.write()
 
+def write_bind (options, settings) :
+    """
+        Write a BIND config for a forward zone
+    """
+
+    assert options.bind_zone
+
+    # load the serial
+    autoserial = bind.AutoSerial(options.autoserial_path)
+
+    # build the zone file
+    zone = bind.Domain(domain=settings.domain, path=options.bind_zone,
+            nameservers     = settings.nameservers,
+            mailservers     = [((i+1)*10, label) for i, label in enumerate(settings.mailservers)],
+            serial          = autoserial.serial(),
+            settings        = settings.bind_settings,
+            objs            = itertools.chain(*[host.build_bind_domain_records(settings.domain) for host in settings.hosts]),
+    )
+
+    # write it out
+    zone.write()
+
 def main (argv) :
     """
         Our app entry point, parse args, load data, write out the config files
@@ -55,6 +79,7 @@
     
     # write out the config files
     write_dhcp(options, data_module)
+    write_bind(options, data_module)
 
 if __name__ == '__main__' :
     from sys import argv