Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new example with pynautobot #53

Merged
merged 25 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be0954c
Add exampele3 with pynautobot
dgarros Jun 18, 2021
9b0ffb1
Replace sub region with population, add diff and flags
dgarros Oct 8, 2021
5288b5f
Pylint and pydocstyle
dgarros Oct 11, 2021
144820d
exclude examples and docs from mypy
dgarros Oct 11, 2021
8c2d17e
exclude examples and docs from pylint
dgarros Oct 11, 2021
8a4cbd9
Update examples/example3/main.py
dgarros Oct 12, 2021
23ce5b3
Update examples/example3/diff.py
dgarros Oct 12, 2021
7578196
Update examples/example3/local_adapter.py
dgarros Oct 12, 2021
0685de8
Update examples/example3/local_adapter.py
dgarros Oct 12, 2021
f91d5c4
Update examples/example3/local_adapter.py
dgarros Oct 12, 2021
db21ce1
Update examples/example3/README.md
dgarros Oct 12, 2021
1eb9b3e
Update examples/example3/README.md
dgarros Oct 12, 2021
29a0995
Update examples/example3/README.md
dgarros Oct 12, 2021
9924b1d
Update examples/example3/local_adapter.py
dgarros Oct 12, 2021
f1382c2
Update examples/example3/local_adapter.py
dgarros Oct 12, 2021
1f73b74
Update examples/example3/main.py
dgarros Oct 12, 2021
bd43009
Update examples/example3/main.py
dgarros Oct 12, 2021
38e8dd9
Update examples/example3/main.py
dgarros Oct 12, 2021
b0e8b54
Update examples/example3/nautobot_adapter.py
dgarros Oct 12, 2021
b99649d
Update examples/example3/nautobot_adapter.py
dgarros Oct 12, 2021
06ec2d2
Update examples/example3/nautobot_adapter.py
dgarros Oct 12, 2021
b307176
Update examples/example3/nautobot_adapter.py
dgarros Oct 12, 2021
c91eeb5
Update format with black
dgarros Oct 14, 2021
efd36a7
Reenable pylint on the examples folder
dgarros Oct 14, 2021
e47dd69
fix import error for pylint in example3
dgarros Oct 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/example1/backend_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# pylint: disable=wrong-import-order
from diffsync import DiffSync
from models import Site, Device, Interface
from models import Site, Device, Interface # pylint: disable=no-name-in-module

DATA = {
"nyc": {
Expand Down
2 changes: 1 addition & 1 deletion examples/example1/backend_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# pylint: disable=wrong-import-order
from diffsync import DiffSync
from models import Site, Device, Interface
from models import Site, Device, Interface # pylint: disable=no-name-in-module

DATA = {
"atl": {
Expand Down
2 changes: 1 addition & 1 deletion examples/example1/backend_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# pylint: disable=wrong-import-order
from diffsync import DiffSync
from models import Site, Device, Interface
from models import Site, Device, Interface # pylint: disable=no-name-in-module

DATA = {
"nyc": {
Expand Down
41 changes: 41 additions & 0 deletions examples/example3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Example 3

This is a simple example to show how DiffSync can be used to compare and synchronize data with a remote system like [Nautobot](https://nautobot.readthedocs.io) via a REST API.

For this example, we have a shared model for Region and Country defined in `models.py`.
A country must be part of a region and has an attribute to capture its population.

The comparison and synchronization of dataset is done between a local JSON file and the [public instance of Nautobot](https://demo.nautobot.com).


## Install the requirements

to use this example you must have some dependencies installed, please make sure to run
```
pip install -r requirements.txt
```

## Setup the environment

By default this example will interact with the public sandbox of Nautobot at https://demo.nautobot.com but you can use your own version of Nautobot by providing a new URL and a new API token using the environment variables `NAUTOBOT_URL` & `NAUTOBOT_TOKEN`

```
export NAUTOBOT_URL = "https://demo.nautobot.com"
export NAUTOBOT_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
```

## Try the example

The first time you run this example, a lot of changes should be reported between Nautobot and the local data because by default the demo instance doesn't have the subregion defined.
After the first sync, on subsequent runs, the diff should show no changes.
At this point, `Diffsync` will be able to identify and fix all changes in Nautobot. You can try to add/update or delete any country in Nautobot and DiffSync will automatically catch it and it will fix it with running in sync mode.

```
### DIFF Compare the data between Nautobot and the local JSON file.
python main.py --diff

### SYNC Update the list of country in Nautobot.
python main.py --sync
```

Loading