!
router bgp {{ bgp.as }}

! AllowAS-IN
{% for n in bgp.neighbors if n.allowas_in is defined %}
{%   for af in ['ipv4','ipv6'] if n[af] is defined %}
 address-family {{ af }}
  neighbor {{ n[af] }} allowas-in {{ n.allowas_in }}
{%   endfor %}
{% endfor %}

{% if vrfs is defined %}
{% for vname,vdata in vrfs.items() if vdata.bgp is defined %}
{%   for n in vdata.bgp.neighbors|default([]) if n.allowas_in is defined %}
{%     for af in ['ipv4','ipv6'] if n[af] is defined and n.allowas_in %}
 address-family {{ af }} vrf {{ vname }}
  neighbor {{ n[af] }} allowas-in {{ n.allowas_in }}
{%     endfor %}
{%   endfor %}
{% endfor %}
{% endif %}

! AS-Override
{% for n in bgp.neighbors if n.as_override is defined %}
{%   for af in ['ipv4','ipv6'] if n[af] is defined %}
 address-family {{ af }}
  neighbor {{ n[af] }} as-override
{%   endfor %}
{% endfor %}

{% if vrfs is defined %}
{% for vname,vdata in vrfs.items() if vdata.bgp is defined %}
{%   for n in vdata.bgp.neighbors|default([]) if n.as_override is defined %}
{%     for af in ['ipv4','ipv6'] if n[af] is defined and n.as_override %}
 address-family {{ af }} vrf {{ vname }}
  neighbor {{ n[af] }} as-override
{%     endfor %}
{%   endfor %}
{% endfor %}
{% endif %}

! Password
{% for n in bgp.neighbors if n.password is defined %}
{%   for af in ['ipv4','ipv6'] if n[af] is defined %}
   neighbor {{ n[af] }} password {{ n.password }}
{%   endfor %}
{% endfor %}

{% if vrfs is defined %}
{% for vname,vdata in vrfs.items() if vdata.bgp is defined %}
{%   for n in vdata.bgp.neighbors|default([]) if n.password is defined %}
{%     for af in ['ipv4','ipv6'] if n[af] is defined and n.password %}
 address-family {{ af }} vrf {{ vname }}
  neighbor {{ n[af] }} password {{ n.password }}
{%     endfor %}
{%   endfor %}
{% endfor %}
{% endif %}
