From b333fb9f402795d73be65e3aefc22701c771b68e Mon Sep 17 00:00:00 2001
From: Peter Vreman <peter.vreman@acision.com>
Date: Fri, 8 May 2009 18:43:32 +0200
Subject: [PATCH] write subnets in dhcpd.conf based on network objects

---
 cobbler/item_network.py       |    4 ++++
 cobbler/modules/manage_isc.py |    2 ++
 templates/dhcp.template       |   34 +++++++++++++++++++++++-----------
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/cobbler/item_network.py b/cobbler/item_network.py
index ad10b82..8f34715 100644
--- a/cobbler/item_network.py
+++ b/cobbler/item_network.py
@@ -42,6 +42,7 @@ class Network(item.Item):
         self.cidr             = None
         self.address          = None
         self.gateway          = None
+        self.netmask          = None
         self.broadcast        = None
         self.name_servers     = []
         self.reserved         = []
@@ -58,6 +59,7 @@ class Network(item.Item):
         self.address          = _IP(self.load_item(seed_data, 'address', self.cidr[0]))
         self.gateway          = _IP(self.load_item(seed_data, 'gateway', self.cidr[-2]))
         self.broadcast        = _IP(self.load_item(seed_data, 'broadcast', self.cidr[-1]))
+        self.netmask          = _IP(self.load_item(seed_data, 'netmask', self.cidr.netmask()))
         self.name_servers     = self.load_item(seed_data, 'name_servers', '')
         self.reserved         = [_CIDR(c) for c in self.load_item(seed_data, 'reserved', [])]
         self.used_addresses   = self.load_item(seed_data, 'used_addresses', {})
@@ -315,6 +317,7 @@ class Network(item.Item):
             'name'           : self.name,
             'owners'         : self.owners,
             'cidr'           : str(self.cidr),
+            'netmask'        : str(self.netmask),
             'address'        : str(self.address),
             'gateway'        : str(self.gateway),
             'broadcast'      : str(self.broadcast),
@@ -330,6 +333,7 @@ class Network(item.Item):
     def printable(self):
         buf =       _("network          : %s\n") % self.name
         buf = buf + _("CIDR             : %s\n") % self.cidr
+        buf = buf + _("netmask          : %s\n") % self.netmask
         buf = buf + _("gateway          : %s\n") % self.gateway
         buf = buf + _("network address  : %s\n") % self.address
         buf = buf + _("broadcast        : %s\n") % self.broadcast
diff --git a/cobbler/modules/manage_isc.py b/cobbler/modules/manage_isc.py
index d5c659e..3a7fe2c 100644
--- a/cobbler/modules/manage_isc.py
+++ b/cobbler/modules/manage_isc.py
@@ -70,6 +70,7 @@ class IscManager:
         self.systems     = config.systems()
         self.settings    = config.settings()
         self.repos       = config.repos()
+        self.networks    = config.networks()
         self.templar     = templar.Templar(config)
 
     def write_dhcp_lease(self,port,host,ip,mac):
@@ -273,6 +274,7 @@ class IscManager:
            "next_server"    : self.settings.next_server,
            "elilo"          : elilo,
            "yaboot"         : yaboot,
+           "networks"       : self.networks,
            "dhcp_tags"      : dhcp_tags
         }
 
diff --git a/templates/dhcp.template b/templates/dhcp.template
index 46171fe..e3d7895 100644
--- a/templates/dhcp.template
+++ b/templates/dhcp.template
@@ -19,16 +19,28 @@ omapi-port $omapi_port;
 ignore client-updates;
 set vendorclass = option vendor-class-identifier;
 
-subnet 192.168.1.0 netmask 255.255.255.0 {
-     option routers             192.168.1.5;
-     option domain-name-servers 192.168.1.1;
-     option subnet-mask         255.255.255.0;
-     range dynamic-bootp        192.168.1.100 192.168.1.254;
-     filename                   "/pxelinux.0";
-     default-lease-time         21600;
-     max-lease-time             43200;
-     next-server                $next_server;
-}
+# subnet 192.168.1.0 netmask 255.255.255.0 {
+#     option routers             192.168.1.5;
+#     option domain-name-servers 192.168.1.1;
+#     option subnet-mask         255.255.255.0;
+#     range dynamic-bootp        192.168.1.100 192.168.1.254;
+#     filename                   "/pxelinux.0";
+#     default-lease-time         21600;
+#     max-lease-time             43200;
+#     next-server                $next_server;
+# }
+
+#for net in $networks
+  #if $net.dhcp_enabled
+subnet $net.address netmask $net.subnet {
+    #if $net.gateway
+  option routers $net.gateway
+    #end if
+    #if $net.subnet
+  option subnet-mask $net.subnet
+    #end if
+  #end if
+#end for
 
 #for dhcp_tag in $dhcp_tags.keys():
     ## group could be subnet if your dhcp tags line up with your subnets
@@ -57,7 +69,7 @@ group {
         ## Cobbler defaults to $next_server, but some users
         ## may like to use $iface.system.server for proxied setups
         next-server $next_server;
-        ## next-server $iface.next_server;
+        ## next-server $iface.system.server;
     }
         #end for
 }
-- 
1.5.5.6

