Skip to content

Commit adc68de

Browse files
committed
leverage built in jinja2 filters instead of .split("/")[0]
1 parent 42a17e3 commit adc68de

19 files changed

+52
-52
lines changed

templates/clab_topology.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ topology:
119119
{%- set device2_name = endpoint2.split(":")[0] %}
120120
{#- Arista cEOS: Strip subinterface notation (e.g., "eth1/1/1" -> "eth1/1") -#}
121121
{%- if device_kinds.get(device1_name) == "arista_ceos" %}
122-
{%- set endpoint1 = endpoint1.split("/")[0] %}
122+
{%- set endpoint1 = endpoint1 | ipaddress_interface(attr='ip') %}
123123
{%- endif %}
124124
{%- if device_kinds.get(device2_name) == "arista_ceos" %}
125-
{%- set endpoint2 = endpoint2.split("/")[0] %}
125+
{%- set endpoint2 = endpoint2 | ipaddress_interface(attr='ip') %}
126126
{%- endif %}
127127
- endpoints: ["{{ endpoint1 }}", "{{ endpoint2 }}"]
128128
{%- endif %}

templates/configs/edges/cisco_ios.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface {{ interface.name }}
4242
! OSPF Configuration
4343
{%- for ospf_config in ospf %}
4444
router ospf {{ ospf_config.process_id }}
45-
router-id {{ ospf_config.router_id.split('/')[0] }}
45+
router-id {{ ospf_config.router_id | ipaddress_interface(attr='ip') }}
4646
area {{ ospf_config.area }} authentication message-digest
4747
auto-cost reference-bandwidth {{ ospf_config.reference_bandwidth }}
4848
passive-interface default
@@ -57,7 +57,7 @@ router ospf {{ ospf_config.process_id }}
5757
! BGP Configuration
5858
{%- for bgp_config in bgp %}
5959
router bgp {{ bgp_config.local_as.asn }}
60-
router-id {{ bgp_config.router_id.address.split('/')[0] }}
60+
router-id {{ bgp_config.router_id.address | ipaddress_interface(attr='ip') }}
6161
{%- if bgp_config.graceful_restart %}
6262
graceful-restart
6363
{%- endif %}
@@ -71,7 +71,7 @@ router bgp {{ bgp_config.local_as.asn }}
7171
exit-peer-policy
7272
!
7373
template peer-session {{ bgp_config.profile }}-SESSION
74-
update-source {{ bgp_config.local_ip.address.split('/')[0] }}
74+
update-source {{ bgp_config.local_ip.address | ipaddress_interface(attr='ip') }}
7575
exit-peer-session
7676
!
7777
address-family ipv4 unicast
@@ -81,7 +81,7 @@ router bgp {{ bgp_config.local_as.asn }}
8181
!
8282
address-family l2vpn evpn
8383
{%- for session in bgp_config.sessions %}
84-
neighbor {{ session.remote_ip.address.split('/')[0] }}
84+
neighbor {{ session.remote_ip.address | ipaddress_interface(attr='ip') }}
8585
remote-as {{ session.remote_as.asn }}
8686
inherit peer-session {{ bgp_config.profile }}-SESSION
8787
address-family l2vpn evpn

templates/configs/edges/cisco_nxos.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface {{ interface.name }}
4242
! OSPF Configuration
4343
{%- for ospf_config in ospf %}
4444
router ospf {{ ospf_config.process_id }}
45-
router-id {{ ospf_config.router_id.split('/')[0] }}
45+
router-id {{ ospf_config.router_id | ipaddress_interface(attr='ip') }}
4646
area {{ ospf_config.area }} authentication message-digest
4747
auto-cost reference-bandwidth {{ ospf_config.reference_bandwidth }}
4848
passive-interface default
@@ -57,7 +57,7 @@ router ospf {{ ospf_config.process_id }}
5757
! BGP Configuration
5858
{%- for bgp_config in bgp %}
5959
router bgp {{ bgp_config.local_as.asn }}
60-
router-id {{ bgp_config.router_id.address.split('/')[0] }}
60+
router-id {{ bgp_config.router_id.address | ipaddress_interface(attr='ip') }}
6161
{%- if bgp_config.graceful_restart %}
6262
graceful-restart
6363
{%- endif %}
@@ -71,7 +71,7 @@ router bgp {{ bgp_config.local_as.asn }}
7171
exit-peer-policy
7272
!
7373
template peer-session {{ bgp_config.profile }}-SESSION
74-
update-source {{ bgp_config.local_ip.address.split('/')[0] }}
74+
update-source {{ bgp_config.local_ip.address | ipaddress_interface(attr='ip') }}
7575
exit-peer-session
7676
!
7777
address-family ipv4 unicast
@@ -81,7 +81,7 @@ router bgp {{ bgp_config.local_as.asn }}
8181
!
8282
address-family l2vpn evpn
8383
{%- for session in bgp_config.sessions %}
84-
neighbor {{ session.remote_ip.address.split('/')[0] }}
84+
neighbor {{ session.remote_ip.address | ipaddress_interface(attr='ip') }}
8585
remote-as {{ session.remote_as.asn }}
8686
inherit peer-session {{ bgp_config.profile }}-SESSION
8787
address-family l2vpn evpn

templates/configs/leafs/arista_eos.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ router bgp {{ bgp.local_as }}
101101
maximum-paths 4 ecmp 64
102102
{# Configure BGP neighbors from enhanced transform data #}
103103
{%- for neighbor in bgp.neighbors %}
104-
{%- set neihbor_ip = neighbor.remote_ip.split('/')[0] %}
104+
{%- set neihbor_ip = neighbor.remote_ip | ipaddress_interface(attr='ip') %}
105105
! {{ neighbor.description or 'BGP Neighbor' }}
106106
neighbor {{ neihbor_ip }} remote-as {{ neighbor.remote_as }}
107107
neighbor {{ neihbor_ip }} update-source Loopback0
@@ -112,11 +112,11 @@ router bgp {{ bgp.local_as }}
112112
address-family ipv4
113113
redistribute connected route-map RM-CONN-2-BGP
114114
{%- for neighbor in bgp.neighbors %}
115-
neighbor {{ neighbor.remote_ip.split('/')[0] }} activate
115+
neighbor {{ neighbor.remote_ip | ipaddress_interface(attr='ip') }} activate
116116
{%- endfor %}
117117
address-family evpn
118118
{%- for neighbor in bgp.neighbors %}
119-
neighbor {{ neighbor.remote_ip.split('/')[0] }} activate
119+
neighbor {{ neighbor.remote_ip | ipaddress_interface(attr='ip') }} activate
120120
{%- endfor %}
121121
{# L2VPN EVPN for VLANs #}
122122
{%- for vlan in vlans %}

templates/configs/leafs/cisco_nxos.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface {{ interface.name }}
4242
! OSPF Configuration
4343
{%- for ospf_config in ospf_configs %}
4444
router ospf {{ ospf_config.process_id }}
45-
router-id {{ ospf_config.router_id.split('/')[0] }}
45+
router-id {{ ospf_config.router_id | ipaddress_interface(attr='ip') }}
4646
area {{ ospf_config.area }} authentication message-digest
4747
auto-cost reference-bandwidth {{ ospf_config.reference_bandwidth }}
4848
passive-interface default
@@ -57,7 +57,7 @@ router ospf {{ ospf_config.process_id }}
5757
! BGP Configuration
5858
{%- for bgp_config in bgp_profiles %}
5959
router bgp {{ bgp_config.local_as.asn }}
60-
router-id {{ bgp_config.router_id.address.split('/')[0] }}
60+
router-id {{ bgp_config.router_id.address | ipaddress_interface(attr='ip') }}
6161
{%- if bgp_config.graceful_restart %}
6262
graceful-restart
6363
{%- endif %}
@@ -70,7 +70,7 @@ router bgp {{ bgp_config.local_as.asn }}
7070
{%- endif %}
7171
!
7272
template peer-session {{ bgp_config.profile }}-SESSION
73-
update-source {{ bgp_config.local_ip.address.split('/')[0] }}
73+
update-source {{ bgp_config.local_ip.address | ipaddress_interface(attr='ip') }}
7474
!
7575
address-family ipv4 unicast
7676
{%- if bgp_config.multipath %}
@@ -79,7 +79,7 @@ router bgp {{ bgp_config.local_as.asn }}
7979
!
8080
address-family l2vpn evpn
8181
{%- for session in bgp_config.sessions %}
82-
neighbor {{ session.remote_ip.address.split('/')[0] }}
82+
neighbor {{ session.remote_ip.address | ipaddress_interface(attr='ip') }}
8383
remote-as {{ session.remote_as.asn }}
8484
inherit peer-session {{ bgp_config.profile }}-SESSION
8585
address-family l2vpn evpn

templates/configs/leafs/dell_sonic.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ router ospf {{ ospf.process_id }}
102102
router bgp {{ bgp.local_as }}
103103
router-id {{ bgp.router_id }}
104104
{% for neighbor in bgp.neighbors %}
105-
neighbor {{ neighbor.remote_ip.split('/')[0] }}
105+
neighbor {{ neighbor.remote_ip | ipaddress_interface(attr='ip') }}
106106
remote-as {{ neighbor.remote_as }}
107107
update-source loopback0
108108
address-family l2vpn evpn

templates/configs/leafs/juniper_junos.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ system {
88

99
{%- if ospf_configs and ospf_configs[0] and ospf_configs[0].router_id %}
1010
## OSPF Router ID
11-
## router-id {{ ospf_configs[0].router_id.split('/')[0] }};
11+
## router-id {{ ospf_configs[0].router_id | ipaddress_interface(attr='ip') }};
1212
{%- endif %}
1313

1414
services {
@@ -127,7 +127,7 @@ protocols {
127127

128128
routing-options {
129129
{%- if bgp_config.router_id and bgp_config.router_id.address %}
130-
router-id {{ bgp_config.router_id.address.split('/')[0] }};
130+
router-id {{ bgp_config.router_id.address | ipaddress_interface(attr='ip') }};
131131
{%- endif %}
132132
autonomous-system {{ bgp_config.local_as.asn }};
133133
}
@@ -142,7 +142,7 @@ protocols {
142142
group {{ bgp_config.profile }} {
143143
type {{ 'internal' if bgp_config.session_type == 'INTERNAL' else 'external' }};
144144
{%- if bgp_config.local_ip and bgp_config.local_ip.address %}
145-
local-address {{ bgp_config.local_ip.address.split('/')[0] }};
145+
local-address {{ bgp_config.local_ip.address | ipaddress_interface(attr='ip') }};
146146
{%- endif %}
147147
family inet {
148148
unicast {
@@ -159,7 +159,7 @@ protocols {
159159
{%- endif %}
160160

161161
{%- for session in bgp_config.sessions %}
162-
neighbor {{ session.remote_ip.address.split('/')[0] }} {
162+
neighbor {{ session.remote_ip.address | ipaddress_interface(attr='ip') }} {
163163
{%- if session.name %}
164164
description "{{ session.name }}";
165165
{%- endif %}

templates/configs/leafs/sonic.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"BGP_NEIGHBOR": {
3636
{% for neighbor in bgp.neighbors %}
37-
"{{ neighbor.remote_ip.split('/')[0] }}": {
37+
"{{ neighbor.remote_ip | ipaddress_interface(attr='ip') }}": {
3838
"local_addr": "{{ bgp.router_id or default_router_id }}",
3939
"asn": "{{ neighbor.remote_as }}",
4040
"holdtime": "10",
@@ -84,7 +84,7 @@
8484
},
8585
"BGP_NEIGHBOR_AF": {
8686
{% for neighbor in bgp.neighbors %}
87-
"{{ neighbor.remote_ip.split('/')[0] }}|l2vpn_evpn": {
87+
"{{ neighbor.remote_ip | ipaddress_interface(attr='ip') }}|l2vpn_evpn": {
8888
"admin_status": "up"
8989
}{{ "," if not loop.last }}
9090
{% endfor %}

templates/configs/loadbalancers/f5_networks_linux.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ltm pool {{ vip.hostname | replace('.', '_') | replace('-', '_') }}_pool {
7878

7979
# Virtual Server configuration for {{ vip.hostname }}
8080
ltm virtual {{ vip.hostname | replace('.', '_') | replace('-', '_') }}_vs {
81-
destination {{ vip.ip_address.split('/')[0] }}:80
81+
destination {{ vip.ip_address | ipaddress_interface(attr='ip') }}:80
8282
{%- if vip.ssl_certificate %}
8383
profiles {
8484
http { }
@@ -119,7 +119,7 @@ ltm profile client-ssl {{ vip.hostname | replace('.', '_') | replace('-', '_') }
119119

120120
# HTTPS Virtual Server for {{ vip.hostname }}
121121
ltm virtual {{ vip.hostname | replace('.', '_') | replace('-', '_') }}_https_vs {
122-
destination {{ vip.ip_address.split('/')[0] }}:443
122+
destination {{ vip.ip_address | ipaddress_interface(attr='ip') }}:443
123123
profiles {
124124
http { }
125125
{{ vip.hostname | replace('.', '_') | replace('-', '_') }}_clientssl {

templates/configs/loadbalancers/haproxy_technologies_linux.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ frontend {{ vip.hostname | replace('.', '_') | replace('-', '_') }}_frontend
6868
mode http
6969
{%- endif %}
7070

71-
bind {{ vip.ip_address.split('/')[0] }}:80
71+
bind {{ vip.ip_address | ipaddress_interface(attr='ip') }}:80
7272
{%- if vip.ssl_certificate %}
73-
bind {{ vip.ip_address.split('/')[0] }}:443 ssl crt {{ vip.ssl_certificate }}
73+
bind {{ vip.ip_address | ipaddress_interface(attr='ip') }}:443 ssl crt {{ vip.ssl_certificate }}
7474
{%- if vip.mode == 'http' %}
7575
redirect scheme https if !{ ssl_fc }
7676
{%- endif %}

0 commit comments

Comments
 (0)