Skip to content

Commit 42a17e3

Browse files
committed
jinja standardization
1 parent 7640f20 commit 42a17e3

File tree

6 files changed

+59
-42
lines changed

6 files changed

+59
-42
lines changed

templates/configs/leafs/arista_eos.j2

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% set default_ospf_area = '0.0.0.0' %}
2+
{% set default_router_id = loopbacks.loopback0 %}
13
!
24
! Arista EOS VXLAN/EVPN Leaf Configuration
35
! Device: {{ hostname }}
@@ -19,20 +21,20 @@ interface {{ loopback_name }}
1921
{%- if loopback_name == 'loopback0' %}
2022
description {{ hostname }} Underlay Loopback Interface
2123
ip address {{ loopback_ip }}/32
22-
ospf area {{ ospf.area or "0.0.0.0" }}
24+
ospf area {{ ospf.area or default_ospf_area }}
2325
{%- elif loopback_name == 'loopback1' %}
2426
description {{ hostname }} VTEP Loopback Interface
2527
ip address {{ loopback_ip }}/32
2628
{#- loopback1 is NOT in OSPF, used only for iBGP EVPN overlay -#}
2729
{%- else %}
2830
description {{ hostname }} {{ loopback_name }} Interface
2931
ip address {{ loopback_ip }}/32
30-
ospf area {{ ospf.area or "0.0.0.0" }}
32+
ospf area {{ ospf.area or default_ospf_area }}
3133
{%- endif %}
3234
{%- endfor %}
3335
! Configure OSPF
3436
router ospf {{ ospf.process_id or 1 }}
35-
router-id {{ ospf.router_id or loopbacks.loopback0 }}
37+
router-id {{ ospf.router_id or default_router_id }}
3638
passive-interface default
3739
no passive-interface Ethernet1
3840
no passive-interface Ethernet2
@@ -53,7 +55,7 @@ interface {{ interface.name }}
5355
mtu {{ interface.mtu or 9214 }}
5456
no switchport
5557
ip unnumbered Loopback0
56-
ospf area {{ ospf.area or "0.0.0.0" }}
58+
ospf area {{ ospf.area or default_ospf_area }}
5759
ospf network point-to-point
5860
{%- elif interface.vlans %}
5961
{%- if interface.vlans | length == 1 %}
@@ -93,18 +95,19 @@ interface {{ interface.name }}
9395
{%- endfor %}
9496
! Configure BGP
9597
router bgp {{ bgp.local_as }}
96-
router-id {{ bgp.router_id or loopbacks.loopback0 }}
98+
router-id {{ bgp.router_id or default_router_id }}
9799
no bgp default ipv4-unicast
98100
distance bgp 20 200 200
99101
maximum-paths 4 ecmp 64
100102
{# Configure BGP neighbors from enhanced transform data #}
101103
{%- for neighbor in bgp.neighbors %}
104+
{%- set neihbor_ip = neighbor.remote_ip.split('/')[0] %}
102105
! {{ neighbor.description or 'BGP Neighbor' }}
103-
neighbor {{ neighbor.remote_ip.split('/')[0] }} remote-as {{ neighbor.remote_as }}
104-
neighbor {{ neighbor.remote_ip.split('/')[0] }} update-source Loopback0
105-
neighbor {{ neighbor.remote_ip.split('/')[0] }} description {{ neighbor.description or 'BGP Neighbor' }}
106-
neighbor {{ neighbor.remote_ip.split('/')[0] }} send-community extended
107-
neighbor {{ neighbor.remote_ip.split('/')[0] }} maximum-routes 0
106+
neighbor {{ neihbor_ip }} remote-as {{ neighbor.remote_as }}
107+
neighbor {{ neihbor_ip }} update-source Loopback0
108+
neighbor {{ neihbor_ip }} description {{ neighbor.description or 'BGP Neighbor' }}
109+
neighbor {{ neihbor_ip }} send-community extended
110+
neighbor {{ neihbor_ip }} maximum-routes 0
108111
{%- endfor %}
109112
address-family ipv4
110113
redistribute connected route-map RM-CONN-2-BGP
@@ -118,7 +121,7 @@ router bgp {{ bgp.local_as }}
118121
{# L2VPN EVPN for VLANs #}
119122
{%- for vlan in vlans %}
120123
vlan {{ vlan.vlan_id }}
121-
rd {{ bgp.router_id or loopbacks.loopback0 }}:{{ vlan.vni }}
124+
rd {{ bgp.router_id or default_router_id }}:{{ vlan.vni }}
122125
route-target both {{ vlan.vni }}:{{ vlan.vni }}
123126
redistribute learned
124127
{%- endfor %}

templates/configs/leafs/sonic.j2

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% set default_ospf_area = '0.0.0.0' %}
2+
{% set default_router_id = loopbacks.loopback0 %}
13
{
24
"DEVICE_METADATA": {
35
"localhost": {
@@ -33,7 +35,7 @@
3335
"BGP_NEIGHBOR": {
3436
{% for neighbor in bgp.neighbors %}
3537
"{{ neighbor.remote_ip.split('/')[0] }}": {
36-
"local_addr": "{{ bgp.router_id or loopbacks.loopback0 }}",
38+
"local_addr": "{{ bgp.router_id or default_router_id }}",
3739
"asn": "{{ neighbor.remote_as }}",
3840
"holdtime": "10",
3941
"keepalive": "3",
@@ -43,33 +45,33 @@
4345
},
4446
"BGP_GLOBALS": {
4547
"default": {
46-
"router_id": "{{ bgp.router_id or loopbacks.loopback0 }}",
48+
"router_id": "{{ bgp.router_id or default_router_id }}",
4749
"local_asn": "{{ bgp.local_as }}"
4850
}
4951
},
5052
"OSPF_ROUTER": {
5153
"default": {
52-
"router_id": "{{ ospf.router_id or loopbacks.loopback0 }}"
54+
"router_id": "{{ ospf.router_id or default_router_id }}"
5355
}
5456
},
5557
"OSPF_INTERFACE": {
5658
{% for interface in interfaces.all_physical %}
5759
{% if interface.role == 'uplink' %}
5860
"{{ interface.name }}": {
59-
"area": "{{ ospf.area or '0.0.0.0' }}",
61+
"area": "{{ ospf.area or default_ospf_area }}",
6062
"network": "point-to-point"
6163
}{{ "," if not (loop.last and not loopbacks.loopback0) }}
6264
{% endif %}
6365
{% endfor %}
6466
{% if loopbacks.loopback0 %}
6567
"loopback0": {
66-
"area": "{{ ospf.area or '0.0.0.0' }}"
68+
"area": "{{ ospf.area or default_ospf_area }}"
6769
}
6870
{% endif %}
6971
},
7072
"VXLAN_TUNNEL": {
7173
"vtep1": {
72-
"src_ip": "{{ loopbacks.loopback1 or loopbacks.loopback0 }}"
74+
"src_ip": "{{ loopbacks.loopback1 or default_router_id }}"
7375
}
7476
},
7577
"VXLAN_TUNNEL_MAP": {

templates/configs/spines/arista_eos.j2

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% set default_ospf_area = '0.0.0.0' %}
2+
{% set default_ospf_process_id = 'Underlay' %}
3+
{% set default_router_id = loopbacks.loopback0 %}
14
!
25
! Arista EOS VXLAN/EVPN Spine Configuration
36
! Device: {{ hostname }}
@@ -22,15 +25,15 @@ interface {{ interface.name }}
2225
ip address {{ interface.ip_address | replace('/24', '/32') }}
2326
{%- endif %}
2427
{%- if interface.name == 'loopback0' %}
25-
ospf area {{ ospf.area or "0.0.0.0" }}
28+
ospf area {{ ospf.area or default_ospf_area }}
2629
{%- elif interface.name != 'loopback1' %}
2730
{#- loopback1 is NOT in OSPF, used only for iBGP EVPN overlay -#}
28-
ospf area {{ ospf.area or "0.0.0.0" }}
31+
ospf area {{ ospf.area or default_ospf_area }}
2932
{%- endif %}
3033
{%- endfor %}
3134
! Configure OSPF
32-
router ospf {{ ospf.process_id or 'Underlay' }}
33-
router-id {{ ospf.router_id or loopbacks.loopback0 }}
35+
router ospf {{ ospf.process_id or default_ospf_process_id }}
36+
router-id {{ ospf.router_id or default_router_id }}
3437
passive-interface default
3538
no passive-interface Ethernet1
3639
no passive-interface Ethernet2
@@ -46,12 +49,12 @@ interface {{ interface.name }}
4649
mtu {{ interface.mtu or 9214 }}
4750
no switchport
4851
ip unnumbered Loopback0
49-
ospf area {{ ospf.area or "0.0.0.0" }}
52+
ospf area {{ ospf.area or default_ospf_area }}
5053
ospf network point-to-point
5154
{%- endfor %}
5255
! Configure BGP
5356
router bgp {{ bgp.local_as }}
54-
router-id {{ bgp.router_id or loopbacks.loopback0 }}
57+
router-id {{ bgp.router_id or default_router_id }}
5558
no bgp default ipv4-unicast
5659
distance bgp 20 200 200
5760
maximum-paths 4 ecmp 64
@@ -64,9 +67,10 @@ router bgp {{ bgp.local_as }}
6467
peer-group EVPN-OVERLAY-PEERS maximum-routes 0
6568
{# Configure BGP neighbors from enhanced transform data #}
6669
{%- for neighbor in bgp.neighbors %}
70+
{%- set neihbor_ip = neighbor.remote_ip.split('/')[0] %}
6771
! {{ neighbor.description or 'BGP Neighbor' }} (Route Reflector Client)
68-
neighbor {{ neighbor.remote_ip.split('/')[0] }} peer-group EVPN-OVERLAY-PEERS
69-
neighbor {{ neighbor.remote_ip.split('/')[0] }} description {{ neighbor.description or 'BGP Neighbor' }}
72+
neighbor {{ neihbor_ip }} peer-group EVPN-OVERLAY-PEERS
73+
neighbor {{ neihbor_ip }} description {{ neighbor.description or 'BGP Neighbor' }}
7074
{%- endfor %}
7175
address-family ipv4
7276
redistribute connected route-map RM-CONN-2-BGP

templates/configs/spines/dell_sonic.j2

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% set default_ospf_area = '0.0.0.0' %}
2+
{% set default_ospf_process_id = 'Underlay' %}
3+
{% set default_router_id = loopbacks.loopback0 %}
14
nv overlay evpn
25
feature ospf
36
feature bgp
@@ -22,7 +25,7 @@ interface {{ interface.name }}
2225
medium p2p
2326
ip unnumbered loopback0
2427
ip ospf network point-to-point
25-
ip router ospf {{ ospf.process_id or 'Underlay' }} area {{ ospf.area or '0.0.0.0' }}
28+
ip router ospf {{ ospf.process_id or default_ospf_process_id }} area {{ ospf.area or default_ospf_area }}
2629
ip pim sparse-mode
2730
no shutdown
2831

@@ -47,11 +50,11 @@ interface {{ interface.name }}
4750
ip address {{ interface.ip_address | replace('/24', '/32') }}
4851
{% endif %}
4952
{% if interface.name == 'loopback0' %}
50-
ip router ospf {{ ospf.process_id or 'Underlay' }} area {{ ospf.area or '0.0.0.0' }}
53+
ip router ospf {{ ospf.process_id or default_ospf_process_id }} area {{ ospf.area or default_ospf_area }}
5154
ip pim sparse-mode
5255
{% elif interface.name != 'loopback1' %}
5356
{#- loopback1 is NOT in OSPF, used only for iBGP EVPN overlay -#}
54-
ip router ospf {{ ospf.process_id or 'Underlay' }} area {{ ospf.area or '0.0.0.0' }}
57+
ip router ospf {{ ospf.process_id or default_ospf_process_id }} area {{ ospf.area or default_ospf_area }}
5558
ip pim sparse-mode
5659
{% endif %}
5760
{% endfor %}
@@ -62,11 +65,11 @@ cli alias name wr copy r s
6265
line console
6366
line vty
6467

65-
router ospf {{ ospf.process_id or 'Underlay' }}
66-
router-id {{ ospf.router_id or loopbacks.loopback0 }}
68+
router ospf {{ ospf.process_id or default_ospf_process_id }}
69+
router-id {{ ospf.router_id or default_router_id }}
6770

6871
router bgp {{ bgp.local_as }}
69-
router-id {{ bgp.router_id or loopbacks.loopback0 }}
72+
router-id {{ bgp.router_id or default_router_id }}
7073
{% for neighbor in bgp.neighbors %}
7174
neighbor {{ neighbor.remote_ip.split('/')[0] }}
7275
remote-as {{ neighbor.remote_as }}

templates/configs/spines/edgecore_sonic.j2

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% set default_ospf_area = '0.0.0.0' %}
2+
{% set default_router_id = loopbacks.loopback0 %}
13
{
24
"DEVICE_METADATA": {
35
"localhost": {
@@ -21,7 +23,7 @@
2123
"BGP_NEIGHBOR": {
2224
{% for neighbor in bgp.neighbors %}
2325
"{{ neighbor.remote_ip.split('/')[0] }}": {
24-
"local_addr": "{{ bgp.router_id or loopbacks.loopback0 }}",
26+
"local_addr": "{{ bgp.router_id or default_router_id }}",
2527
"asn": "{{ neighbor.remote_as }}",
2628
"holdtime": "10",
2729
"keepalive": "3",
@@ -31,27 +33,27 @@
3133
},
3234
"BGP_GLOBALS": {
3335
"default": {
34-
"router_id": "{{ bgp.router_id or loopbacks.loopback0 }}",
36+
"router_id": "{{ bgp.router_id or default_router_id }}",
3537
"local_asn": "{{ bgp.local_as }}"
3638
}
3739
},
3840
"OSPF_ROUTER": {
3941
"default": {
40-
"router_id": "{{ ospf.router_id or loopbacks.loopback0 }}"
42+
"router_id": "{{ ospf.router_id or default_router_id }}"
4143
}
4244
},
4345
"OSPF_INTERFACE": {
4446
{% for interface in interface_roles.all_downlink %}
4547
"{{ interface.name }}": {
46-
"area": "{{ ospf.area or '0.0.0.0' }}",
48+
"area": "{{ ospf.area or default_ospf_area }}",
4749
"network": "point-to-point"
4850
}{{ "," if not loop.last }}
4951
{% endfor %}
5052
{% if interface_roles.all_downlink and interface_roles.loopback %},{% endif %}
5153
{% for interface in interface_roles.loopback %}
5254
{% if interface.name == 'loopback0' %}
5355
"{{ interface.name }}": {
54-
"area": "{{ ospf.area or '0.0.0.0' }}"
56+
"area": "{{ ospf.area or default_ospf_area }}"
5557
}{{ "," if not loop.last }}
5658
{% endif %}
5759
{% endfor %}

templates/configs/spines/sonic.j2

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% set default_ospf_area = '0.0.0.0' %}
2+
{% set default_ospf_process_id = 'Underlay' %}
3+
{% set default_router_id = loopbacks.loopback0 %}
14
nv overlay evpn
25
feature ospf
36
feature bgp
@@ -22,7 +25,7 @@ interface {{ interface.name }}
2225
medium p2p
2326
ip unnumbered loopback0
2427
ip ospf network point-to-point
25-
ip router ospf {{ ospf.process_id or 'Underlay' }} area {{ ospf.area or '0.0.0.0' }}
28+
ip router ospf {{ ospf.process_id or default_ospf_process_id }} area {{ ospf.area or default_ospf_area }}
2629
ip pim sparse-mode
2730
no shutdown
2831

@@ -47,11 +50,11 @@ interface {{ interface.name }}
4750
ip address {{ interface.ip_address | replace('/24', '/32') }}
4851
{% endif %}
4952
{% if interface.name == 'loopback0' %}
50-
ip router ospf {{ ospf.process_id or 'Underlay' }} area {{ ospf.area or '0.0.0.0' }}
53+
ip router ospf {{ ospf.process_id or default_ospf_process_id }} area {{ ospf.area or default_ospf_area }}
5154
ip pim sparse-mode
5255
{% elif interface.name != 'loopback1' %}
5356
{#- loopback1 is NOT in OSPF, used only for iBGP EVPN overlay -#}
54-
ip router ospf {{ ospf.process_id or 'Underlay' }} area {{ ospf.area or '0.0.0.0' }}
57+
ip router ospf {{ ospf.process_id or default_ospf_process_id }} area {{ ospf.area or default_ospf_area }}
5558
ip pim sparse-mode
5659
{% endif %}
5760
{% endfor %}
@@ -62,11 +65,11 @@ cli alias name wr copy r s
6265
line console
6366
line vty
6467

65-
router ospf {{ ospf.process_id or 'Underlay' }}
66-
router-id {{ ospf.router_id or loopbacks.loopback0 }}
68+
router ospf {{ ospf.process_id or default_ospf_process_id }}
69+
router-id {{ ospf.router_id or default_router_id}}
6770

6871
router bgp {{ bgp.local_as }}
69-
router-id {{ bgp.router_id or loopbacks.loopback0 }}
72+
router-id {{ bgp.router_id or default_router_id }}
7073
{% for neighbor in bgp.neighbors %}
7174
neighbor {{ neighbor.remote_ip.split('/')[0] }}
7275
remote-as {{ neighbor.remote_as }}

0 commit comments

Comments
 (0)