From 8747e8f287f5abf9529247f255cf33bd11a528a7 Mon Sep 17 00:00:00 2001
From: Peter Vreman <peter.vreman@acision.com>
Date: Wed, 6 May 2009 12:39:38 +0200
Subject: [PATCH] fix and cleanup dhcp template generation

---
 cobbler/modules/manage_isc.py |   70 +++++++++++-----------------------------
 1 files changed, 19 insertions(+), 51 deletions(-)

diff --git a/cobbler/modules/manage_isc.py b/cobbler/modules/manage_isc.py
index 6abb3e1..dbd1934 100644
--- a/cobbler/modules/manage_isc.py
+++ b/cobbler/modules/manage_isc.py
@@ -179,74 +179,42 @@ class IscManager:
             if not system.is_management_supported(cidr_ok=False):
                 continue
 
-            profile = system.get_conceptual_parent()
-            distro  = profile.get_conceptual_parent()
-
-            # if distro is None then the profile is really an image
-            # record!
-
+            blended_system  = utils.blender( self.api, False, system )
             for (name, interface) in system.interfaces.iteritems():
-
-                # this is really not a per-interface setting
-                # but we do this to make the templates work
-                # without upgrade
-                interface["gateway"] = system.gateway
-
                 mac  = interface["mac_address"]
-                if interface["bonding"] == "slave":
-                    if interface["bonding_master"] not in system.interfaces:
-                        # Can't write DHCP entry; master interface does not
-                        # exist
-                        continue
-                    ip = system.interfaces[interface["bonding_master"]]["ip_address"]
-                    interface["ip_address"] = ip
-                    host = system.interfaces[interface["bonding_master"]]["dns_name"]
-                else:
-                    ip   = interface["ip_address"]
-                    host = interface["dns_name"]
-
-                if distro is not None:
-                    interface["distro"]  = distro.to_datastruct()
-
                 if mac is None or mac == "":
                     # can't write a DHCP entry for this system
                     continue
-
-                counter = counter + 1
+                    
+                if interface["bonding"] == "slave":
+                    if interface["bonding_master"] not in system.interfaces:
+                        # Can't write DHCP entry; master interface does not exists
+                        continue
+                    interface["ip_address"] = system.interfaces[interface["bonding_master"]]["ip_address"]
+                    interface["dns_name"] = system.interfaces[interface["bonding_master"]]["dns_name"]
 
                 # the label the entry after the hostname if possible
-                if host is not None and host != "":
-                    interface["name"] = "%s_%s"%(host,name)
-                else:
-                    interface["name"] = "generic%d" % counter
-
-                # add references to the system, profile, and distro
-                # for use in the template
-                if blender_cache.has_key(host):
-                    blended_system = blender_cache[host]
-                else:
-                    blended_system  = utils.blender( self.api, False, system )
-                    blender_cache[host] = blended_system
-
+                interface["name"] = "%s_%s"%(blended_system["name"],name)
                 interface["next_server"] = blended_system["server"]
                 interface["netboot_enabled"] = blended_system["netboot_enabled"]
                 interface["hostname"] = blended_system["hostname"]
+                interface["gateway"] = blended_system["gateway"]
 
-                interface["filename"] = "/pxelinux.0"
-                # can't use pxelinux.0 anymore
-                if distro is not None:
-                    if distro.arch == "ia64":
-                        interface["filename"] = elilo
-                    elif distro.arch.startswith("ppc"):
-                        interface["filename"] = yaboot
+                # Some architectures use a different loader than pxelinux.0
+                if blended_system["arch"] == "ia64":
+                    interface["filename"] = elilo
+                elif blended_system["arch"].startswith("ppc"):
+                    interface["filename"] = yaboot
+                else:
+                    interface["filename"] = "/pxelinux.0"
 
                 # If we have all values defined and we're using omapi,
                 # we will just create entries dinamically into DHCPD
                 # without requiring a restart (but file will be written
                 # as usual for having it working after restart)
-
+                ip   = interface["ip_address"]
+                host = interface["dns_name"]
                 if ip is not None and ip != "":
-                  if mac is not None and mac != "":
                     if host is not None and host != "":
                       if self.settings.omapi_enabled and self.settings.omapi_port:
                         self.remove_dhcp_lease(self.settings.omapi_port,host)
-- 
1.5.5.6

