pynautobot icon indicating copy to clipboard operation
pynautobot copied to clipboard

Add notes support for all models that support notes

Open whitej6 opened this issue 1 year ago • 4 comments

Improve notes support

Current State

API does not have a "notes" attr in the return payload and only returns "notes_url" as a link to a list view for all notes that apply to the current instance.

Proposal

Provide ".notes" on any model that provides notes and the attribute would be an pynautobot.core.endpoint.Endpoint to allow for create update and delete operations scoped to just the current model instance

Example desired outcome

dev = py_nb.dcim.devices.get(name="foo")
count(dev.notes.all()) # return N notes created on a device named foo
note = dev.notes.create(note="bar")
note.note="baz"
note.save()

count(dev.notes.all()) # return being N+1 of previous count

whitej6 avatar Nov 30 '23 00:11 whitej6

Working on checking some things out on this. But first look at using demo.nautobot.com as a reference, there is a notes API endpoint: /extras/notes.

There is an assigned_object_id reference on the GET reference that would be used to get the notes for the object.

jvanderaa avatar Nov 30 '23 00:11 jvanderaa

So what we are looking at really is a convenience function to help things out, rather than anything is not usable today right?

jvanderaa avatar Nov 30 '23 00:11 jvanderaa

I support the convenience methods as long as it is not something that is only available to the SDK, in that it leverages the current SDK framework.

jvanderaa avatar Nov 30 '23 00:11 jvanderaa

It's a convenience method to match API functionality. When using /api/dcim/devices/<uuid>/notes/ you can post with just {"note": "some note"} without having to account for generic foreign key etc. Also the same endpoint will return a list of all notes for just the one device.

whitej6 avatar Nov 30 '23 14:11 whitej6

Those routes that extend beyond the traditional endpoints are currently handled with the DetailEndpoint class and the routes must be explicitly defined on the model needing them. This can easily be implemented for the Device model using that method and results in the following after testing:

dev = py_nb.dcim.devices.get(name="foo")
len(dev.notes.list()) # return N notes created on a device named foo
dev.notes.create({"note": "bar"}) # pass dictionary of data to create
len(dev.notes.list()) # return being N+1 of previous count

Extending that to all the models (that support notes) would be a heavier lift and require more work.

tsm1th avatar Jul 16 '24 12:07 tsm1th