From 303cd690346450b82108c81825d9a1a0937e6222 Mon Sep 17 00:00:00 2001 From: Aleksandr Kurbatov <ak@geant.org> Date: Tue, 14 Jan 2025 19:41:45 +0000 Subject: [PATCH] Update `policy_options` for LHCONE access --- .../roles/policy_options/tasks/main.yml | 29 ++++++++++++++++++- .../tasks/merge_vrf_custom_vars.yaml | 16 ++++++++++ ...vars.yaml => merge_vrf_standard_vars.yaml} | 4 +++ .../templates/policy_statements.j2 | 5 ++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 geant/gap_ansible/roles/policy_options/tasks/merge_vrf_custom_vars.yaml rename geant/gap_ansible/roles/policy_options/tasks/{merge_vrf_vars.yaml => merge_vrf_standard_vars.yaml} (66%) diff --git a/geant/gap_ansible/roles/policy_options/tasks/main.yml b/geant/gap_ansible/roles/policy_options/tasks/main.yml index a896fc3b..4c3793bf 100644 --- a/geant/gap_ansible/roles/policy_options/tasks/main.yml +++ b/geant/gap_ansible/roles/policy_options/tasks/main.yml @@ -1,5 +1,21 @@ --- # tasks file for policy_options +- name: Set BGP V4 session object to check for custom policies + when: > + subscription.product.product_type == "L3CoreService" + ansible.builtin.set_fact: + bgp_session_v4: "{{ ap.sbp | json_query(query) }}" + vars: + query: "bgp_session_list[?ip_type == 'ipv4'] | [0]" + +- name: Set BGP V6 session object to check for custom policies + when: > + subscription.product.product_type == "L3CoreService" + ansible.builtin.set_fact: + bgp_session_v6: "{{ ap.sbp | json_query(query) }}" + vars: + query: "bgp_session_list[?ip_type == 'ipv6'] | [0]" + - name: Load Standard Policy Statements vars when: > subscription.product.product_type == "L3CoreService" @@ -7,10 +23,21 @@ subscription.l3_core_service_type in ["GÉANT IP", "GEANT IP", "GEANT_IP"] ansible.builtin.include_tasks: merge_geant_ip_vars.yaml +- name: Load NREN custom VRF policies + when: > + subscription.product.product_type == "L3CoreService" + and + subscription.l3_core_service_type in ["LHCONE"] + and + (bgp_session_v4.has_custom_policies | ansible.builtin.bool + or + bgp_session_v6.has_custom_policies | ansible.builtin.bool) + ansible.builtin.include_tasks: merge_vrf_custom_vars.yaml + - name: Load Standard Policy Options for VRF {{ subscription.vrf.vrf_name }} when: > subscription.product.product_type == "VRF" - ansible.builtin.include_tasks: merge_vrf_vars.yaml + ansible.builtin.include_tasks: merge_vrf_standard_vars.yaml - name: Compile templates ansible.builtin.include_tasks: compile.yaml diff --git a/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_custom_vars.yaml b/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_custom_vars.yaml new file mode 100644 index 00000000..e223ce3a --- /dev/null +++ b/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_custom_vars.yaml @@ -0,0 +1,16 @@ +--- +- name: Set custom PO vars + # when: > + # bgp_session_v6.has_custom_policies | ansible.builtin.bool + block: + - name: Set NREN custom communities + ansible.builtin.set_fact: + po_final_communities: "{{ lookup('community.general.merge_variables', 'CUSTOM_COMMUNITIES') }}" + + # - name: Set NREN custom AS paths + # ansible.builtin.set_fact: + # po_final_aspath: "{{ lookup('community.general.merge_variables', 'CUSTOM_ASPATH') }}" + + - name: Set NREN custom policies + ansible.builtin.set_fact: + po_final_policies: "{{ lookup('community.general.merge_variables', 'CUSTOM_PO_POL_STATEMENTS') }}" diff --git a/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_vars.yaml b/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_standard_vars.yaml similarity index 66% rename from geant/gap_ansible/roles/policy_options/tasks/merge_vrf_vars.yaml rename to geant/gap_ansible/roles/policy_options/tasks/merge_vrf_standard_vars.yaml index 528a7b45..b832e4e0 100644 --- a/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_vars.yaml +++ b/geant/gap_ansible/roles/policy_options/tasks/merge_vrf_standard_vars.yaml @@ -3,6 +3,10 @@ ansible.builtin.set_fact: po_final_prefix_lists: "{{ lookup('community.general.merge_variables', 'STANDARD_VRF_PO_PREFIX_LISTS') }}" +- name: Load Standard Policy Options prefix lists for VRF {{ subscription.vrf.vrf_name }} + ansible.builtin.set_fact: + po_final_communities: "{{ lookup('community.general.merge_variables', 'STANDARD_VRF_COMMUNITIES') }}" + - name: Load Standard Policy Options policies for VRF {{ subscription.vrf.vrf_name }} ansible.builtin.set_fact: po_final_policies: "{{ lookup('community.general.merge_variables', 'STANDARD_VRF_PO_POLICIES') }}" diff --git a/geant/gap_ansible/roles/policy_options/templates/policy_statements.j2 b/geant/gap_ansible/roles/policy_options/templates/policy_statements.j2 index 32570140..1dd917a6 100644 --- a/geant/gap_ansible/roles/policy_options/templates/policy_statements.j2 +++ b/geant/gap_ansible/roles/policy_options/templates/policy_statements.j2 @@ -57,6 +57,11 @@ <add>{{ community }}</add> </community> {% endfor %} + {% elif act_k == "as_path_prepend" %} + <as-path-prepend> + <as-path>{{ act_v.as_path }}</as-path> + <repeat>{{ act_v.repeat }}</repeat> + </as-path-prepend> {% elif act_k == "bgp_med" %} <bgp-med> <set>{{ act_v | default(bgp.standard_metric.med[ap_type]) }}</set> -- GitLab