Skip to content

Commit

Permalink
Vpc peering enhancement (#84)
Browse files Browse the repository at this point in the history
* Switchover vPC peeri interface prep to use dcnm_links

change from provisioning interfaces to provisioning links

* Remove vpc peering before switch delete

* fix feedbacks from PR 84

* add removal for links

* fix state
  • Loading branch information
rrahimm authored May 2, 2024
1 parent df179d4 commit 4b1a3c7
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 117 deletions.
9 changes: 8 additions & 1 deletion roles/dtc/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
- name: Build NDFC Fabric Switch Inventory List From Template
ansible.builtin.include_tasks: ndfc_inventory.yml

# --------------------------------------------------------------------
# Build Fabric intra links for vpc peering From Template
# --------------------------------------------------------------------

- name: Build intra fabric links From Template
ansible.builtin.include_tasks: ndfc_link_vpc_peering.yml

# --------------------------------------------------------------------
# Build VPC Peering parameter List From Template
# --------------------------------------------------------------------
Expand Down Expand Up @@ -123,4 +130,4 @@
# --------------------------------------------------------------------

- name: Build Fabric interface All List From Template
ansible.builtin.include_tasks: ndfc_interface_all.yml
ansible.builtin.include_tasks: ndfc_interface_all.yml
18 changes: 18 additions & 0 deletions roles/dtc/common/tasks/ndfc_link_vpc_peering.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Set link_vpc_peering_file_name Var
ansible.builtin.set_fact:
link_vpc_peering_file_name: "{{ MD.fabric.global.name }}_ndfc_link_vpc_peering_.yml"

- name: Build Links for VPC Peering
ansible.builtin.template:
src: ndfc_links_vpc_peering.j2
dest: "{{ role_path }}/files/{{ link_vpc_peering_file_name }}"

- name: Set link_vpc_peering Var default
ansible.builtin.set_fact:
link_vpc_peering: []

- name: Set link_vpc_peering Var
ansible.builtin.set_fact:
link_vpc_peering: "{{ lookup('file', link_vpc_peering_file_name) | from_yaml }}"
when: MD_Extended.fabric.topology.vpc_peers | length > 0
20 changes: 1 addition & 19 deletions roles/dtc/common/tasks/ndfc_vpc_peering.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
---
- name: Set interface_vpc_peering_file_name Var
ansible.builtin.set_fact:
interface_vpc_peering_file_name: "{{ MD.fabric.global.name }}_ndfc_interface_vpc_peering_.yml"

- name: Build Interfaces for VPC Peering
ansible.builtin.template:
src: ndfc_interface_vpc_peering.j2
dest: "{{ role_path }}/files/{{ interface_vpc_peering_file_name }}"

- name: Set interface_vpc_peering Var default
ansible.builtin.set_fact:
interface_vpc_peering: []

- name: Set interface_vpc_peering Var
ansible.builtin.set_fact:
interface_vpc_peering: "{{ lookup('file', interface_vpc_peering_file_name) | from_yaml }}"
when: MD_Extended.fabric.topology.vpc_peers | length > 0

- name: Set vpc_peering_file_name Var
ansible.builtin.set_fact:
vpc_peering_file_name: "{{ MD.fabric.global.name }}_ndfc_vpc_peering.yml"
Expand All @@ -33,4 +15,4 @@
- name: Set vpc_peering Var
ansible.builtin.set_fact:
vpc_peering: "{{ lookup('file', vpc_peering_file_name) | from_yaml }}"
when: MD_Extended.fabric.topology.vpc_peers | length > 0
when: MD_Extended.fabric.topology.vpc_peers | length > 0
38 changes: 0 additions & 38 deletions roles/dtc/common/templates/ndfc_interface_vpc_peering.j2

This file was deleted.

31 changes: 31 additions & 0 deletions roles/dtc/common/templates/ndfc_links_vpc_peering.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# This NDFC links for vPC Peering is auto-generated
# DO NOT EDIT MANUALLY
#
#jinja2: trim_blocks: True, lstrip_blocks: False
{% for peers in MD_Extended.fabric.topology.vpc_peers %}
{% for interface_index in range(peers['peer1_peerlink_interfaces']|length) %}
{% set peer1_interface = peers['peer1_peerlink_interfaces'][interface_index] %}
{% set peer2_interface = peers['peer2_peerlink_interfaces'][interface_index] %}
{% if peer1_interface is defined and peer2_interface is defined %}
- dst_fabric : {{ MD_Extended.fabric.global.name }}
template: int_pre_provision_intra_fabric_link
src_interface: {{peer1_interface.name}}
dst_interface: {{peer2_interface.name}}
src_device:
{% set switch = MD_Extended.fabric.topology.leaf[peers.peer1] %}
{% if switch.management_ipv4_address is defined %}
{{ switch.management_ipv4_address}}
{% elif (switch.management_ipv4_address is not defined) and (switch.management_ipv6_address is defined) %}
{{ switch.management_ipv6_address}}
{% endif %}
dst_device:
{% set switch = MD_Extended.fabric.topology.leaf[peers.peer2] %}
{% if switch.management_ipv4_address is defined %}
{{ switch.management_ipv4_address}}
{% elif (switch.management_ipv4_address is not defined) and (switch.management_ipv6_address is defined) %}
{{ switch.management_ipv6_address}}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
84 changes: 55 additions & 29 deletions roles/dtc/create/tasks/vpc_peering.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
---

- name: Query for vPC Peering Interfaces
cisco.dcnm.dcnm_interface:
fabric: "{{ MD.fabric.global.name }}"
state: query
config: "{{ interface_vpc_peering }}"
register: interface_vpc_peering_query

- name: Get Interfaces Not Associated to vPC Peering Policy
ansible.builtin.set_fact:
interface_not_vpc_policy: "{{ interface_vpc_peering_query.response | community.general.json_query(vpc_peer_policy_query) }}"
vars:
vpc_peer_policy_query: "[?(@.policy!=`int_vpc_peer_link_po_member_11_1`)]"

- name: Generate Config Payload Update for Interfaces Not Associated to vPC Peering Policy
ansible.builtin.set_fact:
interface_vpc_peering_payload: "{{ lookup('template', 'ndfc_interface_vpc_peer_link.j2') }}"
when: interface_not_vpc_policy | length > 0
# --------------------------------------------------------------------
# Manage Intra Fabric Links Configuration on NDFC (prepare links for vpc peering)
# --------------------------------------------------------------------

- name: Manage Interfaces for vPC Peering
cisco.dcnm.dcnm_interface:
fabric: "{{ MD.fabric.global.name }}"
- name: Manage Intra Fabric Links for vpc peering
cisco.dcnm.dcnm_links:
state: replaced
config: "{{ interface_vpc_peering_payload | from_yaml }}"
deploy: true
src_fabric: "{{ MD_Extended.fabric.global.name }}"
config: "{{ link_vpc_peering }}"
vars:
ansible_command_timeout: 3000
ansible_connect_timeout: 3000
when: interface_not_vpc_policy | length > 0

# tune this based on field testing. for now we are leaving at 60 seconds to allow the interfaces to come up.
# we can also look at the interface status and wait for the interfaces to be up before proceeding.
- name: Wait for vPC Peering Interfaces to come up
ansible.builtin.pause:
seconds: 60
when: interface_not_vpc_policy | length > 0
# --------------------------------------------------------------------
# Manage vPC Peering
# --------------------------------------------------------------------

- name: Manage vPC Peering
cisco.dcnm.dcnm_vpc_pair:
src_fabric: "{{ MD.fabric.global.name }}"
deploy: false
state: replaced
config: "{{ vpc_peering }}"



# - name: Query for vPC Peering Interfaces
# cisco.dcnm.dcnm_interface:
# fabric: "{{ MD.fabric.global.name }}"
# state: query
# config: "{{ interface_vpc_peering }}"
# register: interface_vpc_peering_query

# - name: Get Interfaces Not Associated to vPC Peering Policy
# ansible.builtin.set_fact:
# interface_not_vpc_policy: "{{ interface_vpc_peering_query.response | community.general.json_query(vpc_peer_policy_query) }}"
# vars:
# vpc_peer_policy_query: "[?(@.policy!=`int_vpc_peer_link_po_member_11_1`)]"

# - name: Generate Config Payload Update for Interfaces Not Associated to vPC Peering Policy
# ansible.builtin.set_fact:
# interface_vpc_peering_payload: "{{ lookup('template', 'ndfc_interface_vpc_peer_link.j2') }}"
# when: interface_not_vpc_policy | length > 0

# - name: Manage Interfaces for vPC Peering
# cisco.dcnm.dcnm_interface:
# fabric: "{{ MD.fabric.global.name }}"
# state: replaced
# config: "{{ interface_vpc_peering_payload | from_yaml }}"
# deploy: true
# vars:
# ansible_command_timeout: 3000
# ansible_connect_timeout: 3000
# when: interface_not_vpc_policy | length > 0

# # tune this based on field testing. for now we are leaving at 60 seconds to allow the interfaces to come up.
# # we can also look at the interface status and wait for the interfaces to be up before proceeding.
# - name: Wait for vPC Peering Interfaces to come up
# ansible.builtin.pause:
# seconds: 60
# when: interface_not_vpc_policy | length > 0

# - name: Manage vPC Peering
# cisco.dcnm.dcnm_vpc_pair:
# src_fabric: "{{ MD.fabric.global.name }}"
# deploy: false
# state: replaced
# config: "{{ vpc_peering }}"
21 changes: 0 additions & 21 deletions roles/dtc/create/templates/ndfc_interface_vpc_peer_link.j2

This file was deleted.

28 changes: 19 additions & 9 deletions roles/dtc/remove/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
state: overridden
config: "{{ vrf_config }}"

- debug: msg="Removing all Unmanaged vPC Peering. This could take several minutes..."
- name: Remove vPC Peering
cisco.dcnm.dcnm_vpc_pair:
src_fabric: "{{ MD.fabric.global.name }}"
deploy: true
state: overridden
config: "{{ vpc_peering }}"

- debug: msg="Removing all Unmanaged links. This could take several minutes..."
- name: Remove Intra Fabric Links for vpc peering
cisco.dcnm.dcnm_links:
state: replaced
src_fabric: "{{ MD_Extended.fabric.global.name }}"
config: "{{ link_vpc_peering }}"
vars:
ansible_command_timeout: 3000
ansible_connect_timeout: 3000

- debug: msg="Removing Unmanaged Fabric Switches. This could take several minutes..."
- name: Remove NDFC Fabric Devices {{ MD.fabric.global.name }}
cisco.dcnm.dcnm_inventory:
Expand All @@ -41,12 +59,4 @@
state: overridden
vars:
ansible_command_timeout: 3000
ansible_connect_timeout: 3000

- debug: msg="Removing all Unmanaged vPC Peering. This could take several minutes..."
- name: Remove vPC Peering
cisco.dcnm.dcnm_vpc_pair:
src_fabric: "{{ MD.fabric.global.name }}"
deploy: false
state: overridden
config: "{{ vpc_peering }}"
ansible_connect_timeout: 3000

0 comments on commit 4b1a3c7

Please sign in to comment.