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

Create exports with multiple sites #88

Merged
merged 11 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 48 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ test-local: test-dc1 test-dc2 test-colo test-site1 test-h88
test-local-lrg: test-lrg-nb-2-cyjs-latest
test-current: test-dc1-nb-2-cyjs-current test-dc2-nb-2-cyjs-current test-colo-nb-2-cyjs-current test-site1-nb-2-cyjs-current test-h88-nb-2-cyjs-current
test-latest: test-dc1-nb-2-cyjs-latest test-dc2-nb-2-cyjs-latest test-colo-nb-2-cyjs-latest test-site1-nb-2-cyjs-latest test-h88-nb-2-cyjs-latest
test: test-dc1-cyjs-2-clab test-dc1-cyjs-2-clab-custom-platform-map test-dc2-cyjs-2-cml test-site1-cyjs-2-clab test-site1-cyjs-2-clab-rename test-dc1-cyjs-2-graphite test-dc2-cyjs-2-graphite test-h88-cyjs-2-clab test-dc1-cyjs-2-d2 test-lrg-cyjs-2-graphite
test: test-args test-dc1-cyjs-2-clab test-dc1-cyjs-2-clab-custom-platform-map test-dc2-cyjs-2-cml test-site1-cyjs-2-clab test-site1-cyjs-2-clab-rename test-dc1-cyjs-2-graphite test-dc2-cyjs-2-graphite test-h88-cyjs-2-clab test-dc1-cyjs-2-d2 test-lrg-cyjs-2-graphite

test-args: test-args-site-and-sites
test-clab: test-dc1-cyjs-2-clab test-dc1-cyjs-2-clab-custom-platform-map test-site1-cyjs-2-clab test-h88-cyjs-2-clab
test-cml: test-dc2-cyjs-2-cml
test-graphite: test-dc1-cyjs-2-graphite test-dc2-cyjs-2-graphite test-lrg-cyjs-2-graphite
Expand All @@ -19,6 +20,13 @@ test-site1: test-site1-nb-2-cyjs-current test-site1-nb-2-cyjs-latest test-site1-
test-h88: test-h88-nb-2-cyjs-current test-h88-nb-2-cyjs-latest test-h88-nb-2-cyjs-latest-noconfigs test-h88-cyjs-2-clab
test-lrg: test-lrg-nb-2-cyjs-latest test-lrg-cyjs-2-graphite

test-args-site-and-sites:
@echo "#################################################################"
@echo "# Simulteneous use of site and sites should fail"
@echo "#################################################################"
! ./nrx.py --site dc1 --sites dc1,dc2 -d
@echo

test-dc1-nb-2-cyjs-current:
@echo "#################################################################"
@echo "# DC1: read from NetBox current version and export as CYJS"
Expand All @@ -39,6 +47,36 @@ test-dc1-nb-2-cyjs-latest:
diff dc1.cyjs ../data/dc1.cyjs
@echo

test-dc1-nb-2-cyjs-single-site:
@echo "#################################################################"
@echo "# Single site DC1: read from NetBox current version and export as CYJS"
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx-no-site.conf -o cyjs --site dc1 -d && \
diff dc1.cyjs ../data/dc1.cyjs
@echo

test-dc1-nb-2-cyjs-single-sites:
@echo "#################################################################"
@echo "# Single site DC1: read from NetBox current version and export as CYJS"
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx-no-site.conf -o cyjs --sites dc1 -d && \
diff dc1.cyjs ../data/dc1.cyjs
@echo

test-dc1-dc2-nb-2-cyjs-sites:
@echo "#################################################################"
@echo "# Two site DC1 and DC2: read from NetBox current version and export as CYJS"
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx-no-site.conf -o cyjs --sites dc1,dc2 -d && \
diff dc1-dc2.cyjs ../data/dc1-dc2.cyjs
@echo

test-dc1-cyjs-2-clab:
@echo "#################################################################"
@echo "# DC1: read from CYJS and export as Containerlab"
Expand Down Expand Up @@ -66,6 +104,15 @@ test-dc1-cyjs-2-graphite:
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

test-dc1-dc2-cyjs-2-graphite:
@echo "#################################################################"
@echo "# DC1 and DC2: read from CYJS and export as graphite"
@echo "#################################################################"
mkdir -p tests/dc1/graphite && cd tests/dc1/graphite && rm -rf * && \
../../../nrx.py -c ../nrx-no-site.conf -i cyjs -f ../data/dc1-dc2.cyjs -o graphite -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

