From dc15912b867f8b68919f93ec5a303e54c9365e6d Mon Sep 17 00:00:00 2001 From: Aleksandr Kurbatov <aleksandr.kurbatov@GL1342-AKURBATOV.local> Date: Mon, 12 Aug 2024 18:07:52 +0100 Subject: [PATCH] policy-options rework decompose policy-options template into specific templates. --- .../templates/routers/nokia/pe_base_config.j2 | 1 + .../routers/nokia/policy_options/as_paths.j2 | 6 +++ .../nokia/policy_options/communities.j2 | 8 ++++ .../nokia/policy_options/policy_options.j2 | 43 +++++++------------ .../nokia/policy_options/policy_statements.j2 | 5 +-- .../nokia/policy_options/prefix_lists.j2 | 14 ++++++ 6 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/as_paths.j2 create mode 100644 geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/communities.j2 create mode 100644 geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/prefix_lists.j2 diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/pe_base_config.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/pe_base_config.j2 index 0df1cfb3..b2b897bc 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/pe_base_config.j2 +++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/pe_base_config.j2 @@ -2,6 +2,7 @@ <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf"> {% include 'ip_prefix_list.j2' %} {% include 'filters/cpm_filters.j2' %} + {% include 'policy_options/policy_options.j2' %} {% include 'cflowd.j2' %} {% include 'router/router_base.j2' %} {% include 'sdp_mesh.j2' %} diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/as_paths.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/as_paths.j2 new file mode 100644 index 00000000..fadb9c5b --- /dev/null +++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/as_paths.j2 @@ -0,0 +1,6 @@ + {% for as_path in as_paths_obj %} + <as-path alu:operation="replace"> + <name>{{ as_path.name }}</name> + <expression>{{ as_path.expression}}</expression> + </as-path> + {% endfor %} diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/communities.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/communities.j2 new file mode 100644 index 00000000..631ddacf --- /dev/null +++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/communities.j2 @@ -0,0 +1,8 @@ + {% for community in communities_obj %} + <community alu:operation="replace"> + <name>{{ community.name }}</name> + <member> + <member>{{ community.member }}</member> + </member> + </community> + {% endfor %} diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_options.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_options.j2 index 089e202d..047dc0e8 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_options.j2 +++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_options.j2 @@ -1,39 +1,26 @@ <policy-options 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 nokia_po_prefix_lists is defined %} - {% for prefix_list in nokia_po_prefix_lists %} - <prefix-list alu:operation="replace"> - <name>{{ prefix_list.name }}</name> - {% for prefix in prefix_list.prefixes %} - <prefix> - <ip-prefix>{{ prefix.ip }}</ip-prefix> - <type>{{ prefix.type }}</type> - {% if prefix.type == 'range' %} - <start-length>{{ prefix.range_start_length }}</start-length> - <end-length>{{ prefix.range_end_length }}</end-length> - {% endif %} - {% endfor %} - </prefix-list> - {% endfor %} + {% with prefix_lists_obj=nokia_po_prefix_lists %} + {% include 'policy_options/prefix_lists.j2' %} + {% endwith %} {% endif %} {# Communities #} {% if nokia_po_communities is defined %} - {% for community in nokia_po_communities %} - <community alu:operation="replace"> - <name>{{ community.name }}</name> - <member> - <member>{{ community.member }}</member> - </member> - </community> - {% endfor %} + {% with communities_obj=nokia_po_communities %} + {% include 'policy_options/communites.j2' %} + {% endwith %} {% endif %} {# AS paths #} {% if nokia_po_as_paths is defined %} - {% for as_path in nokia_po_as_paths %} - <as-path alu:operation="replace"> - <name>{{ as_path.name }}</name> - <expression>{{ as_path.expression}}</expression> - </as-path> - {% endfor %} + {% with as_paths_obj=nokia_po_as_paths %} + {% include 'policy_options/as_paths.j2' %} + {% endwith %} + {% endif %} +{# Policy statements #} + {% if nokia_po_policy_statements is defined %} + {% with policy_obj=nokia_po_policy_statements %} + {% include 'policy_options/policy_statement.j2' %} + {% endwith %} {% endif %} </policy-options> diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_statements.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_statements.j2 index 1da7e321..3e451852 100644 --- a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_statements.j2 +++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/policy_statements.j2 @@ -1,6 +1,4 @@ -<policy-options 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 nokia_po_policy_statements is defined %} - {% for pol in nokia_po_policy_statements %} + {% for pol in policy_obj %} <policy-statement alu:operation="replace"> <name>{{ pol.name }}</name> <entry-type>{{ pol.entry_type }}</entry-type> @@ -62,4 +60,3 @@ </policy-statement> {% endfor %} {% endif %} -</policy-options> diff --git a/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/prefix_lists.j2 b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/prefix_lists.j2 new file mode 100644 index 00000000..67529ea5 --- /dev/null +++ b/geant/gap_ansible/roles/promote_p_to_pe/templates/routers/nokia/policy_options/prefix_lists.j2 @@ -0,0 +1,14 @@ + {% for prefix_list in prefix_lists_obj %} + <prefix-list alu:operation="replace"> + <name>{{ prefix_list.name }}</name> + {% for prefix in prefix_list.prefixes %} + <prefix> + <ip-prefix>{{ prefix.ip }}</ip-prefix> + <type>{{ prefix.type }}</type> + {% if prefix.type == 'range' %} + <start-length>{{ prefix.range_start_length }}</start-length> + <end-length>{{ prefix.range_end_length }}</end-length> + {% endif %} + {% endfor %} + </prefix-list> + {% endfor %} -- GitLab