# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
#
# ******************************************************************

#import netaddr

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option system-arch code 93 = unsigned integer 16;

subnet subnet_mask netmask net_mask {
option subnet-mask net_mask;
range dynamic-bootp start end;
default-lease-time default;
max-lease-time max;
next-server $next_server;
#insert the static DHCP leases for configuration here


     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

          # Legacy
          if option system-arch = 00:00 {
              filename "grub/grub.0";
          }
          # UEFI-32-1
          if option system-arch = 00:06 {
               # Not supported, no 32 bit UEFI grub executable
              filename "unsupported";
          }
          # UEFI-32-2
          if option system-arch = 00:02 {
              # Not supported, no 32 bit UEFI grub executable
              filename "unsupported";
          }
          # UEFI-64-1
          else if option system-arch = 00:07 {
              filename "grub/grubx64.efi";
          }
          # UEFI-64-2
          else if option system-arch = 00:08 {
              filename "grub/grubx64.efi";
          }
          # UEFI-64-3
          else if option system-arch = 00:09 {
              filename "grub/grubx64.efi";
          }
          # armv7   (aka arm 32 bit)
          else if option system-arch = 00:0a {
              filename "grub/armv7.efi";
          }
          # aarch64 (aka arm 64 bit)
          else if option system-arch = 00:0b {
              filename "grub/grubaa64.efi";
          }
          # RiskV 32 bit
          else if option system-arch = 00:25 {
              #ToDo petitboot loader
              filename "unsupported";
          }
          #RiskV 32 bit
          else if option system-arch = 00:27 {
              #ToDo petitboot loader
              filename "unsupported";
          }
          else if option system-arch = 00:0e {
              filename "grub/grub.ppc64le";
          }
          else
          {
              filename "grub/grub.0";
          }
     }
}

#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]
            #set mac_dhcp_format = netaddr.EUI($mac,dialect=netaddr.mac_unix)
            host $iface.name {
                #if $iface.interface_type == "infiniband":
                    option dhcp-client-identifier = $mac;
                #else
                    hardware ethernet $mac_dhcp_format;
                #end if
            #if $iface.ip_address:
                fixed-address $iface.ip_address;
            #end if
            #if $iface.dns_name:
               option host-name "$iface.dns_name";
            #else if $iface.hostname:
                option host-name "$iface.hostname";
            #end if
            #if $iface.netmask:
                option subnet-mask $iface.netmask;
            #end if
            #if $iface.if_gateway:
                option routers $iface.if_gateway;
            #else if $iface.gateway:
                option routers $iface.gateway;
            #end if
            #if "filename" in $iface.keys() and $iface.filename:
                #if $iface.enable_gpxe:
                    if exists user-class and option user-class = "gPXE" {
                        filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
                    } else if exists user-class and option user-class = "iPXE" {
                        filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
                    } else {
                        filename "undionly.kpxe";
                    }
                #else
                    filename "$iface.filename";
                #end if
            #end if
            #if $iface.next_server:
                next-server $iface.next_server;
            #end if
            #if $iface.filename:
                filename $filename
            #end if
            #if $iface.name_servers:
                #set $mynameservers = ','.join($iface.name_servers)
                option domain-name-servers $mynameservers;
            #end if
        }
    #end for
}
#end for
