From 4f75c95c203373b6fe5ae14aeba96baa2373ed85 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Thu, 22 Dec 2022 13:05:11 +0100 Subject: [PATCH] add scripts/netbox-dump --- .editorconfig | 3 + netbox_dump.json | 1308 +++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + scripts/netbox-dump | 117 ++++ 4 files changed, 1429 insertions(+) create mode 100644 netbox_dump.json create mode 100755 scripts/netbox-dump diff --git a/.editorconfig b/.editorconfig index e09c9dd..b632cc1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,3 +22,6 @@ indent_size = unset [*.vault] end_of_line = unset insert_final_newline = unset + +[*.json] +insert_final_newline = unset diff --git a/netbox_dump.json b/netbox_dump.json new file mode 100644 index 0000000..30eb1e7 --- /dev/null +++ b/netbox_dump.json @@ -0,0 +1,1308 @@ +{ + "home": { + "devices": { + "home.nas": { + "bond0": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "lag", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "br0": { + "description": "", + "enabled": true, + "ip_addresses": [ + "172.19.138.20/24" + ], + "lag": null, + "mode": "tagged-all", + "type": "bridge", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "br42": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "bridge", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "eno1": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp8s0f0": { + "description": "home.sw01 (41)", + "enabled": true, + "ip_addresses": [], + "lag": "bond0", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp8s0f1": { + "description": "home.sw01 (43)", + "enabled": true, + "ip_addresses": [], + "lag": "bond0", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp9s0f0": { + "description": "home.sw01 (45)", + "enabled": true, + "ip_addresses": [], + "lag": "bond0", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp9s0f1": { + "description": "home.sw01 (47)", + "enabled": true, + "ip_addresses": [], + "lag": "bond0", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + } + }, + "home.router": { + "enp1s0": { + "description": "home.sw01 (2)", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp1s0.100": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "virtual", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp1s0.23": { + "description": "", + "enabled": true, + "ip_addresses": [ + "172.19.139.1/24" + ], + "lag": null, + "mode": null, + "type": "virtual", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "enp1s0.42": { + "description": "", + "enabled": true, + "ip_addresses": [ + "172.19.138.1/24" + ], + "lag": null, + "mode": null, + "type": "virtual", + "vlans": { + "tagged": [], + "untagged": null + } + } + }, + "home.sw01": { + "1": { + "description": "Isanet", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.dmz" + } + }, + "10": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "11": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "12": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "13": { + "description": "home.ejgwdesk", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "14": { + "description": "Schreibtisch Franzi", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "15": { + "description": "Schreibtisch Sophie", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "16": { + "description": "home.snom-wohnzimmer", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "17": { + "description": "home.drucker-sophie", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "18": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "19": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "2": { + "description": "home.router (enp1s0)", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "1000base-t", + "vlans": { + "tagged": [ + "home.clients", + "home.dmz", + "home.wan" + ], + "untagged": null + } + }, + "20": { + "description": "RIPE-Probe #28280", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.dmz" + } + }, + "21": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "22": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "23": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "24": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "25": { + "description": "home.kodi-wohnzimmer", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "26": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "27": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "28": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "29": { + "description": "Sofa-Kabel", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "3": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "30": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "31": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "32": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "33": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": "LAG3", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "34": { + "description": "Patchpanel unten (17)", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "35": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": "LAG3", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "36": { + "description": "Patchpanel unten (18)", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "37": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": "LAG1", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "38": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "39": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": "LAG1", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "4": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "40": { + "description": "info-beamer 12199 (LAN)", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "41": { + "description": "home.nas (enp8s0f0)", + "enabled": true, + "ip_addresses": [], + "lag": "LAG2", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "42": { + "description": "Patchpanel unten (21)", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.wan" + } + }, + "43": { + "description": "home.nas (enp8s0f1)", + "enabled": true, + "ip_addresses": [], + "lag": "LAG2", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "44": { + "description": "home.bubble01", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "45": { + "description": "home.nas (enp9s0f0)", + "enabled": true, + "ip_addresses": [], + "lag": "LAG2", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "46": { + "description": "home.winkeeinhorn-1", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "1000base-t", + "vlans": { + "tagged": [ + "ffwi.mesh" + ], + "untagged": "home.clients" + } + }, + "47": { + "description": "home.nas (enp9s0f1)", + "enabled": true, + "ip_addresses": [], + "lag": "LAG2", + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "48": { + "description": "home.winkeeinhorn-2", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "1000base-t", + "vlans": { + "tagged": [ + "ffwi.mesh" + ], + "untagged": "home.clients" + } + }, + "49": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "5": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "50": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "51": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "52": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "6": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "7": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "8": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "9": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "ffwi.client" + } + }, + "LAG1": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "lag", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "LAG2": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "lag", + "vlans": { + "tagged": [ + "ffwi.client", + "ffwi.mesh", + "home.clients", + "home.dmz", + "home.wan" + ], + "untagged": null + } + }, + "LAG3": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "lag", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "VLAN42": { + "description": "", + "enabled": true, + "ip_addresses": [ + "172.19.138.2/24" + ], + "lag": null, + "mode": "access", + "type": "virtual", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + } + }, + "home.sw02": { + "ge-0/0/0": { + "description": "snom", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/1": { + "description": "bubble", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/10": { + "description": "sophie", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/11": { + "description": "sophie", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/12": { + "description": "franzi", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/13": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/14": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/15": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/16": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/17": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/18": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/19": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/2": { + "description": "freifunk", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "1000base-t", + "vlans": { + "tagged": [ + "ffwi.mesh" + ], + "untagged": "home.clients" + } + }, + "ge-0/0/20": { + "description": "kodi", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/21": { + "description": "infobeamer", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/22": { + "description": "fritzbox", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.wan" + } + }, + "ge-0/0/23": { + "description": "router", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "1000base-t", + "vlans": { + "tagged": [ + "home.clients", + "home.dmz", + "home.wan" + ], + "untagged": null + } + }, + "ge-0/0/3": { + "description": "freifunk", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "1000base-t", + "vlans": { + "tagged": [ + "ffwi.mesh" + ], + "untagged": "home.clients" + } + }, + "ge-0/0/4": { + "description": "wohnzimmer", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/5": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/6": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/7": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/0/8": { + "description": "drucker", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "ge-0/0/9": { + "description": "ripe-probe", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": "home.dmz" + } + }, + "ge-0/1/0": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/1/1": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/1/2": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "ge-0/1/3": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-x-sfp", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "xe-0/1/0": { + "description": "nas", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "tagged", + "type": "10gbase-x-sfpp", + "vlans": { + "tagged": [ + "ffwi.client", + "ffwi.mesh", + "home.clients", + "home.dmz" + ], + "untagged": null + } + }, + "xe-0/1/1": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "10gbase-x-sfpp", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + }, + "xe-0/1/2": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": "access", + "type": "10gbase-x-sfpp", + "vlans": { + "tagged": [], + "untagged": "home.clients" + } + } + }, + "home.usv01": { + "LAN": { + "description": "", + "enabled": true, + "ip_addresses": [ + "172.19.138.3/24" + ], + "lag": null, + "mode": null, + "type": "100base-tx", + "vlans": { + "tagged": [], + "untagged": null + } + } + } + }, + "vlans": { + "ffwi.client": 8, + "ffwi.mesh": 7, + "home.clients": 42, + "home.dmz": 23, + "home.wan": 100 + } + }, + "meerfarbig gmbh & co. kg": { + "devices": { + "rx300": { + "IPMI": { + "description": "", + "enabled": true, + "ip_addresses": [ + "10.250.179.2/32" + ], + "lag": null, + "mode": null, + "type": "100base-tx", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "LAN1": { + "description": "", + "enabled": true, + "ip_addresses": [ + "2a00:f820:528::2/64", + "31.47.232.106/29" + ], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + }, + "LAN2": { + "description": "", + "enabled": true, + "ip_addresses": [], + "lag": null, + "mode": null, + "type": "1000base-t", + "vlans": { + "tagged": [], + "untagged": null + } + } + } + }, + "vlans": {} + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index eaec252..8c04545 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ bundlewrap~=4.16.0 PyNaCl bundlewrap-pass +pynetbox==7.0.0 diff --git a/scripts/netbox-dump b/scripts/netbox-dump new file mode 100755 index 0000000..779b143 --- /dev/null +++ b/scripts/netbox-dump @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 + +from json import dump +from os import environ +from os.path import join +from sys import exit + +from bundlewrap.utils.ui import QUIT_EVENT, io +from bundlewrap.utils.text import bold, yellow, validate_name +from pynetbox import api as netbox_api + + +BW_REPO_PATH = environ.get('BW_REPO_PATH', '.') +netbox = netbox_api( + environ.get('NETBOX_HOST', 'https://netbox.franzi.business'), + token=environ.get('NETBOX_TOKEN', None), +) + +result = { +# 'my_site_name': { +# 'vlans': { +# 'my_vlan_name': 10, +# 'other_vlan_name': 11, +# 'yet_another_vlan_name': 12, +# }, +# 'devices': { +# 'my_switch': { +# 'port1': { +# 'description': 'foo', +# 'type': '1000base-t', # or 'lag' +# 'mode': None, # or 'access', 'tagged', 'tagged-all' +# 'lag': 'none', # or 'LAG1' +# 'vlan': { +# 'untagged': 'my_vlan_name', +# 'tagged': [ +# 'other_vlan_name', +# 'yet_another_vlan_name', +# ], +# }, +# }, +# }, +# }, +# }, +} + +errors = False +try: + io.activate() + + for site in netbox.dcim.sites.all(): + site_name = site.name.lower() + + result[site_name] = { + 'vlans': {}, + 'devices': {}, + } + + with io.job(f'{bold(site_name)} getting vlans'): + for vlan in netbox.ipam.vlans.filter(site_id=site.id): + if vlan.name in result[site_name]['vlans'].keys() and result[site_name]['vlans'][vlan.name] != vlan.id: + raise Exception(f"vlan {result[site_name]['vlans'][vlan.name]} and {vlan.id} both have the name {vlan.name}") + + result[site_name]['vlans'][vlan.name] = vlan.vid + + for interface in netbox.dcim.interfaces.filter(site_id=site.id): + if QUIT_EVENT.is_set(): + exit(0) + + with io.job(f'{bold(site_name)} {bold(interface.device.name)} interface {yellow(interface.name)}'): + if not interface.device.name: + # Unnamed device. Probably not managed by bw. + continue + elif not validate_name(interface.device.name): + # bundlewrap does not consider this device name to be a valid + # node name. Ignore it, we don't manage it + continue + + has_valid_description = False + if interface.description: + description = interface.description + has_valid_description = True + elif interface.connected_endpoints: + description = f'{sorted(interface.connected_endpoints)[0].device.display} ({sorted(interface.connected_endpoints)[0].display})' + has_valid_description = True + elif interface.link_peers: + description = f'{sorted(interface.link_peers)[0].device.display} ({sorted(interface.link_peers)[0].display})' + else: + description = '' + + if not description.isascii(): + errors = True + io.stderr(f'{bold(interface.device.name)} {bold(interface.name)} description "{description}" contains non-ascii characters, this isn\'t supported') + + result[site_name]['devices'].setdefault(interface.device.name, {})[interface.name] = { + 'description': description, + 'enabled': interface.enabled, + 'ip_addresses': sorted(set() if interface.count_ipaddresses == 0 else { + ip.address for ip in + netbox.ipam.ip_addresses.filter(interface_id=interface.id) + }), + 'mode': interface.mode.value if interface.mode else None, + 'type': interface.type.value, + 'lag': interface.lag.name if interface.lag else None, + 'vlans': { + 'untagged': interface.untagged_vlan.name if interface.untagged_vlan else None, + 'tagged': sorted(vlan.name for vlan in interface.tagged_vlans), + }, + } + + if errors: + exit(1) + + with io.job('dumping result to netbox_dump.json'): + with open(join(BW_REPO_PATH, 'netbox_dump.json'), 'w') as f: + dump(result, f, indent=4, sort_keys=True) +finally: + io.deactivate()