You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
We hit the issue noted by the FIXME in the code that results from the same VLAN ID existing in Netbox across datacenters:
def get_or_create_vlan(self, vlan_id):
# FIXME: we may need to specify the datacenter
# since users may have same vlan id in multiple dc
vlan = nb.ipam.vlans.get(
vid=vlan_id,
)
if vlan is None:
vlan = nb.ipam.vlans.create(
name='VLAN {}'.format(vlan_id),
vid=vlan_id,
)
return vlan
Error raised:
INFO:root:Resetting tagged VLAN(s) on interface eno1.1234
DEBUG:urllib3.connectionpool:http://***:****/ "GET /api/ipam/vlans/?vid=1234&limit=0 HTTP/1.1" 200 2790
Traceback (most recent call last):
File "/root/nb/venv/bin/netbox_agent", line 11, in <module>
load_entry_point('netbox-agent==0.7.1', 'console_scripts', 'netbox_agent')()
File "/root/nb/venv/lib/python3.7/site-packages/netbox_agent/cli.py", line 50, in main
return run(config)
File "/root/nb/venv/lib/python3.7/site-packages/netbox_agent/cli.py", line 43, in run
server.netbox_create_or_update(config)
File "/root/nb/venv/lib/python3.7/site-packages/netbox_agent/server.py", line 413, in netbox_create_or_update
self.network.create_or_update_netbox_network_cards()
File "/root/nb/venv/lib/python3.7/site-packages/netbox_agent/network.py", line 448, in create_or_update_netbox_network_cards
ret, interface = self.reset_vlan_on_interface(nic, interface)
File "/root/nb/venv/lib/python3.7/site-packages/netbox_agent/network.py", line 244, in reset_vlan_on_interface
nb_vlan = self.get_or_create_vlan(vlan_id)
File "/root/nb/venv/lib/python3.7/site-packages/netbox_agent/network.py", line 204, in get_or_create_vlan
vid=vlan_id,
File "/root/nb/venv/lib/python3.7/site-packages/pynetbox/core/endpoint.py", line 148, in get
"get() returned more than one result. "
ValueError: get() returned more than one result. Check that the kwarg(s) passed are valid for this endpoint or use filter() or all() instead.
Expected behavior
When querying for the VLANs netbox-agent should include the datacenter as a filter.
We were able to work around this issue with the following edit:
diff --git a/netbox_agent/network.py b/netbox_agent/network.py
index 673dfc1..0793454 100644
--- a/netbox_agent/network.py
+++ b/netbox_agent/network.py
@@ -202,6 +202,7 @@ class Network(object):
# since users may have same vlan id in multiple dc
vlan = nb.ipam.vlans.get(
vid=vlan_id,
+ site=self.server.get_datacenter(),
)
if vlan is None:
vlan = nb.ipam.vlans.create(
If this approach is a reasonable one, I'd be happy to open a PR for the specific change.
Over the years I haven't had any network setup with similar VLAN IDs across datacenters, especially since modern networks use BGP/EVPN, so I guess we could finally add this parameter to filter out this.
Would you mind opening a PR ?
As for maintaining, I must confess I wasn't very active these past few months/years ; you should really thank @cyrinux who took over for quite some time :)
tze089
added a commit
to ChessCom/netbox-agent
that referenced
this issue
Feb 2, 2024
Describe the bug
We hit the issue noted by the
FIXME
in the code that results from the same VLAN ID existing in Netbox across datacenters:Error raised:
Expected behavior
When querying for the VLANs netbox-agent should include the datacenter as a filter.
We were able to work around this issue with the following edit:
If this approach is a reasonable one, I'd be happy to open a PR for the specific change.
Configuration file
Environment:
Additional context
Thank you for sharing and helping maintaining this wonderful tool!
The text was updated successfully, but these errors were encountered: