
{% if bgp.as is defined %}
{% include 'junos.bgp.j2' %}
{% endif %}

{% for vname,vdata in vrfs.items() if 'ospf' in vdata %}

{# generic policy to redistribute bgp + leaked(imported) into ospf #}
{% set ns = namespace(import_list=[]) %}
{%   for i in vdata.import|default([]) %}
{{ ns.import_list.append('tg_'+i|replace(':', '_')|replace('.', '_')) }}
{%   endfor %}

policy-options {
  policy-statement vrf-{{vname}}-ospf-export {
    term redis_bgp {
      from protocol bgp;
      then {
        accept;
      }
    }
    term redis_local_target {
      from community [ {{ ns.import_list|join(' ') }} ];
      then accept;
    }
  }
}

{%   include 'junos.ospfv2-vrf.j2' %}
{% endfor %}
