Skip to content
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
6 changes: 4 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3182,8 +3182,10 @@ def add_snmp_agent_address(ctx, agentip, port, vrf):
if not vrf:
entry = config_db.get_entry('MGMT_VRF_CONFIG', "vrf_global")
if entry and entry['mgmtVrfEnabled'] == 'true' :
click.echo("ManagementVRF is Enabled. Provide vrf.")
return False
mgmtintf_key_list = _get_all_mgmtinterface_keys()

Copilot AI Apr 17, 2025

Copy link

Choose a reason for hiding this comment

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

Verify that _get_all_mgmtinterface_keys() returns only management interface IPs and excludes any loopback interfaces. Consider adding a comment or validation to clarify its expected output.

Suggested change
mgmtintf_key_list = _get_all_mgmtinterface_keys()
mgmtintf_key_list = _get_all_mgmtinterface_keys()
# Filter out loopback interfaces to ensure only management interface IPs are included
mgmtintf_key_list = [key for key in mgmtintf_key_list if not key[0].startswith('lo')]

Copilot uses AI. Check for mistakes.
if any(ip.split('/')[0].lower() == agentip.lower() for _, ip in mgmtintf_key_list):

Copilot AI Apr 17, 2025

Copy link

Choose a reason for hiding this comment

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

Using string splitting for IP comparison may lead to issues if the IP format changes; consider using the ipaddress module for robust IP address comparisons (e.g., comparing ipaddress.ip_address values).

Suggested change
if any(ip.split('/')[0].lower() == agentip.lower() for _, ip in mgmtintf_key_list):
if any(str(ipaddress.ip_interface(ip).ip).lower() == agentip.lower() for _, ip in mgmtintf_key_list):

Copilot uses AI. Check for mistakes.
click.echo("ManagementVRF is Enabled. Provide vrf.")
return False
found = 0
ip = ipaddress.ip_address(agentip)
for intf in netifaces.interfaces():
Expand Down