Skip to content

Commit 4aa5602

Browse files
VRFs should never deploy when deploy flag is False (#491)
* Initial work on this issue * Updated dcnm_vrf to honor deploy flag * Fixed whitespace sanity issue --------- Co-authored-by: Neil John <[email protected]>
1 parent c475d35 commit 4aa5602

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

plugins/modules/dcnm_vrf.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@
584584
from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import (
585585
dcnm_get_ip_addr_info, dcnm_get_url, dcnm_send, dcnm_version_supported,
586586
get_fabric_details, get_fabric_inventory_details, get_ip_sn_dict,
587-
get_sn_fabric_dict, validate_list_of_dicts, search_nested_json)
587+
get_sn_fabric_dict, validate_list_of_dicts, search_nested_json,
588+
find_dict_in_list_by_key_value)
588589

589590
from ..module_utils.common.log_v2 import Log
590591

@@ -1675,10 +1676,10 @@ def get_have(self):
16751676
attach_list = vrf_attach["lanAttachList"]
16761677
deploy_vrf = ""
16771678
for attach in attach_list:
1678-
attach_state = not attach["lanAttachState"] == "NA"
1679-
deploy = attach["isLanAttached"]
1679+
attach_state = bool(attach.get("isLanAttached", False))
1680+
deploy = attach_state
16801681
deployed = False
1681-
if deploy and (
1682+
if attach_state and (
16821683
attach["lanAttachState"] == "OUT-OF-SYNC"
16831684
or attach["lanAttachState"] == "PENDING"
16841685
):
@@ -2083,11 +2084,19 @@ def get_diff_replace(self):
20832084
self.diff_deploy = diff_deploy
20842085
return
20852086

2086-
if not self.diff_deploy:
2087-
diff_deploy.update({"vrfNames": ",".join(all_vrfs)})
2088-
else:
2089-
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(all_vrfs)
2090-
diff_deploy.update({"vrfNames": vrfs})
2087+
modified_all_vrfs = copy.deepcopy(all_vrfs)
2088+
for vrf in all_vrfs:
2089+
# If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list.
2090+
want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf)
2091+
if want_vrf_data.get('deploy', True) is False:
2092+
modified_all_vrfs.remove(vrf)
2093+
2094+
if modified_all_vrfs:
2095+
if not diff_deploy:
2096+
diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)})
2097+
else:
2098+
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs)
2099+
diff_deploy.update({"vrfNames": vrfs})
20912100

20922101
self.diff_attach = copy.deepcopy(diff_attach)
20932102
self.diff_deploy = copy.deepcopy(diff_deploy)
@@ -2388,8 +2397,19 @@ def diff_merge_attach(self, replace=False):
23882397
if deploy_vrf:
23892398
all_vrfs.append(deploy_vrf)
23902399

2391-
if len(all_vrfs) != 0:
2392-
diff_deploy.update({"vrfNames": ",".join(all_vrfs)})
2400+
modified_all_vrfs = copy.deepcopy(all_vrfs)
2401+
for vrf in all_vrfs:
2402+
# If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list.
2403+
want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf)
2404+
if want_vrf_data.get("deploy", True) is False:
2405+
modified_all_vrfs.remove(vrf)
2406+
2407+
if modified_all_vrfs:
2408+
if not diff_deploy:
2409+
diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)})
2410+
else:
2411+
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs)
2412+
diff_deploy.update({"vrfNames": vrfs})
23932413

23942414
self.diff_attach = diff_attach
23952415
self.diff_deploy = diff_deploy

0 commit comments

Comments
 (0)