test-dc1-cyjs-2-d2:
@echo "#################################################################"
@echo "# DC1: read from CYJS and export as d2"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ optional arguments:
-i, --input INPUT input source: netbox (default) | cyjs
-o, --output OUTPUT output format: cyjs | clab | cml | graphite | d2 or any other format supported by provided templates
-a, --api API netbox API URL
-s, --site SITE netbox site to export
-s, --site SITE netbox site to export, cannot be combined with --sites
--sites SITES netbox sites to export, for multiple tags use a comma-separated list: site1,site2,site3 (uses OR logic)
-t, --tags TAGS netbox tags to export, for multiple tags use a comma-separated list: tag1,tag2,tag3 (uses AND logic)
-n, --name NAME name of the exported topology (site name or tags by default)
--noconfigs disable device configuration export (enabled by default)
Expand Down
4 changes: 2 additions & 2 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ PLATFORM_MAP = '$HOME/.nr/platform_map.yaml'

# List of NetBox Device Roles to export
EXPORT_DEVICE_ROLES = ['router', 'core-switch', 'distribution-switch', 'access-switch', 'tor-switch', 'server']
# NetBox Site to export. Alternatively, use --site argument
EXPORT_SITE = 'DM-Akron'
# NetBox Site to export. Alternatively, use --sites argument
EXPORT_SITES = ['DM-Akron']
# NetBox tags to export. Alternatively, use --tags argument
EXPORT_TAGS = []
# Export device configurations, when available
Expand Down
14 changes: 7 additions & 7 deletions jupyter/ntopex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"metadata": {},
"outputs": [],
"source": [
"export_site = \"nr-1\"\n",
"export_sites = [\"nr-1\"]\n",
"nb_api_url = 'https://demo.netbox.dev'\n",
"nb_api_token = 'd2fa978199167d24f75aa477fc24a1a59eba9db7'\n",
"export_device_roles = [\"router\", \"core-switch\", \"access-switch\", \"distribution-switch\", \"tor-switch\"]"
Expand Down Expand Up @@ -107,7 +107,7 @@
}
],
"source": [
"s = nb.dcim.sites.get(name=export_site)\n",
"s = nb.dcim.sites.get(name=export_sites)\n",
"nodes, devices, interfaces = [], [], []\n",
"device_ids, interface_ids, cable_ids = [], [], []\n",
"for device in list(nb.dcim.devices.filter(site_id=s.id,role=export_device_roles)):\n",
Expand Down Expand Up @@ -167,7 +167,7 @@
],
"source": [
"import networkx as nx\n",
"G = nx.Graph(name=export_site)\n",
"G = nx.Graph(name=export_sites)\n",
"\n",
"for cable in list(nb.dcim.cables.filter(id=cable_ids)):\n",
" if len(cable.a_terminations) == 1 and len(cable.b_terminations) == 1:\n",
Expand Down Expand Up @@ -235,7 +235,7 @@
"id": "2a78d1be",
"metadata": {},
"source": [
"Serialize the graph into GML format and save it as `<export_site>.gml`"
"Serialize the graph into GML format and save it as `<export_sites>.gml`"
]
},
{
Expand Down Expand Up @@ -400,7 +400,7 @@
],
"source": [
"print(\"\\n\".join(nx.generate_gml(G)))\n",
"nx.write_gml(G, export_site+\".gml\")\n"
"nx.write_gml(G, export_sites+\".gml\")\n"
]
},
{
Expand All @@ -409,7 +409,7 @@
"id": "9cd785d6",
"metadata": {},
"source": [
"Also export in Cytoscape JSON format `<export_site>.cyjs`"
"Also export in Cytoscape JSON format `<export_sites>.cyjs`"
]
},
{
Expand Down Expand Up @@ -634,7 +634,7 @@
"import json\n",
"cyjs = nx.cytoscape_data(G)\n",
"print(json.dumps(cyjs, indent=4))\n",
"with open(export_site + \".cyjs\", 'w', encoding='utf-8') as f:\n",
"with open(export_sites + \".cyjs\", 'w', encoding='utf-8') as f:\n",
" json.dump(cyjs, f, indent=4)"
]
}
Expand Down
4 changes: 2 additions & 2 deletions nrx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
;OUTPUT_DIR = '$HOME/nrx'
# List of NetBox Device Roles to export
;EXPORT_DEVICE_ROLES = ['router', 'core-switch', 'distribution-switch', 'access-switch', 'tor-switch']
# NetBox Site to export. Alternatively, use --site argument
;EXPORT_SITE = 'DC1'
# NetBox Site to export. Alternatively, use --site or --sites arguments
;EXPORT_SITES = ['DC1']
# NetBox tags to export. Alternatively, use --tags argument
;EXPORT_TAGS = []
# Export device configurations, when available
Expand Down
Loading