Skip to content

Commit

Permalink
Merge pull request #128 from nautobot/develop
Browse files Browse the repository at this point in the history
1.5 Release to Main
  • Loading branch information
jvanderaa authored Jun 23, 2023
2 parents f4a61f0 + f350c73 commit 18f2717
Show file tree
Hide file tree
Showing 21 changed files with 1,028 additions and 637 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,21 @@ jobs:
fail-fast: true
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
nautobot-version: ["1.2", "1.3"]
nautobot-version: ["1.2", "1.3", "stable"]
exclude:
- python-version: 3.10
nautobot-version: 1.2
env:
PYTHON_VER: "${{ matrix.python-version }}"
NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
INVOKE_LOCAL: true
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Install CICD dependencies"
run: "pip install -U pip && pip install poetry"
- name: "Install project dependencies via Poetry"
run: "poetry install"
- name: "Start containers"
run: "poetry run invoke start"
- name: "Wait for Nautobot to become available."
run: "poetry run invoke wait"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
- name: "Set up Docker Buildx"
id: "buildx"
uses: "docker/setup-buildx-action@v1"
- name: "Tests"
run: "poetry run invoke tests"
publish_pypi:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/upstream_testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: "Nautobot Upstream Monitor"

on: # yamllint disable-line rule:truthy rule:comments
schedule:
- cron: "0 4 */2 * *" # every other day at midnight

jobs:
upstream-test:
uses: "nautobot/nautobot/.github/workflows/plugin_upstream_testing_base.yml@develop"
with: # Below could potentially be collapsed into a single argument if a concrete relationship between both is enforced
invoke_context_name: "PYNAUTOBOT"
plugin_name: "pynautobot"
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## v1.5.0

### New Features

- (#125) Adds Update Method based on ID to keep within the pynautobot experience to update a device (@jamesharr)

```python
import os
from pynautobot import api
url = os.environ["NAUTOBOT_URL"]
token = os.environ["NAUTOBOT_TOKEN"]
nautobot = api(url=url, token=token)
# Update status and name fields
result = nautobot.dcim.devices.update(
id="491d799a-eeee-bbbb-aaaa-7c5cbb5b71b6",
data={
"comments": "removed from service",
"status": "decommissioned",
},
)
```

## v.1.4.0

### New Features
Expand Down
12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

18 changes: 18 additions & 0 deletions development/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG PYTHON_VER

FROM python:${PYTHON_VER}-slim

RUN apt-get -y update && apt-get -y install --no-install-recommends \
curl \
git \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org | python3 - && \
/root/.local/bin/poetry config virtualenvs.create false

WORKDIR /source
COPY pyproject.toml poetry.lock /source/

RUN git config --global --add safe.directory /source

RUN /root/.local/bin/poetry install --no-interaction --no-ansi
4 changes: 4 additions & 0 deletions development/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*

!/pyproject.toml
!/poetry.lock
2 changes: 2 additions & 0 deletions development/creds.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Empty file to mimic plugins that requires a creds file for upstream testing
# [see](https://github.com/nautobot/nautobot/blob/develop/.github/workflows/plugin_upstream_testing_base.yml#L47)
26 changes: 26 additions & 0 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
---
version: "3"

x-common: &common
image: "${IMAGE_NAME}:${IMAGE_VER}"
volumes:
- "${PWD}:/source"

services:
pynautobot-dev:
<<: *common
build:
context: "${PWD}"
dockerfile: "development/Dockerfile"
args:
PYTHON_VER: "${PYTHON_VER}"
pynautobot-dev-tests:
<<: *common
depends_on:
nautobot:
condition: "service_healthy"
nautobot:
image: "ghcr.io/nautobot/nautobot-dev:${NAUTOBOT_VER:-1.3}-py${PYTHON_VER:-3.7}"
command: "nautobot-server runserver 0.0.0.0:8000 --insecure"
Expand All @@ -12,6 +30,14 @@ services:
env_file:
- "./dev.env"
tty: true
healthcheck:
interval: "30s"
timeout: "10s"
start_period: "2m"
retries: 4
test:
- "CMD-SHELL"
- "curl --fail http://localhost:8000/health/ || exit 1"
postgres:
image: "postgres:13"
env_file:
Expand Down
9 changes: 9 additions & 0 deletions docs/advanced/graphql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ This example shows accessing data from the previous query.
>>> # Get the name of the first site
>>> graphql_response.json["data"]["sites"][0]["name"]
'den'
Saving Changes
--------------
The Nautobot GraphQL API is currently read-only. To make updates to objects, see:
* :ref:`Updating objects without loading data`
* :py:meth:`~pynautobot.core.endpoint.Endpoint.update`
40 changes: 40 additions & 0 deletions docs/advanced/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,43 @@ and fetching the object from Nautobot shows that ``face`` has also been left unc
Front
>>> tmp_hq_access_5.position
42
Updating objects without loading data
-------------------------------------

In some cases it may not be necessary to load an object to update it, for example
if the ID and updated fields are known, the call HTTP PATCH may be made without
performing an :py:meth:`~pynautobot.core.endpoint.Endpoint.get` first.

In this case, the :py:meth:`~pynautobot.core.endpoint.Endpoint.update` method may
be used to directly submit a PATCH to the Nautobot REST API. Using this reduces
the number of API calls. It can be particularly useful as a way to update data
fetched from the GraphQL API.

The examples updates a Device record, however this can apply to other API
:py:class:`~pynautobot.core.endpoint.Endpoint` types.

.. 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)
# Update status and name fields
result = nautobot.dcim.devices.update(
id="491d799a-2b4d-41fc-80e1-7c5cbb5b71b6",
data={
"comments": "removed from service",
"status": "decommissioned",
},
)
print(result) # will output True if successful
References:

* :ref:`Gathering Data from GraphQL Endpoint`
Loading

0 comments on commit 18f2717

Please sign in to comment.