{{- $host := .BuildHost }}
{{- $time := .BuildTime }}
{{- $source := .BuildSource }}
{{- range $connection_id, $netdev := .NetDevs }}
{{- $filename := print "warewulf-" $connection_id  ".conf" }}
{{- file $filename }}
# This file is autogenerated by warewulf
# Host:   {{ $host }}
# Time:   {{ $time }}
# Source: {{ $source }}
[connection]
id={{ $connection_id }}
interface-name={{ $netdev.Device }}
{{ if $netdev.Type -}}
{{ if eq $netdev.Type "bond-slave" -}}
slave-type=bond
{{- $conn := split $connection_id "_" }}
{{- $master := index $conn 0 }}
master={{ $master }}
type=ethernet
{{ else }}
type={{ $netdev.Type }}
autoconnect=true
{{ end -}}
{{ end -}}

{{ if $netdev.Hwaddr -}}
{{ if eq $netdev.Type "ethernet" -}}
[ethernet]
mac-address={{ $netdev.Hwaddr }}
{{ if $netdev.MTU -}}
mtu={{ $netdev.MTU }}
{{ end -}}
{{ end -}}
{{ end -}}

# bond
{{ if eq $netdev.Type "bond" -}}
[ethernet]
{{ if $netdev.MTU -}}
mtu={{ $netdev.MTU }}
{{ end -}}

[bond]
downdelay=0
miimon=100
mode=802.3ad
xmit_hash_policy=layer2+3
updelay=0

{{ end -}}

{{ if eq $netdev.Type "infiniband" -}}
[infiniband]
transport-mode=datagram
{{ if $netdev.MTU -}}
mtu={{ $netdev.MTU }}
{{ end -}}
{{ end -}}

{{ if and ($netdev.IpCIDR) (ne $netdev.Type "bond-slave") -}}
[ipv4]
address={{ $netdev.IpCIDR }}
{{ if $netdev.Gateway -}}
gateway={{ $netdev.Gateway }}
{{ end -}}
method=manual
{{- $dns := "" }}
{{range $tk, $tv := $netdev.Tags -}}
{{ $prefix := slice $tk 0 3 -}}
{{ if eq $prefix "DNS" -}}
{{ $dns = print $dns $tv ";" -}}
{{ end -}}
{{ end -}}
{{ if ne $dns "" -}}
dns={{$dns}}
{{ end -}}
{{ end -}}

{{/* always autoconfigure ipv6 */}}
[ipv6]
addr-gen-mode=stable-privacy
method=ignore
never-default=true
{{ if $netdev.Ipaddr6 -}}
ipaddr="{{ $netdev.Ipaddr6 }}"
{{ end -}}
{{ end -}}
