From dcb531625b1b8313a5e7788427ba93b4f5ec7863 Mon Sep 17 00:00:00 2001
From: Aleksandr Kurbatov <aleksandr.kurbatov@GL1342-AKURBATOV.local>
Date: Mon, 2 Sep 2024 16:23:49 +0100
Subject: [PATCH] BGP base config in a separate template

Common BGP base config into a separate template (bgp_base).
This allows to re-use it in both router Base and VPRN contexts.
---
 .../routers/nokia/router/base_bgp.j2          | 58 -------------------
 .../templates/routers/nokia/router/bgp.j2     | 13 +++++
 .../routers/nokia/router/bgp_base.j2          |  0
 .../routers/nokia/router/router_base.j2       |  2 +-
 .../templates/routers/nokia/router/vprn.j2    | 39 +------------
 5 files changed, 17 insertions(+), 95 deletions(-)
 delete mode 100644 geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/base_bgp.j2
 create mode 100644 geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp.j2
 create mode 100644 geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp_base.j2

diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/base_bgp.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/base_bgp.j2
deleted file mode 100644
index 0b911be7..00000000
--- a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/base_bgp.j2
+++ /dev/null
@@ -1,58 +0,0 @@
-            <bgp xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
-              {% if pe_bgp_base.best_path_selection is defined %}
-                <best-path-selection>
-                {% for bps in pe_bgp_base.best_path_selection %}
-                    <{{ bps }}>true</{{ bps }}>
-                {% endfor %}
-                </best-path-selection>
-              {% endif %}
-              {% if pe_bgp_base.error_handling is defined %}
-                <error-handling>
-                    <{{ pe_bgp_base.error_handling }}>true</{{ pe_bgp_base.error_handling }}>
-                </error-handling>
-              {% endif %}
-              {% if pe_bgp_base.next_hop_resolution.shortcut_tunnel is defined %}
-                <next-hop-resolution>
-                    <shortcut-tunnel>
-                    {% for nhr in pe_bgp_base.next_hop_resolution.shortcut_tunnel %}
-                        <family>
-                            <family-type>{{ nhr.type }}</family-type>
-                            <resolution-filter>
-                                <{{ nhr.resolution_filter }}>true</{{ nhr.resolution_filter }}>
-                            </resolution-filter>
-                        </family>
-                    {% endfor %}
-                    </shortcut-tunnel>
-                </next-hop-resolution>
-              {% endif %}
-              {% if pe_bgp_base.multipath is defined %}
-                <multipath alu:operation="replace">
-                  {% if pe_bgp_base.multipath.ibgp is defined %}
-                    <ibgp>{{ pe_bgp_base.multipath.ibgp }}</ibgp>
-                  {% endif %}
-                  {% if pe_bgp_base.multipath.ebgp is defined %}
-                    <ebgp>{{ pe_bgp_base.multipath.ebgp }}</ebgp>
-                  {% endif %}
-                  {% if pe_bgp_base.multipath.ipv4 is defined %}
-                    <family>
-                        <family-type>ipv4</family-type>
-                        <max-paths>{{ pe_bgp_base.multipath.ipv4 }}</max-paths>
-                    </family>
-                  {% endif %}
-                  {% if pe_bgp_base.multipath.ipv6 is defined %}
-                    <family>
-                        <family-type>ipv6</family-type>
-                        <max-paths>{{ pe_bgp_base.multipath.ipv6 }}</max-paths>
-                    </family>
-                  {% endif %}
-                </multipath>
-              {% endif %}
-{% with bgp_obj=pe_bgp_tools %}
-        {% include "router/bgp_group.j2" %}
-        {% include "router/bgp_neighbor.j2" %}
-{% endwith %}
-{% with bgp_obj=pe_bgp_internal %}
-        {% include "router/bgp_group.j2" %}
-{% endwith %}
-            </bgp>
-
diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp.j2
new file mode 100644
index 00000000..b5af67ba
--- /dev/null
+++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp.j2
@@ -0,0 +1,13 @@
+            <bgp xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
+{% with bgp_base_obj=pe_bgp_base, bgp_context='bgp_base' %}
+        {% include 'router/bgp_base.j2' %}
+{% endwith %}
+{% with bgp_obj=pe_bgp_tools %}
+        {% include "router/bgp_group.j2" %}
+        {% include "router/bgp_neighbor.j2" %}
+{% endwith %}
+{% with bgp_obj=pe_bgp_internal %}
+        {% include "router/bgp_group.j2" %}
+{% endwith %}
+            </bgp>
+
diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp_base.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/bgp_base.j2
new file mode 100644
index 00000000..e69de29b
diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/router_base.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/router_base.j2
index ce792e85..621d8348 100644
--- a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/router_base.j2
+++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/router_base.j2
@@ -4,7 +4,7 @@
             {% include 'router/static_routes.j2' %}
             {% endwith %}
             {% with bgp_group_context='bgp_base' %}
-            {% include 'router/base_bgp.j2' %}
+            {% include 'router/bgp.j2' %}
             {% endwith %}
             {% include 'router/flowspec.j2' %}
             {% include 'router/ldp.j2' %}
diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/vprn.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/vprn.j2
index fa8b9362..23185e59 100644
--- a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/vprn.j2
+++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/router/vprn.j2
@@ -24,42 +24,9 @@
             </mpls>
         </bgp-ipvpn>
         <bgp>
-            {% if vprn.bgp.families is defined %}
-            <family>
-              {% for fam in vprn.bgp.families %}
-                <{{ fam }}>true</{{ fam }}>
-              {% endfor %}
-            </family>
-            {% endif %}
-            {% if vprn.bgp.best_path_selection is defined %}
-            <best-path-selection>
-              {% for bps in vprn.bgp.best_path_selection %}
-                <{{ bps }}>true</{{ bps }}>
-              {% endfor %}
-            </best-path-selection>
-            {% endif %}
-            {% if vprn.bgp.multipath is defined %}
-            <multipath>
-              {% if vprn.bgp.multipath.ibgp is defined %}
-                <ibgp>{{ vprn.bgp.multipath.ibgp }}</ibgp>
-              {% endif %}
-              {% if vprn.bgp.multipath.ebgp is defined %}
-                <ebgp>{{ vprn.bgp.multipath.ebgp }}</ebgp>
-              {% endif %}
-              {% if vprn.bgp.multipath.ipv4 is defined %}
-                <family>
-                    <family-type>ipv4</family-type>
-                    <max-paths>{{ vprn.bgp.multipath.ipv4 }}</max-paths>
-                </family>
-              {% endif %}
-              {% if vprn.bgp.multipath.ipv6 is defined %}
-                <family>
-                    <family-type>ipv6</family-type>
-                    <max-paths>{{ vprn.bgp.multipath.ipv6 }}</max-paths>
-                </family>
-              {% endif %}
-            </multipath>
-            {% endif %}
+          {% with bgp_base_obj=vprn.bgp, bgp_context='vprn' %}
+            {% include 'router/bgp_base.j2' %}
+          {% endwith %}
             {% with bgp_obj=vprn.bgp, bgp_group_context='vprn' %}
             {% include 'router/bgp_group.j2' %}
             {% endwith %}
-- 
GitLab