Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 30
Update example05#107
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Update example05 #107
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
60fbe2d
Update example05
chadell 4b04776
Use site as children
chadell 5110a0d
Add update after adding children
chadell 9a5ae11
Add pylint disable until Redis code is in
chadell 66e8af0
Update example
chadell 30c4998
simplify
chadell 210ddd8
wip
chadell e2b3732
wip
chadell 6b06281
Update example
chadell 7554162
Take redis from main
chadell 5cd0503
Merge branch 'example05-update' of github.com:networktocode/diffsync …
chadell 4888266
imprort order
chadell a15d346
yml
chadell 614d1bd
update readme
chadell fb31505
Use diffsync from pypi
chadell 31869c4
Apply suggestions from code review
chadell e9f5f70
Merge remote-tracking branch 'origin/develop' into example05-update
chadell 8ebab53
Code review
chadell 3bd0f6f
replace bash by python exec
chadell 64cec66
Rename dockerfile to Dockerfile
glennmatthews fbf17a9
Merge branch 'develop' into example05-update
glennmatthews f3948ad
Update docs source
glennmatthews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -289,3 +289,6 @@ fabric.properties | ||
| ## Sphinx Documentation ## | ||
| docs/build | ||
| ## Secrets | ||
| creds.env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| diffsync.store.local | ||
| ==================== | ||
| .. automodule:: diffsync.store.local | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| diffsync.store.redis | ||
| ==================== | ||
| .. automodule:: diffsync.store.redis | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| API Reference | ||
| ============= | ||
| .. automodule:: diffsync.store | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| .. toctree:: | ||
| :maxdepth: 4 | ||
| diffsync.store.local | ||
| diffsync.store.redis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ARG PYTHON_VER=3.8.10 | ||
| FROM python:${PYTHON_VER}-slim | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends git \ | ||
| && apt-get purge -y --auto-remove \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| WORKDIR /local | ||
| COPY . /local | ||
| RUN pip install --upgrade pip \ | ||
| && pip install -r requirements.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,45 +4,61 @@ | ||
| 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. | ||
| 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. | ||
| 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. | ||
| 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. | ||
| 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. | ||
| We have 3 files: | ||
| - `models.py`: defines the reference models that we will use: `RegionMode` and `SiteModel` | ||
| - `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) | ||
| - `adapter_nautobot.py`: deifnes the Nautobot adapter with the `load()` and the CRUD methods | ||
| - `adapter_nautobot.py`: defines the Nautobot adapter with the `load()` and the CRUD methods | ||
| > 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. | ||
| ## Install dependencies | ||
| ## Get PeeringDB API Key (optional) | ||
| To ensure a good performance from PeeringDB API, you should provide an API Key: https://docs.peeringdb.com/howto/api_keys/ | ||
| Then, copy the example `creds.example.env` into `creds.env`, and place your new API Key. | ||
| ```bash | ||
| python3 -m venv .venv | ||
| source .venv/bin/activate | ||
| pip3 install -r requirements.txt | ||
| $ cp examples/05-nautobot-peeringdb/creds.example.env examples/05-nautobot-peeringdb/creds.env | ||
| ``` | ||
| ## Run it interactively | ||
| > Without API Key it might also work, but it could fail due to API rate limiting. | ||
| ```python | ||
| from IPython import embed | ||
| embed(colors="neutral") | ||
| ## Set up local docker environment | ||
| # Import Adapters | ||
| from diffsync.enum import DiffSyncFlags | ||
| ```bash | ||
| $ docker-compose -f examples/05-nautobot-peeringdb/docker-compose.yml up -d --build | ||
| $ docker exec -it 05-nautobot-peeringdb_example_1 python | ||
| ``` | ||
| ## Interactive execution | ||
| ```python | ||
| from adapter_nautobot import NautobotRemote | ||
| from adapter_peeringdb import PeeringDB | ||
| from diffsync.enum import DiffSyncFlags | ||
| from diffsync.store.redis import RedisStore | ||
| store_one = RedisStore(host="redis") | ||
| store_two = RedisStore(host="redis") | ||
| # Initialize PeeringDB adapter, using CATNIX id for demonstration | ||
chadell marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| peeringdb = PeeringDB(ix_id=62) | ||
| peeringdb = PeeringDB( | ||
| ix_id=62, | ||
| internal_storage_engine=store_one | ||
| ) | ||
| # Initialize Nautobot adapter, pointing to the demo instance (it's also the default settings) | ||
| nautobot = NautobotRemote( | ||
| url="https://demo.nautobot.com", | ||
| token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
| token="a" * 40, | ||
| internal_storage_engine=store_two | ||
| ) | ||
| # Load PeeringDB info into the adapter | ||
| @@ -55,12 +71,11 @@ peeringdb.dict() | ||
| nautobot.load() | ||
| # Let's diffsync do it's magic | ||
| diff = nautobot.diff_from(peeringdb) | ||
| diff = nautobot.diff_from(peeringdb, flags=DiffSyncFlags.SKIP_UNMATCHED_DST) | ||
| # Quick summary of the expected changes (remember that delete ones are dry-run) | ||
| diff.summary() | ||
| # Execute the synchronization | ||
| nautobot.sync_from(peeringdb, flags=DiffSyncFlags.SKIP_UNMATCHED_DST) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking - should that last sentence be amended to indicate that that the datacenter would be a
Siteassociated with the BarcelonaRegion?