Skip to content

Commit c398c61

Browse files
glennmatthewschadellKircheneer
authored
Version 1.5.1 (#119)
* New Example06 - IP Prefixes (#111) * first draft of example06 Co-authored-by: Glenn Matthews <[email protected]> * Attempt to fix the read the docs pipeline. (#115) * Attempt to fix the read the docs pipeline. * Yamllint. Co-authored-by: Leo Kirchner <[email protected]> * Update CODEOWNERS (#113) * Fix get() by modelname (#118) * Update example05 (#107) * Update example05 * Use site as children * Add update after adding children * Add pylint disable until Redis code is in * Update example * simplify * wip * wip * Update example * Take redis from main * imprort order * yml * update readme * Use diffsync from pypi * Apply suggestions from code review Co-authored-by: Glenn Matthews <[email protected]> * Code review * replace bash by python exec * Rename dockerfile to Dockerfile * Update docs source Co-authored-by: Glenn Matthews <[email protected]> * Update CHANGELOG and bump version Co-authored-by: Christian Adell <[email protected]> Co-authored-by: Leo Kirchner <[email protected]> Co-authored-by: Leo Kirchner <[email protected]>
1 parent 9e11129 commit c398c61

32 files changed

+568
-108
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Default owners for all files in this repository
2-
* @glennmatthews @dgarros
2+
* @glennmatthews @Kircheneer @chadell

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,6 @@ fabric.properties
289289

290290
## Sphinx Documentation ##
291291
docs/build
292+
293+
## Secrets
294+
creds.env

.readthedocs.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ sphinx:
77
fail_on_warning: false
88

99
python:
10-
version: 3.7
10+
version: "3.7"
1111
install:
12-
- method: "pip"
13-
path: "."
14-
extra_requirements:
15-
- "docs"
12+
- requirements: "docs/requirements.txt"

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## v1.5.1 - 2022-06-30
4+
5+
### Added
6+
7+
- #111 - Added example 6, regarding IP prefixes.
8+
9+
### Changed
10+
11+
- #107 - Updated example 5 to use the Redis backend store.
12+
13+
### Fixed
14+
15+
- #115 - Fixed ReadTheDocs rendering pipeline
16+
- #118 - Fixed a regression in `DiffSync.get(modelname, identifiers)` introduced in 1.5.0
17+
318
## v1.5.0 - 2022-06-07
419

520
### Added

diffsync/store/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def _get_object_class_and_model(
194194
"""Get object class and model name for a model."""
195195
if isinstance(model, str):
196196
modelname = model
197-
if not hasattr(self, model):
197+
if not hasattr(self.diffsync, model):
198198
return None, modelname
199-
object_class = getattr(self, model)
199+
object_class = getattr(self.diffsync, model)
200200
else:
201201
object_class = model
202202
modelname = model.get_type()
@@ -216,7 +216,7 @@ def _get_uid(
216216
uid = object_class.create_unique_id(**identifier)
217217
else:
218218
raise ValueError(
219-
f"Invalid args: ({model}, {identifier}): "
220-
f"either {model} should be a class/instance or {identifier} should be a str"
219+
f"Invalid args: ({model}, {object_class}, {identifier}): "
220+
f"either {object_class} should be a class/instance or {identifier} should be a str"
221221
)
222222
return uid

docs/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
m2r2==0.2.7
2+
mistune==0.8.4
3+
sphinx==4.5.0
4+
toml==0.10.2
5+
sphinx-rtd-theme==1.0.0

docs/source/api/diffsync.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ API Reference
1616
diffsync.helpers
1717
diffsync.logging
1818
diffsync.utils
19+
20+
Subpackages
21+
-----------
22+
23+
.. toctree::
24+
:maxdepth: 4
25+
26+
diffsync.store
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diffsync.store.local
2+
====================
3+
4+
.. automodule:: diffsync.store.local
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
diffsync.store.redis
2+
====================
3+
4+
.. automodule:: diffsync.store.redis
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/source/api/diffsync.store.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
API Reference
2+
=============
3+
4+
.. automodule:: diffsync.store
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
10+
.. toctree::
11+
:maxdepth: 4
12+
13+
diffsync.store.local
14+
diffsync.store.redis

docs/source/examples/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ For each example, the complete source code is `available in Github <https://gith
88
.. mdinclude:: ../../../examples/02-callback-function/README.md
99
.. mdinclude:: ../../../examples/03-remote-system/README.md
1010
.. mdinclude:: ../../../examples/04-get-update-instantiate/README.md
11+
.. mdinclude:: ../../../examples/05-nautobot-peeringdb/README.md
12+
.. mdinclude:: ../../../examples/06-ip-prefixes/README.md

docs/source/template/api/package.rst_t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
{{ automodule(pkgname, automodule_options) }}
2424
{% endif %}
2525

26-
{%- if subpackages %}
27-
Subpackages
28-
-----------
29-
30-
{{ toctree(subpackages) }}
31-
{% endif %}
32-
3326
{%- if submodules %}
3427
{% if separatemodules %}
3528
{{ toctree(submodules) }}
@@ -43,9 +36,16 @@ Subpackages
4336
{%- endif %}
4437
{%- endif %}
4538

39+
{%- if subpackages %}
40+
Subpackages
41+
-----------
42+
43+
{{ toctree(subpackages) }}
44+
{% endif %}
45+
4646
{%- if not modulefirst and not is_namespace %}
4747
Module contents
4848
---------------
4949

5050
{{ automodule(pkgname, automodule_options) }}
51-
{% endif %}
51+
{% endif %}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG PYTHON_VER=3.8.10
2+
3+
FROM python:${PYTHON_VER}-slim
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends git \
7+
&& apt-get purge -y --auto-remove \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /local
11+
COPY . /local
12+
13+
RUN pip install --upgrade pip \
14+
&& pip install -r requirements.txt

examples/05-nautobot-peeringdb/README.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,61 @@
44

55
The goal of this example is to synchronize some data from [PeeringDB](https://www.peeringdb.com/), that as the name suggests is a DB where peering entities define their facilities and presence to facilitate peering, towards [Nautobot Demo](https://demo.nautobot.com/) that is a always on demo service for [Nautobot](https://nautobot.readthedocs.io/), an open source Source of Truth.
66

7-
In Peering DB there is a model that defines a `Facility` and you can get information about the actual data center and the city where it is placed. In Nautobot, this information could be mapped to the `Region` and `Site` models, where `Region` can define hierarchy. For instance, Barcelona is in Spain and Spain is in Europe, and all of them are `Regions`. And, finally, the actual datacenter will refer to the `Region` where it is placed.
7+
In Peering DB there is a model that defines a `Facility` and you can get information about the actual data center and the city where it is placed. In Nautobot, this information could be mapped to the `Region` and `Site` models, where `Region` can depend from other `Region` and also contain `Site` as children. For instance, Barcelona is in Spain and Spain is in Europe, and all of them are `Regions`. And, finally, the actual datacenter will refer to the `Region` where it is placed.
88

9-
Because of the nature of the demo, we will focus on syncing from PeeringDB to Nautobot (we can assume that PeeringDB is the authoritative System of Record) and we will skip the `delete` part of the `diffsync` library.
9+
Because of the nature of the demo, we will focus on syncing from PeeringDB to Nautobot (we assume that PeeringDB is the authoritative System of Record) and we will skip the `delete` part of the `diffsync` library, using diffsync flags.
1010

1111
We have 3 files:
1212

1313
- `models.py`: defines the reference models that we will use: `RegionMode` and `SiteModel`
1414
- `adapter_peeringdb.py`: defines the PeeringDB adapter to translate via `load()` the data from PeeringDB into the reference models commented above. Notice that we don't define CRUD methods because we will sync from it (no to it)
15-
- `adapter_nautobot.py`: deifnes the Nautobot adapter with the `load()` and the CRUD methods
15+
- `adapter_nautobot.py`: defines the Nautobot adapter with the `load()` and the CRUD methods
1616

1717
> The source code for this example is in Github in the [examples/05-nautobot-peeringdb/](https://github.com/networktocode/diffsync/tree/main/examples/05-nautobot-peeringdb) directory.
1818
19-
## Install dependencies
19+
## Get PeeringDB API Key (optional)
20+
21+
To ensure a good performance from PeeringDB API, you should provide an API Key: https://docs.peeringdb.com/howto/api_keys/
22+
23+
Then, copy the example `creds.example.env` into `creds.env`, and place your new API Key.
2024

2125
```bash
22-
python3 -m venv .venv
23-
source .venv/bin/activate
24-
pip3 install -r requirements.txt
26+
$ cp examples/05-nautobot-peeringdb/creds.example.env examples/05-nautobot-peeringdb/creds.env
27+
2528
```
2629

27-
## Run it interactively
30+
> Without API Key it might also work, but it could fail due to API rate limiting.
2831
29-
```python
30-
from IPython import embed
31-
embed(colors="neutral")
32+
## Set up local docker environment
3233

33-
# Import Adapters
34-
from diffsync.enum import DiffSyncFlags
34+
```bash
35+
$ docker-compose -f examples/05-nautobot-peeringdb/docker-compose.yml up -d --build
36+
37+
$ docker exec -it 05-nautobot-peeringdb_example_1 python
38+
```
39+
40+
## Interactive execution
3541

42+
```python
3643
from adapter_nautobot import NautobotRemote
3744
from adapter_peeringdb import PeeringDB
45+
from diffsync.enum import DiffSyncFlags
46+
from diffsync.store.redis import RedisStore
47+
48+
store_one = RedisStore(host="redis")
49+
store_two = RedisStore(host="redis")
3850

3951
# Initialize PeeringDB adapter, using CATNIX id for demonstration
40-
peeringdb = PeeringDB(ix_id=62)
52+
peeringdb = PeeringDB(
53+
ix_id=62,
54+
internal_storage_engine=store_one
55+
)
4156

4257
# Initialize Nautobot adapter, pointing to the demo instance (it's also the default settings)
4358
nautobot = NautobotRemote(
4459
url="https://demo.nautobot.com",
45-
token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
60+
token="a" * 40,
61+
internal_storage_engine=store_two
4662
)
4763

4864
# Load PeeringDB info into the adapter
@@ -55,12 +71,11 @@ peeringdb.dict()
5571
nautobot.load()
5672

5773
# Let's diffsync do it's magic
58-
diff = nautobot.diff_from(peeringdb)
74+
diff = nautobot.diff_from(peeringdb, flags=DiffSyncFlags.SKIP_UNMATCHED_DST)
5975

6076
# Quick summary of the expected changes (remember that delete ones are dry-run)
6177
diff.summary()
6278

6379
# Execute the synchronization
6480
nautobot.sync_from(peeringdb, flags=DiffSyncFlags.SKIP_UNMATCHED_DST)
65-
6681
```

0 commit comments

Comments
 (0)