From 045d1a8e69358debdac5a111c09c6e11c270dde8 Mon Sep 17 00:00:00 2001
From: Aleksandr Kurbatov <ak@geant.org>
Date: Tue, 8 Oct 2024 21:02:18 +0100
Subject: [PATCH] BFD update for Nokia as a remaining side of a trunk

---
 .../iptrunk_migration/tasks/bfd_update.yaml   | 47 ++++++++++++++++---
 .../templates/nokia/bfd_update.j2             | 14 ++++++
 2 files changed, 55 insertions(+), 6 deletions(-)
 create mode 100644 geant/gap_ansible/roles/iptrunk_migration/templates/nokia/bfd_update.j2

diff --git a/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml b/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml
index 1a31076c..74842b76 100644
--- a/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml
+++ b/geant/gap_ansible/roles/iptrunk_migration/tasks/bfd_update.yaml
@@ -1,24 +1,59 @@
 ---
 - name: Update Trunk interface BFD on  "{{ inventory_hostname }}" [CHECK ONLY][JUNIPER]
+  when: >
+    verb == "update"
+    and
+    remaining_side.vendor == "juniper"
+    and
+    dry_run | ansible.builtin.bool
   junipernetworks.junos.junos_config:
     update: 'replace'
     src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
     src_format: set
     check_commit: true
   diff: true
-  when: >
-    verb == "update" and
-    remaining_side.vendor == "juniper" and
-    dry_run | ansible.builtin.bool
 
 - name: Update Trunk interface BFD on "{{ inventory_hostname }}" [AND COMMIT][JUNIPER]
+  when: >
+    verb == "update"
+    and
+    remaining_side.vendor == "juniper"
+    and
+    not (dry_run | ansible.builtin.bool)
   junipernetworks.junos.junos_config:
     update: 'replace'
     src: "/var/tmp/ansible_run_{{ opid }}/{{ config_object }}.conf"
     src_format: set
     comment: "{{ commit_comment }}"
   diff: true
+
+- name: Update Trunk interface BFD on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA]
+  when: >
+    verb == "update"
+    and
+    remaining_side.vendor == "nokia"
+    and
+    dry_run | ansible.builtin.bool
+  geant.gap_ansible.nokia_netconf_config:
+    format: xml
+    default_operation: merge
+    content: "{{ lookup('ansible.builtin.template', '{{ remaining_side.vendor }}/{{ config_object }}.j2') }}"
+    commit: true
+  diff: true
+  check_mode: true
+
+- name: Update Trunk interface BFD on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
   when: >
-    verb == "update" and
-    remaining_side.vendor == "juniper" and
+    verb == "update"
+    and
+    remaining_side.vendor == "nokia"
+    and
     not (dry_run | ansible.builtin.bool)
+  geant.gap_ansible.nokia_netconf_config:
+    format: xml
+    default_operation: merge
+    content: "{{ lookup('ansible.builtin.template', '{{ remaining_side.vendor }}/{{ config_object }}.j2') }}"
+    commit: true
+    commit_comment: "{{ commit_comment }}"
+  diff: true
+  check_mode: false
diff --git a/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/bfd_update.j2 b/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/bfd_update.j2
new file mode 100644
index 00000000..7bbc7131
--- /dev/null
+++ b/geant/gap_ansible/roles/iptrunk_migration/templates/nokia/bfd_update.j2
@@ -0,0 +1,14 @@
+<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:alu="urn:ietf:params:xml:ns:netconf:base:1.0">
+    <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf">
+
+    <lag 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">
+          <lag-name>{{ remaining_side.ae_name | lower }}</lag-name>
+          <bfd-liveness>
+              <ipv4>
+                  <remote-ip-address alu:operation="replace">{{ new_node.router.router_lo_ipv4_address }}</remote-ip-address>
+              </ipv4>
+          </bfd-liveness>
+      </lag>
+  </configure>
+</config>
+
-- 
GitLab