def render_subnet(network):
    network_options = network.keyvalue_set.filter(is_option=True)
    network_statements = network.keyvalue_set.filter(is_statement=True)
    network_raw_include = network.dhcpd_raw_include
    # All interface objects that are within this network and have enable_dhcp.
    # TODO, make this work with IPv6
    if network.ip_type == '6':
        raise NotImplemented()
    network.update_network()
    ip_lower_start = int(network.network.network)
    ip_lower_end = int(network.network.broadcast) - 1
    sregs = StaticReg.objects.filter(
        ip_upper=0,
        ip_lower__gte=ip_lower_start,
        ip_lower__lte=ip_lower_end,
        ip_type='4'
    ).select_related()
    ranges = network.range_set.all()

    # Let's assume all options need a ';' appended.
    build_str = "# Generated DHCP \n\n"
    build_str += "subnet {0} netmask {1} {{\n\n".format(
        network, network.network.netmask)
    build_str += "\t# Network Statements\n"
    build_str += render_statements(network_statements)
    build_str += "\t# Network Options\n"
    build_str += render_options(network_options)

    if network_raw_include:
        for line in network_raw_include.split('\n'):
            build_str += "\t{0}\n".format(line)
    build_str += "\n"

    for mrange in ranges:
        build_str += render_pool(mrange)

    build_str += render_sregs(sregs)

    build_str += "}"
    return build_str
The core function of building DHCP files.
dataset/ETHPy150Open mozilla/inventory/core/dhcp/render.py/render_subnet