diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | cobbler/modules/manage_isc.py | 53 | ||||
-rw-r--r-- | cobbler/templar.py | 4 | ||||
-rw-r--r-- | templates/dhcp.template | 32 |
4 files changed, 57 insertions, 33 deletions
@@ -7,6 +7,7 @@ Cobbler CHANGELOG - added cobbler find command to do searches from the command line - fix mkdir invocation - improved cobbler replicate, it now can rsync needed files +- further templatize ISC dhcp config file (pay attention to /etc/cobbler/dhcp.template.rpmnew !) - Wed Jun 03 2008 - 1.0.3 - Fix error message output from failed kickstart rendering diff --git a/cobbler/modules/manage_isc.py b/cobbler/modules/manage_isc.py index c3982707..ba5f21cd 100644 --- a/cobbler/modules/manage_isc.py +++ b/cobbler/modules/manage_isc.py @@ -145,13 +145,12 @@ class IscManager: # from those that care about Itanium. elilo seems to be unmaintained # so additional maintaince in other areas may be required to keep # this working. - elilo = os.path.basename(self.settings.bootloaders["ia64"]) - system_definitions = {} + # use a simple counter for generating generic names where a hostname + # is not available counter = 0 - # Clean system definitions in /var/lib/dhcpd/dhcpd.leases just in # case to avoid conflicts with the hosts we're defining and to clean # possible removed hosts (only if using OMAPI) @@ -169,45 +168,43 @@ class IscManager: # we used to just loop through each system, but now we must loop # through each network interface of each system. - + dhcp_tags = { "default": {} } + for system in self.systems: profile = system.get_conceptual_parent() distro = profile.get_conceptual_parent() for (name, interface) in system.interfaces.iteritems(): - mac = interface["mac_address"] ip = interface["ip_address"] host = interface["hostname"] + # add references to the system, profile, and distro + # for use in the template + interface["system"] = utils.blender( self.api, False, system ) + interface["profile"] = utils.blender( self.api, False, profile ) + interface["distro"] = distro.to_datastruct() + if mac is None or mac == "": # can't write a DHCP entry for this system continue counter = counter + 1 - systxt = "" - # the label the entry after the hostname if possible if host is not None and host != "": - systxt = "\nhost %s {\n" % host - if self.settings.isc_set_host_name: - systxt = systxt + " option host-name = \"%s\";\n" % host + interface["name"] = host else: - systxt = "\nhost generic%d {\n" % counter + interface["name"] = "generic%d" % counter + interface["filename"] = "/pxelinux.0" + # can't use pxelinux.0 anymore if distro.arch == "ia64": - # can't use pxelinux.0 anymore - systxt = systxt + " filename \"/%s\";\n" % elilo - systxt = systxt + " hardware ethernet %s;\n" % mac - if ip is not None and ip != "": - systxt = systxt + " fixed-address %s;\n" % ip - systxt = systxt + "}\n" + interface["filename"] = elilo # 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) - if ip is not None and ip != "": if mac is not None and mac != "": if host is not None and host != "": @@ -219,28 +216,24 @@ class IscManager: if dhcp_tag == "": dhcp_tag = "default" - if not system_definitions.has_key(dhcp_tag): - system_definitions[dhcp_tag] = "" - system_definitions[dhcp_tag] = system_definitions[dhcp_tag] + systxt + if not dhcp_tags.has_key(dhcp_tag): + dhcp_tags[dhcp_tag] = { + mac: interface + } + else: + dhcp_tags[dhcp_tag][mac] = interface # we are now done with the looping through each interface of each system - metadata = { "omapi_enabled" : self.settings.omapi_enabled, "omapi_port" : self.settings.omapi_port, - "insert_cobbler_system_definitions" : system_definitions.get("default",""), "date" : time.asctime(time.gmtime()), "cobbler_server" : self.settings.server, "next_server" : self.settings.next_server, - "elilo" : elilo + "elilo" : elilo, + "dhcp_tags" : dhcp_tags } - # now add in other DHCP expansions that are not tagged with "default" - for x in system_definitions.keys(): - if x == "default": - continue - metadata["insert_cobbler_system_definitions_%s" % x] = system_definitions[x] - self.templar.render(template_data, metadata, settings_file, None) def regen_ethers(self): diff --git a/cobbler/templar.py b/cobbler/templar.py index edfd5f2c..f39baf57 100644 --- a/cobbler/templar.py +++ b/cobbler/templar.py @@ -86,8 +86,8 @@ class Templar: try: data_out = str(t) except: - print _("There appears to be an formatting error in the template file.") - print _("For completeness, the traceback from Cheetah has been included below.") + print "There appears to be an formatting error in the template file." + print "For completeness, the traceback from Cheetah has been included below." raise # now apply some magic post-filtering that is used by cobbler import and some diff --git a/templates/dhcp.template b/templates/dhcp.template index 344b108f..0204d1f5 100644 --- a/templates/dhcp.template +++ b/templates/dhcp.template @@ -26,5 +26,35 @@ subnet 192.168.1.0 netmask 255.255.255.0 { next-server $next_server; } -$insert_cobbler_system_definitions +#for dhcp_tag in $dhcp_tags.keys(): + ## group could be subnet if your dhcp tags line up with your subnets + ## or really any valid dhcpd.conf construct ... if you only use the + ## default dhcp tag in cobbler, the group block can be deleted for a + ## flat configuration +# group for Cobbler DHCP tag: $dhcp_tag +group { + #for mac in $dhcp_tags[$dhcp_tag].keys(): + #set iface = $dhcp_tags[$dhcp_tag][$mac] + host $iface.name { + hardware ethernet $mac; + #if $iface.ip_address: + fixed-address $iface.ip_address; + #end if + #if $iface.subnet: + option subnet-mask $iface.subnet; + #end if + #if $iface.gateway: + option routers $iface.gateway; + #end if + #if $iface.system.netboot_enabled: + filename "$iface.filename"; + ## Cobbler defaults to $next_server, but some users + ## like to use $iface.system.server for proxied setups + next-server $next_server; + ## next-server $iface.system.server; + #end if + } + #end for +} +#end for |