Skip to content

Commit

Permalink
Merge pull request #167 from nautobot/release-v2.1.0
Browse files Browse the repository at this point in the history
Release v2.1.0
  • Loading branch information
jvanderaa authored Feb 29, 2024
2 parents f17e47d + 3b45c4a commit 66ebf7f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 28 additions & 0 deletions docs/advanced/delete.rst
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions docs/advanced/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 66ebf7f

Please sign in to comment.