Skip to content

Conversation

lmacken
Copy link

@lmacken lmacken commented Jun 26, 2025

This patch is an attempt to fix an error with doing --update-all on machines that have an existing NIC in netbox with missing MAC addresses. This state triggered this exception:

DEBUG:urllib3.connectionpool:[https://netbox.farmgpu.net:443](https://netbox.farmgpu.net/) "GET /api/dcim/interfaces/?mac_address=90%3A5a%3A08%3A0e%3A30%3A1c&name=ens4059f0np0&device_id=119&limit=0 HTTP/1.1" 200 None
INFO:root:Interface 90:5a:08:0e:30:1c not found, creating..
INFO:root:Creating NIC ens4059f0np0 (90:5a:08:0e:30:1c) on intel-minio-1
DEBUG:urllib3.connectionpool:[https://netbox.farmgpu.net:443](https://netbox.farmgpu.net/) "POST /api/dcim/interfaces/ HTTP/1.1" 400 67
Traceback (most recent call last):
  File "/home/fgpu/myenv/bin/netbox_agent", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/fgpu/myenv/lib/python3.12/site-packages/netbox_agent/cli.py", line 63, in main
    return run(config)
           ^^^^^^^^^^^
  File "/home/fgpu/myenv/lib/python3.12/site-packages/netbox_agent/cli.py", line 56, in run
    server.netbox_create_or_update(config)
  File "/home/fgpu/myenv/lib/python3.12/site-packages/netbox_agent/server.py", line 425, in netbox_create_or_update
    self.network.create_or_update_netbox_network_cards()
  File "/home/fgpu/myenv/lib/python3.12/site-packages/netbox_agent/network.py", line 463, in create_or_update_netbox_network_cards
    interface = self.create_netbox_nic(nic)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fgpu/myenv/lib/python3.12/site-packages/netbox_agent/network.py", line 297, in create_netbox_nic
    interface = self.nb_net.interfaces.create(**params)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fgpu/myenv/lib/python3.12/site-packages/pynetbox/core/endpoint.py", line 417, in create
    ).post(args[0] if args else kwargs)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fgpu/myenv/lib/python3.12/site-packages/pynetbox/core/query.py", line 370, in post
    return self._make_call(verb="post", data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fgpu/myenv/lib/python3.12/site-packages/pynetbox/core/query.py", line 260, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'__all__': ['Interface with this Device and Name already exists.']}

This patch seems to update the existing device with the new MAC address properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant