Skip to content
Open
Changes from 2 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
10 changes: 9 additions & 1 deletion plugins/modules/dcnm_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,9 @@ def get_next_vrf_id(self, fabric) -> int:
msg += f"{self.dcnm_version}"
self.module.fail_json(msg)

if vrf_id is not None:
break

if vrf_id is None:
msg = f"{self.class_name}.{method_name}: "
msg += "Unable to retrieve vrf_id "
Expand Down Expand Up @@ -2273,7 +2276,12 @@ def diff_merge_create(self, replace=False):
}

if self.dcnm_version > 11:
template_conf.update(isRPAbsent=json_to_dict.get("isRPAbsent"))
template_conf.update(
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline conditional in the update() call is difficult to read and maintain. Consider extracting this logic to a separate variable before the update:

vrf_vlan_id_value = "" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
template_conf.update(vrfVlanId=vrf_vlan_id_value)

This improves readability and makes the transformation logic more explicit.

Suggested change
template_conf.update(
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
vrf_vlan_id_value = "" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
template_conf.update(
vrfVlanId=vrf_vlan_id_value

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented suggestion in ^9608cc6

Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional check template_conf["vrfVlanId"] == 0 doesn't handle the case where vrfVlanId might be None. When json_to_dict.get("vrfVlanId") is called at line 2246 without a default value, it returns None if the key is missing.

Consider using a more defensive check:

template_conf.update(
    vrfVlanId="" if template_conf.get("vrfVlanId") in [0, None] else template_conf["vrfVlanId"]
)

Or alternatively, ensure vrfVlanId has a default value at line 2246:

"vrfVlanId": json_to_dict.get("vrfVlanId", 0),
Suggested change
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
vrfVlanId="" if template_conf.get("vrfVlanId") in [0, None] else template_conf["vrfVlanId"]

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented the defesive check in ^9608cc6

)
template_conf.update(
isRPAbsent=json_to_dict.get("isRPAbsent")
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the update for isRPAbsent related to creating the VRF without VNI or is it a separate issue? It's fine that it's added here, but am rather just curious about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not related. I just added the newline to standirize the elements inside the update function.

template_conf.update(
ENABLE_NETFLOW=json_to_dict.get("ENABLE_NETFLOW")
)
Expand Down
Loading