From 3b45c4ac434dc468f11c3b814379a33d8e92e806 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 27 Feb 2024 14:14:29 -0600 Subject: [PATCH] Release v2.1.0 --- CHANGELOG.md | 11 +++++++++++ docs/advanced/delete.rst | 28 ++++++++++++++++++++++++++++ docs/advanced/update.rst | 31 +++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 docs/advanced/delete.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 32aff5d..ab0f289 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## v2.1.0 + +### New Features + +- (#163) Adds `Endpoint.delete` method for bulk deleting of records +- (#165) Adds `Endpoint.update` method for bulk updating of records + +### Fixes + +- (#162) Corrects signature of `RODetailEndpoint.create` to provide a proper error that it is not implemented when using `api_version` + ## v2.0.2 ### Fixes diff --git a/docs/advanced/delete.rst b/docs/advanced/delete.rst new file mode 100644 index 0000000..5c96f2f --- /dev/null +++ b/docs/advanced/delete.rst @@ -0,0 +1,28 @@ +Deleting Multiple Objects +========================= + +The :ref:`Deleting Records` section shows how to use the +:py:meth:`~pynautobot.core.response.Record.delete` method to delete a single record. +Another way to accomplish this for multiple records at once is to use the +:py:meth:`~pynautobot.core.endpoint.Endpoint.delete` method. + +.. code-block:: python + + >>> import os + >>> from pynautobot import api + >>> + >>> url = os.environ["NAUTOBOT_URL"] + >>> token = os.environ["NAUTOBOT_TOKEN + >>> nautobot = api(url=url, token=token) + >>> + >>> # Delete multiple devices by passing a list of UUIDs + >>> device_uuids = [ + >>> "a3e2f3e4-5b6c-4d5e-8f9a-1b2c3d4e5f6a", + >>> "b3e2f3e4-5b6c-4d5e-8f9a-1b2c3d4e5f6b", + >>> "c3e2f3e4-5b6c-4d5e-8f9a-1b2c3d4e5f6c", + >>> ] + >>> nautobot.dcim.devices.delete(device_uuids) + >>> + >>> # Delete all devices with a name starting with "Test" + >>> test_devices = nautobot.dcim.devices.filter(name__sw="Test") + >>> nautobot.dcim.devices.delete(test_devices) diff --git a/docs/advanced/update.rst b/docs/advanced/update.rst index ed08788..d4b6ec1 100644 --- a/docs/advanced/update.rst +++ b/docs/advanced/update.rst @@ -181,3 +181,34 @@ The examples updates a Device record, however this can apply to other API References: * :ref:`Gathering Data from GraphQL Endpoint` + +Updating Multiple Objects +------------------------- + +The :py:meth:`~pynautobot.core.endpoint.Endpoint.update` method can also be used to update multiple +items with a single call. You can pass in a list of dictionaries, each containing the +``id`` and the fields to be updated, or a list of :py:class:`~pynautobot.core.response.Record`. + +.. code-block:: python + + >>> import os + >>> from pynautobot import api + >>> + >>> url = os.environ["NAUTOBOT_URL"] + >>> token = os.environ["NAUTOBOT_TOKEN + >>> nautobot = api(url=url, token=token) + >>> + >>> # Add a comment to multiple devices by passing in a list of dictionaries + >>> updated_devices = nautobot.dcim.devices.update([ + >>> {"id": "db8770c4-61e5-4999-8372-e7fa576a4f65", "comments": "removed from service"}, + >>> {"id": "e9b5f2e0-4f20-41ad-9179-90a4987f743e", "comments": "removed from service"}, + >>> ]) + >>> + >>> # Get a list of all devices + >>> devices = nautobot.dcim.devices.all() + >>> # Update the status and name fields for all records + >>> for device in devices: + >>> device.status = "Decommissioned" + >>> device.comments = "removed from service" + >>> # And then update them all at once + >>> updated_devices = nautobot.dcim.devices.update(devices) diff --git a/pyproject.toml b/pyproject.toml index 9614c4e..667cd22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "pynautobot" -version = "2.0.2" +version = "2.1.0" description = "Nautobot API client library" authors = ["Network to Code, LLC "] readme = "README.md"