Skip to content

Commit b47dcf2

Browse files
committed
Initial work on this issue
1 parent cfbb0d8 commit b47dcf2

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

plugins/modules/dcnm_vrf.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@
578578
from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import (
579579
dcnm_get_ip_addr_info, dcnm_get_url, dcnm_send, dcnm_version_supported,
580580
get_fabric_details, get_fabric_inventory_details, get_ip_sn_dict,
581-
get_sn_fabric_dict, validate_list_of_dicts, search_nested_json)
581+
get_sn_fabric_dict, validate_list_of_dicts, search_nested_json,
582+
find_dict_in_list_by_key_value)
582583

583584
from ..module_utils.common.log_v2 import Log
584585

@@ -1656,10 +1657,10 @@ def get_have(self):
16561657
attach_list = vrf_attach["lanAttachList"]
16571658
deploy_vrf = ""
16581659
for attach in attach_list:
1659-
attach_state = not attach["lanAttachState"] == "NA"
1660-
deploy = attach["isLanAttached"]
1660+
attach_state = bool(attach.get("isLanAttached", False))
1661+
deploy = attach_state
16611662
deployed = False
1662-
if deploy and (
1663+
if attach_state and (
16631664
attach["lanAttachState"] == "OUT-OF-SYNC"
16641665
or attach["lanAttachState"] == "PENDING"
16651666
):
@@ -2064,10 +2065,17 @@ def get_diff_replace(self):
20642065
self.diff_deploy = diff_deploy
20652066
return
20662067

2068+
modified_all_vrfs = copy.deepcopy(all_vrfs)
2069+
for vrf in all_vrfs:
2070+
# If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list.
2071+
want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf)
2072+
if want_vrf_data['deploy'] is False:
2073+
modified_all_vrfs.remove(vrf)
2074+
20672075
if not self.diff_deploy:
2068-
diff_deploy.update({"vrfNames": ",".join(all_vrfs)})
2076+
diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)})
20692077
else:
2070-
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(all_vrfs)
2078+
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs)
20712079
diff_deploy.update({"vrfNames": vrfs})
20722080

20732081
self.diff_attach = copy.deepcopy(diff_attach)
@@ -2368,7 +2376,14 @@ def diff_merge_attach(self, replace=False):
23682376
if deploy_vrf:
23692377
all_vrfs.append(deploy_vrf)
23702378

2371-
if len(all_vrfs) != 0:
2379+
modified_all_vrfs = copy.deepcopy(all_vrfs)
2380+
for vrf in all_vrfs:
2381+
# If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list.
2382+
want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf)
2383+
if want_vrf_data['deploy'] is False:
2384+
modified_all_vrfs.remove(vrf)
2385+
2386+
if len(modified_all_vrfs) != 0:
23722387
diff_deploy.update({"vrfNames": ",".join(all_vrfs)})
23732388

23742389
self.diff_attach = diff_attach

0 commit comments

Comments
 (0)