'DHCP files are written when manage_dhcp is set in
/var/lib/cobbler/settings.'

def write_dhcp_file(self):

    settings_file = '/etc/dnsmasq.conf'
    template_file = '/etc/cobbler/dnsmasq.template'
    try:
        f2 = open(template_file, 'r')
    except:
        raise CX((_('error    writing    template    to    file:    %s') % template_file))
    template_data = ''
    template_data = f2.read()
    f2.close()
    system_definitions = {}
    counter = 0
    for system in self.systems:
        if (not system.is_management_supported(cidr_ok=False)):
            continue
        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['dns_name']
            ipv6 = interface['ipv6_address']
            if ((mac is None) or (mac == '')):
                continue
            counter += 1
            systxt = ((('dhcp-host=net:' + distro.arch.lower()) + ',') + mac)
            if ((host is not None) and (host != '')):
                systxt += (',' + host)
            if ((ip is not None) and (ip != '')):
                systxt += (',' + ip)
            if ((ipv6 is not None) and (ipv6 != '')):
                systxt += (',[%s]' % ipv6)
            systxt += '\n'
            dhcp_tag = interface['dhcp_tag']
            if (dhcp_tag == ''):
                dhcp_tag = 'default'
            if (dhcp_tag not in system_definitions):
                system_definitions[dhcp_tag] = ''
            system_definitions[dhcp_tag] = (system_definitions[dhcp_tag] + systxt)
    metadata = {'insert_cobbler_system_definitions': system_definitions.get('default', ''), 'date': time.asctime(time.gmtime()), 'cobbler_server': self.settings.server, 'next_server': self.settings.next_server}
    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)
