# This template creates a cloud-init network configuration,
# based upon these input values:
#
# .Node: the Node from a ViNO CR
# .Networks: the list of Networks from a ViNO CR
# .Generated: host-specific info generated/calculated by ViNO itself
apiVersion: v1
kind: Secret
metadata:
  name: test-template
  namespace: default
type: Opaque
stringData:
  template: |
    {{ $netToIface := dict }}
    links:
      {{- range .Node.NetworkInterfaces }}
      - id: {{ .Name }}
        name: {{ .Name }}
        type: {{ .Type }}
        mtu: {{ .MTU }}
        ethernet_mac_address: {{ index $.Generated.MACAddresses .Name }}
        {{- if .Options -}}
        {{ range $key, $val := .Options }}
        {{ $key }}: {{ $val }}
        {{- end }}
        {{- end }}
        {{- /* Save the network->interface mapping, needed below */ -}}
        {{- $_ := set $netToIface .NetworkName .Name }}
      {{- end }}
    networks:
      {{- range .Networks }}
      - id: {{ .Name }}
        type: {{ .Type }}
        link: {{ index $netToIface .Name }}
        ip_address: {{ index $.Generated.IPAddresses .Name }}
        #netmask: "TODO - see if needed when ip has CIDR range"
        dns_nameservers: {{ .DNSServers }}
        {{- if .Routes }}
        routes:
        {{- range .Routes }}
          - network: {{ .Network }}
            {{ if .Netmask }}netmask: {{ .Netmask }}{{ end }}
            gateway: {{ .Gateway }}
        {{- end }}
        {{- end }}
      {{- end }}
    #services:
    # TODO: confirm dns_nameservers above does the trick here

