nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
36 stars 32 forks source link

Add Endpoint.delete() method #131

Closed joewesch closed 7 months ago

joewesch commented 1 year ago

Many endpoints allow for bulk delete by sending in a list of ID's to the endpoint. We should allow for this feature in pynautobot.

Example usage:

import pynautobot
nautobot = pynautobot.api(
  url="http://localhost:8000", token="d6f4e314a5b5fefd164995169f28ae32d987704f",
)
devices = nautobot.dcim.devices
filtered_devices = devices.filter(name__ic="foo")
delete_payload = [{"id": d.id} for d in filtered_devices]
devices.delete(data=delete_payload)
tsm1th commented 7 months ago

I have this implemented and could submit a PR. It supports a list of objects or a list of ids from any endpoint. Is this what you were envisioning?

pynautobot.dcim.devices.delete(pynautobot.dcim.devices.all())

pynautobot.dcim.devices.delete(pynautobot.dcim.devices.filter(name__ic="foo"))

pynautobot.dcim.devices.delete(["db8770c4-61e5-4999-8372-e7fa576a4f65","e9b5f2e0-4f20-41ad-9179-90a4987f743e"])
joewesch commented 7 months ago

Yeah, if it can be dynamic and take both that sounds great.

tsm1th commented 7 months ago

Submitted the PR. Let me know if anything needs to be addressed prior to approving.