{% macro ip_addresses(intf,ipv6_ra,is_system) %}
{% if 'ipv4' in intf %}
    ipv4:
     address:
     - ip-prefix: "{{ intf.ipv4 }}"
{% if not is_system %}
       primary: [null]
{% endif %}
{% endif %}
{% if 'ipv6' in intf %}
    ipv6:
     address:
     - ip-prefix: "{{ intf.ipv6 }}"
{% if ipv6_ra %}
     router-advertisement:
      router-role:
       admin-state: enable            # no ipv6 nd suppress-ra
       max-advertisement-interval: 5  # ipv6 nd ra-interval 5
{% endif %}
{% endif %}
{% endmacro %}

updates:
{% if mtu is defined %}
{% if (clab.type in ['ixr6','ixr10'] and (mtu+14)>9486)
   or (clab.type in ['ixrd1','ixrd2','ixrd3','ixrh1','ixrh2'] and (mtu+14)>9398) %}
{{ mtu_too_large | mandatory( 'IP MTU '+str(mtu)+' too large for given hardware platform: ' + clab.type ) }}
{% else %}
- path: system/mtu
  val:
   default-port-mtu: {{ [mtu + 14,1500]|max }}
   default-l2-mtu: {{ [mtu + 14,1500]|max }}
   default-ip-mtu: {{ mtu }}
   _annotate_default-ip-mtu: "Custom system wide setting, overrides default 1500"
{% endif %}
{% endif %}
- path: interface[name=system0]/subinterface[index=0]
  val:
{{  ip_addresses(loopback,False,True)  }}

{% for l in interfaces|default([]) %}
- path: interface[name={{ l.ifname }}]
  val:
{% if l.name is defined %}
   description: "{{ l.name|replace('->','~')|regex_replace('[\\[\\]]','') }}{{ " ("+l.role+")" if l.role is defined else '' }}"
{% elif l.type|default("") == "stub" %}
   description: "Stub interface"
{% endif %}
{% if l.mtu is defined %} # min 1500; max 9412 for 7220, 9500 for 7250 platforms
   mtu {{ [l.mtu + 14,1500]|max }} # TODO not supported on loopback interfaces
{% endif %}
   subinterface:
    index: 0
{{  ip_addresses(l,True,False) }}
{% if l.bandwidth is defined %}
 # bandwidth {{ l.bandwidth  }}
{% endif %}
{% endfor %}

{# Make sure the default VRF is called 'default' #}
- path: network-instance[name=default]
  val:
   type: default
   interface:
   - name: system0.0
{% for l in interfaces|default([]) %}
   - name: {{ l.ifname + '.0' }}
{% endfor %}
