Skip to content

Commit 110bf8a

Browse files
authored
Fix: Simplify SR-OS IS-IS template with 'configure_router' macro (#2475)
Most SR-OS configuration templates used 'declare_router' macro that would select the correct service configuration path based on interface data, leading to an awkward recreation of interface data in case we really wanted to configure a router, not an interface. This fix adds another layer of indirection (proving RFC 1925) in front of the 'declare_router' macro to make the routing protocol configuration templates a bit cleaner.
1 parent fb98ccf commit 110bf8a

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

netsim/ansible/templates/initial/sros.j2

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{ name or i.ifname }}
33
{%- endmacro %}
44

5-
{% macro declare_router(i,sub_path="",intf_cfg=False) -%}
5+
{% macro declare_router(i,sub_path="",intf_cfg=False,vrf_config=True) -%}
66
{#
77
This macro selects the SR/OS service in which the current object
88
is configured. The global routing instance is "router Base" unless
@@ -32,7 +32,7 @@
3232
else "service/vprn[service-name="+service_name+"]" %}
3333

3434
{# Minimal service config must exist #}
35-
{% if not in_base %}
35+
{% if not in_base and vrf_config %}
3636
- path: configure/{{ base_path }}
3737
val:
3838
customer: "1"
@@ -44,6 +44,20 @@
4444
- path: configure/{{ base_path }}{{ sub_path }}
4545
{%- endmacro %}
4646

47+
{#
48+
This macro is just a convenient wrapper around the more generic declare_router
49+
macro. That one expects an interface data structure and extracts VRF from it,
50+
this one takes VRF as the parameter (it can also be missing) and fakes the minimal
51+
data structure that makes declare_router happy
52+
#}
53+
{% macro configure_router(vrf="",sub_path="") -%}
54+
{% if vrf %}
55+
{{ declare_router({ 'vrf': vrf },sub_path=sub_path) }}
56+
{% else %}
57+
{{ declare_router({},sub_path=sub_path) }}
58+
{% endif %}
59+
{%- endmacro %}
60+
4761
{% macro declare_interface(i,name=None) %}
4862
{% set ifname = if_name(i,name or i.ifname) %}
4963
{{ declare_router(i,sub_path="/interface[interface-name=" + ifname + "]",intf_cfg=True) }}

netsim/ansible/templates/isis/sros.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% from "templates/initial/sros.j2" import if_name, declare_router with context %}
1+
{% from "templates/initial/sros.j2" import if_name, configure_router with context %}
22
{% from 'templates/routing/_redistribute.sros.j2' import import_protocols with context %}
33

44
{% macro isis_export_policy(isis,vrf) %}
@@ -10,13 +10,13 @@
1010
{{ import_protocols(isis.import) | indent(4,first=True) }}
1111
{% endmacro %}
1212

13-
{% macro isis_router(vrf_data,isis,intf_list) %}
14-
{% set vname = vrf_data.vrf|default('default') %}
13+
{% macro isis_router(isis,intf_list=[],vrf_name="") %}
14+
{% set vname = vrf_name or 'default' %}
1515
{% if isis.import is defined %}
1616
{{ isis_export_policy(isis,vname) }}
1717
{% endif %}
1818
{% set kw_level = {'level-1': '1', 'level-2': '2', 'level-1-2': '1/2'} %}
19-
{{ declare_router(vrf_data) }}
19+
{{ configure_router(vrf_name) }}
2020
val:
2121
isis:
2222
- isis-instance: 0
@@ -71,5 +71,5 @@
7171

7272
updates:
7373
{% if isis is defined %}
74-
{{ isis_router({},isis,netlab_interfaces) }}
74+
{{ isis_router(isis,netlab_interfaces) }}
7575
{% endif %}

netsim/ansible/templates/vrf/sros.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ updates:
2727
{% endfor %}
2828
{% endif %}
2929
{% if 'isis' in vdata and 'af' in vdata %}
30-
{{ isis_router({ 'vrf': vname },vdata.isis,vdata.isis.interfaces) }}
30+
{{ isis_router(vdata.isis,vdata.isis.interfaces,vname) }}
3131
{% endif %}
3232
{% endfor %}

0 commit comments

Comments
 (0)