Skip to content

Commit 5d3b490

Browse files
authored
Allow configure fabric links in both direction (#629)
* Update existing_links_check.py * Update ndfc_fabric_links.j2 * Update links.yml * fix pep8
1 parent c721b58 commit 5d3b490

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

plugins/action/dtc/existing_links_check.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def run(self, tmp=None, task_vars=None):
5656
existing_link['sw1-info']['sw-sys-name'] = switch['management']['management_ipv4_address']
5757
if existing_link['sw2-info']['sw-sys-name'].lower() == switch['name'].lower():
5858
existing_link['sw2-info']['sw-sys-name'] = switch['management']['management_ipv4_address']
59+
60+
# Check if the existing link matches the fabric link in either direction
5961
if ((existing_link['sw1-info']['sw-sys-name'].lower() == link['src_device'].lower() and
6062
existing_link['sw1-info']['if-name'].lower() == link['src_interface'].lower() and
6163
existing_link['sw2-info']['sw-sys-name'].lower() == link['dst_device'].lower() and
@@ -64,11 +66,44 @@ def run(self, tmp=None, task_vars=None):
6466
existing_link['sw1-info']['if-name'].lower() == link['dst_interface'].lower() and
6567
existing_link['sw2-info']['sw-sys-name'].lower() == link['src_device'].lower() and
6668
existing_link['sw2-info']['if-name'].lower() == link['src_interface'].lower())):
69+
70+
# If the link is in reverse order, swap the src and dst to match
71+
# swap also in profile peer1 and peer2
72+
# Don't swap IP addresses, bc they are assigned based on existing link
73+
# and should not change
74+
if (
75+
existing_link['sw1-info']['sw-sys-name'].lower() == link['dst_device'].lower()
76+
and existing_link['sw1-info']['if-name'].lower() == link['dst_interface'].lower()
77+
and existing_link['sw2-info']['sw-sys-name'].lower() == link['src_device'].lower()
78+
and existing_link['sw2-info']['if-name'].lower() == link['src_interface'].lower()
79+
):
80+
link['src_device'], link['dst_device'] = link['dst_device'], link['src_device']
81+
link['src_interface'], link['dst_interface'] = link['dst_interface'], link['src_interface']
82+
# Safely swap descriptions without creating keys when absent
83+
p1_desc = link['profile'].pop('peer1_description', None)
84+
p2_desc = link['profile'].pop('peer2_description', None)
85+
if p2_desc is not None:
86+
link['profile']['peer1_description'] = p2_desc
87+
if p1_desc is not None:
88+
link['profile']['peer2_description'] = p1_desc
89+
# Safely swap freeform without creating keys when absent
90+
p1_free = link['profile'].pop('peer1_freeform', None)
91+
p2_free = link['profile'].pop('peer2_freeform', None)
92+
if p2_free is not None:
93+
link['profile']['peer1_freeform'] = p2_free
94+
if p1_free is not None:
95+
link['profile']['peer2_freeform'] = p1_free
96+
6797
if 'templateName' not in existing_link:
6898
not_required_links.append(link)
6999
elif existing_link['templateName'] == 'int_pre_provision_intra_fabric_link':
70100
required_links.append(link)
71101
elif existing_link['templateName'] == 'int_intra_fabric_num_link':
102+
# Populate additional fields from existing link
103+
# into the required link. IPs are assigned by ND and not managed in NaC Fabric link
104+
# at this time.
105+
# When template is defined as int_pre_provision_intra_fabric_link, template is converted
106+
# by ND to int_intra_fabric_num_link, when fabric-link is P2P and IPs are assigned.
72107
link['template'] = 'int_intra_fabric_num_link'
73108
link['profile']['peer1_ipv4_addr'] = existing_link['nvPairs']['PEER1_IP']
74109
link['profile']['peer2_ipv4_addr'] = existing_link['nvPairs']['PEER2_IP']

roles/dtc/common/templates/ndfc_fabric_links.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
mtu: "{{ link.mtu | default(defaults.vxlan.topology.fabric_links.mtu) }}"
3535
peer1_description: "{{ link.source_description | default('') }}"
3636
peer2_description: "{{ link.destination_description | default('') }}"
37+
{% if link.peer1_freeform is defined %}
38+
peer1_cmds: |2
39+
{{ link.peer1_freeform | indent(8) }}
40+
{% endif %}
41+
{% if link.peer2_freeform is defined %}
42+
peer2_cmds: |2
43+
{{ link.peer2_freeform | indent(8) }}
44+
{% endif %}
3745
{%- endif %}
3846
{%- endfor %}
3947
{%- endif %}

roles/dtc/create/tasks/common/links.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@
8686
src_fabric: "{{ MD_Extended.vxlan.fabric.name }}"
8787
config: "{{ required_links['required_links'] }}"
8888
deploy: false
89-
state: merged
89+
state: replaced
9090
register: manage_fabric_links_result

0 commit comments

Comments
 (0)