netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.93k stars 2.56k forks source link

Interface description update (pynetbox 5.0.5) #5770

Closed sngx13 closed 3 years ago

sngx13 commented 3 years ago

Hi,

Looks like an update of interface descriptions is not working, I've followed few guides so far with the same result.

update_intf = nb.dcim.interfaces.get(intf_id)
update_intf.description = intf_descr
update_intf.save()

Getting the following error:

pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'non_field_errors': ['Expected a list of items but got type "dict".']}

if update_intf.save is used instead of update_intf.save(), scripts succeeds but descriptions are not actually updated.

Interestingly when I do the same via Python3 interpreter it works:

>>> intf = nb.dcim.interfaces.get(3280)
>>> intf.serialize()
{'id': 3280, 'url': 'https://ipam.serviceworks.cloud/api/dcim/interfaces/3280/', 'device': 63, 'name': 'XGE1/0/1', 'label': '', 'type': '10gbase-x-sfpp', 'enabled': True, 'lag': None, 'mtu': None, 'mac_address': None, 'mgmt_only': False, 'description': 'testing...', 'mode': None, 'untagged_vlan': None, 'tagged_vlans': [], 'cable': None, 'cable_peer': None, 'cable_peer_type': None, 'connected_endpoint': None, 'connected_endpoint_type': None, 'connected_endpoint_reachable': None, 'tags': [211], 'count_ipaddresses': 0}
>>> intf.description = "Test-123"
>>> intf.save
>>> intf.serialize()
{'id': 3280, 'url': 'https://ipam.serviceworks.cloud/api/dcim/interfaces/3280/', 'device': 63, 'name': 'XGE1/0/1', 'label': '', 'type': '10gbase-x-sfpp', 'enabled': True, 'lag': None, 'mtu': None, 'mac_address': None, 'mgmt_only': False, 'description': 'Test-123', 'mode': None, 'untagged_vlan': None, 'tagged_vlans': [], 'cable': None, 'cable_peer': None, 'cable_peer_type': None, 'connected_endpoint': None, 'connected_endpoint_type': None, 'connected_endpoint_reachable': None, 'tags': [211], 'count_ipaddresses': 0}

Thank you

sngx13 commented 3 years ago

Turns out Netbox version and Pynetbox were out of sync version wise, updated both to latest and it worked as per docs.