Skip to content

[WIP] VRFs should never deploy when deploy flag is False #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions plugins/modules/dcnm_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@
from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import (
dcnm_get_ip_addr_info, dcnm_get_url, dcnm_send, dcnm_version_supported,
get_fabric_details, get_fabric_inventory_details, get_ip_sn_dict,
get_sn_fabric_dict, validate_list_of_dicts, search_nested_json)
get_sn_fabric_dict, validate_list_of_dicts, search_nested_json,
find_dict_in_list_by_key_value)

from ..module_utils.common.log_v2 import Log

Expand Down Expand Up @@ -1656,10 +1657,10 @@ def get_have(self):
attach_list = vrf_attach["lanAttachList"]
deploy_vrf = ""
for attach in attach_list:
attach_state = not attach["lanAttachState"] == "NA"
deploy = attach["isLanAttached"]
attach_state = bool(attach.get("isLanAttached", False))
deploy = attach_state
deployed = False
if deploy and (
if attach_state and (
attach["lanAttachState"] == "OUT-OF-SYNC"
or attach["lanAttachState"] == "PENDING"
):
Expand Down Expand Up @@ -2064,11 +2065,19 @@ def get_diff_replace(self):
self.diff_deploy = diff_deploy
return

if not self.diff_deploy:
diff_deploy.update({"vrfNames": ",".join(all_vrfs)})
else:
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(all_vrfs)
diff_deploy.update({"vrfNames": vrfs})
modified_all_vrfs = copy.deepcopy(all_vrfs)
for vrf in all_vrfs:
# If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list.
want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf)
if want_vrf_data.get('deploy', True) is False:
modified_all_vrfs.remove(vrf)

if modified_all_vrfs:
if not diff_deploy:
diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)})
else:
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs)
diff_deploy.update({"vrfNames": vrfs})

self.diff_attach = copy.deepcopy(diff_attach)
self.diff_deploy = copy.deepcopy(diff_deploy)
Expand Down Expand Up @@ -2368,8 +2377,19 @@ def diff_merge_attach(self, replace=False):
if deploy_vrf:
all_vrfs.append(deploy_vrf)

if len(all_vrfs) != 0:
diff_deploy.update({"vrfNames": ",".join(all_vrfs)})
modified_all_vrfs = copy.deepcopy(all_vrfs)
for vrf in all_vrfs:
# If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list.
want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf)
if want_vrf_data.get("deploy", True) is False:
modified_all_vrfs.remove(vrf)

if modified_all_vrfs:
if not diff_deploy:
diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)})
else:
vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs)
diff_deploy.update({"vrfNames": vrfs})

self.diff_attach = diff_attach
self.diff_deploy = diff_deploy
Expand Down