Deleting non-existent interface NIC0 returns error 400 - Expected a list of items but got type "dict"
Hello,
I am trying to register a proxmox device into my netbox server and nothing seems to work as expected. I have checked project's dependencies as mentioned in the repo's requirements.txt and they seem ok. The problem is the following:
root@prmx# netbox_agent -c /etc/netbox_agent.yml --register
INFO:root:Creating server (serial: XXXX) prmx
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "POST /api/dcim/devices/ HTTP/1.1" 201 1161
DEBUG:root:Updating Server...
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "OPTIONS /api/dcim/interfaces/ HTTP/1.1" 200 17503
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "OPTIONS /api/ipam/ip-addresses/ HTTP/1.1" 200 9224
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/dcim/devices/?serial=XXXX HTTP/1.1" 200 1213
DEBUG:root:Creating/Updating NIC...
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/dcim/interfaces/?device_id=326 HTTP/1.1" 200 1794
INFO:root:Deleting netbox interface NIC0 because not present locally
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "DELETE /api/dcim/interfaces/ HTTP/1.1" 400 72
Traceback (most recent call last):
File "/usr/local/bin/netbox_agent", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/cli.py", line 44, in main
return run(config)
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/cli.py", line 39, in run
server.netbox_create_or_update(config)
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/server.py", line 292, in netbox_create_or_update
self.network.create_or_update_netbox_network_cards()
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/network.py", line 379, in create_or_update_netbox_network_cards
nic.delete()
File "/usr/local/lib/python3.7/dist-packages/pynetbox/core/response.py", line 439, in delete
return True if req.delete() else False
File "/usr/local/lib/python3.7/dist-packages/pynetbox/core/query.py", line 396, in delete
return self._make_call(verb="delete")
File "/usr/local/lib/python3.7/dist-packages/pynetbox/core/query.py", line 267, in _make_call
raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'non_field_errors': ['Expected a list of items but got type "dict".']}
Is that an compatibility problem between the netbox server version (v2.10.3) and the netbox_agent client, or maybe a related issue with pynetbox needs patching as mentioned in 177?
Also I do not understand why 3 network interfaces (NIC0, NIC1, iDRAG) are being created, after the device entry is created on the netbox server, as those interfaces do not exists on the proxmox host. If I manually delete these interfaces from netbox server and try to run the register command again then the followin happens:
root@prmx# netbox_agent -c /etc/netbox_agent.yml --register
DEBUG:root:Updating Server...
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "OPTIONS /api/dcim/interfaces/ HTTP/1.1" 200 17503
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "OPTIONS /api/ipam/ip-addresses/ HTTP/1.1" 200 9224
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/dcim/devices/?serial=XXXX HTTP/1.1" 200 1213
DEBUG:root:Creating/Updating NIC...
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/dcim/interfaces/?device_id=327 HTTP/1.1" 200 52
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/dcim/interfaces/?mac_address=XxXxXx&name=vmbr0&device_id=327 HTTP/1.1" 200 52
INFO:root:Interface XxXxXx not found, creating..
INFO:root:Creating NIC vmbr0 (XxXxXx) on prmx
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "POST /api/dcim/interfaces/ HTTP/1.1" 201 580
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/ipam/ip-addresses/?address=PVE_IP%2F24 HTTP/1.1" 200 512
DEBUG:urllib3.connectionpool:https://PVE_IP:443 "GET /api/ipam/ip-addresses/1124/ HTTP/1.1" 200 460
Traceback (most recent call last):
File "/usr/local/bin/netbox_agent", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/cli.py", line 44, in main
return run(config)
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/cli.py", line 39, in run
server.netbox_create_or_update(config)
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/server.py", line 292, in netbox_create_or_update
self.network.create_or_update_netbox_network_cards()
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/network.py", line 444, in create_or_update_netbox_network_cards
self.create_or_update_netbox_ip_on_interface(ip, interface)
File "/usr/local/lib/python3.7/dist-packages/netbox_agent/network.py", line 347, in create_or_update_netbox_ip_on_interface
if netbox_ip.interface is None:
File "/usr/local/lib/python3.7/dist-packages/pynetbox/core/response.py", line 196, in __getattr__
raise AttributeError('object has no attribute "{}"'.format(k))
AttributeError: object has no attribute "interface"
Any help or guideline would be appreciated.
Hi @sebek88
The master branch doesn't handle netbox with versions >= 2.9, there's a PR that I've been testing since a few days and seems stable and compatible with the last Netbox API changes I'd be interested in getting your feedback about it
I'm going to merge it anyway in a few days after further testing
Hello @Solvik
Sorry I could not reply earlier as I did not have time to test netbox_agent as you mentioned in your comment. It seems that branch 177 does not handle netbox versions > 2.9 (my server is v2.10.3), as I get exactly the same stack trace as mentioned before. By switching to that branch and executing the registration command (--register) the outcome is the same.