pynetbox
pynetbox copied to clipboard
Nebox device tags wont update by save or serializing
pynetbox==5.0.4 python3.7.5 Netbox 59d3e65b7ed2 (v2.7.10)
Here is what I have tried to get the tags for a device to update.
I am using a token generated with write access.
For some reason the tags never update, despite return True.
In [46]: dev = nb.dcim.devices.get(31114)
In [47]: dev.tags
Out[47]: ['not in billing']
In [48]: dev.tags.extend(["test702"])
In [49]: dev.tags
Out[49]: ['not in billing', 'test702']
In [50]: dev.save()
Out[50]: True
In [51]: dev = nb.dcim.devices.get(31114)
In [52]: dev.tags
Out[52]: ['not in billing']
In [53]: dev.tags = dev.tags + ["test702"]
In [54]: dev.tags
Out[54]: ['not in billing', 'test702']
In [55]: dev.save()
Out[55]: True
In [56]: dev = nb.dcim.devices.get(31114)
In [57]: dev.tags
Out[57]: ['not in billing']
In [58]: dev_data = dev.serialize()
In [59]: dev_data["tags"]
Out[59]: ['not in billing']
In [60]: dev_data["tags"].extend(["test702"])
In [61]: dev_data["tags"]
Out[61]: ['not in billing', 'test702']
In [62]: dev.update(dev_data)
Out[62]: True
In [63]: dev = nb.dcim.devices.get(31114)
In [64]: dev.tags
Out[64]: ['not in billing']
Seems ok for me. This is on NetBox 2.7.12 though.
>>> nb = pynetbox.api("https://netbox", token="hunter2")
>>> x = nb.dcim.devices.get(123)
>>> x
test-device
>>> x.tags
[]
>>> x.tags.append("test")
>>> x.save()
True
>>> x = nb.dcim.devices.get(123)
>>> x.tags
['test']
>>> x.tags.append("test2")
>>> x.save()
True
>>> x = nb.dcim.devices.get(123)
>>> x.tags
['test', 'test2']
>>>
You could trying adding something like this to get a little better picture of what's happening between pynetbox and NetBox
import http
http.client.HTTPConnection.debuglevel = 1
Debugging command helps.
Was getting a HTTP/1.1 301 Moved Permanently
Turns out I needed to use HTTPS when instantiating the api object. All is good now. Would be kinda cool if .save() would not return True unless it was a HTTP/1.1 200 OK, but I am nitpicking. This is a very nice api.
Thank you for your time.
Would be kinda cool if .save() would not return True unless it was a HTTP/1.1 200 OK, but I am nitpicking.
That's probably fair, iirc, we look at response.ok
from requests which gets set to True if the response code is <400.
Since there is no update on this thread for more than 3 years, I'm going to close it for now. If the change in the status code is required a new FR can be opened.