apiVersion: services.eda.nokia.com/v1
kind: VirtualNetwork
metadata:
  name: {{ name }}
  namespace: {{ namespace }}
{% if labels is defined and labels %}
  labels:
{% for k, v in labels.items() %}
    {{ k }}: {{ v | default('') }}
{% endfor %}
{% endif %}
spec:
{% if bridgeDomains is defined and bridgeDomains %}
  bridgeDomains:
{% for bd in bridgeDomains %}
  - name: {{ bd.name }}
    spec:
{% if bd.spec.eviPool is defined and bd.spec.eviPool is not none %}
      eviPool: {{ bd.spec.eviPool }}
{% endif %}
{% if bd.spec.macLearning is defined and bd.spec.macLearning is not none %}
      macLearning: {{ bd.spec.macLearning }}
{% endif %}
{% if bd.spec.tunnelIndexPool is defined and bd.spec.tunnelIndexPool is not none %}
      tunnelIndexPool: {{ bd.spec.tunnelIndexPool }}
{% endif %}
{% if bd.spec.type is defined and bd.spec.type is not none %}
      type: {{ bd.spec.type }}
{% endif %}
{% if bd.spec.vniPool is defined and bd.spec.vniPool is not none %}
      vniPool: {{ bd.spec.vniPool }}
{% endif %}
{% endfor %}
{% endif %}
{% if bridgeInterfaces is defined and bridgeInterfaces %}
  bridgeInterfaces: []
{% endif %}
{% if irbInterfaces is defined and irbInterfaces %}
  irbInterfaces:
{% for irb in irbInterfaces %}
  - name: {{ irb.name }}
    spec:
{% if irb.spec.arpTimeout is defined and irb.spec.arpTimeout is not none %}
      arpTimeout: {{ irb.spec.arpTimeout }}
{% endif %}
{% if irb.spec.bridgeDomain is defined and irb.spec.bridgeDomain is not none %}
      bridgeDomain: {{ irb.spec.bridgeDomain }}
{% endif %}
{% if irb.spec.ipAddresses is defined and irb.spec.ipAddresses %}
      ipAddresses:
{% for ip in irb.spec.ipAddresses %}
      - ipv4Address:
          ipPrefix: {{ ip.ipv4Address.ipPrefix }}
          primary: {{ ip.ipv4Address.primary | default(true) }}
{% endfor %}
{% endif %}
{% if irb.spec.ipMTU is defined and irb.spec.ipMTU is not none %}
      ipMTU: {{ irb.spec.ipMTU }}
{% endif %}
{% if irb.spec.learnUnsolicited is defined and irb.spec.learnUnsolicited is not none %}
      learnUnsolicited: {{ irb.spec.learnUnsolicited }}
{% endif %}
{% if irb.spec.router is defined and irb.spec.router is not none %}
      router: {{ irb.spec.router }}
{% endif %}
{% endfor %}
{% endif %}
{% if routers is defined and routers %}
  routers:
{% for r in routers %}
  - name: {{ r.name }}
    spec:
{% if r.spec.eviPool is defined and r.spec.eviPool is not none %}
      eviPool: {{ r.spec.eviPool }}
{% endif %}
{% if r.spec.tunnelIndexPool is defined and r.spec.tunnelIndexPool is not none %}
      tunnelIndexPool: {{ r.spec.tunnelIndexPool }}
{% endif %}
{% if r.spec.type is defined and r.spec.type is not none %}
      type: {{ r.spec.type }}
{% endif %}
{% if r.spec.vniPool is defined and r.spec.vniPool is not none %}
      vniPool: {{ r.spec.vniPool }}
{% endif %}
{% endfor %}
{% endif %}
{% if vlans is defined and vlans %}
  vlans:
{% for v in vlans %}
  - name: {{ v.name }}
    spec:
{% if v.spec.bridgeDomain is defined and v.spec.bridgeDomain is not none %}
      bridgeDomain: {{ v.spec.bridgeDomain }}
{% endif %}
{% if v.spec.interfaceSelector is defined and v.spec.interfaceSelector %}
      interfaceSelector:
{% for s in v.spec.interfaceSelector %}
      - {{ s }}
{% endfor %}
{% endif %}
{% if v.spec.vlanID is defined and v.spec.vlanID is not none %}
      vlanID: "{{ v.spec.vlanID }}"
{% endif %}
{% endfor %}
{% endif %}
