#14, added circuit terminations

This commit is contained in:
Mattijs Vanhaverbeke
2020-05-19 17:18:20 +02:00
parent 6d28ce2da4
commit 370eff6b67
5 changed files with 62 additions and 9 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ PLUGINS_CONFIG = {
| allow_coordinates_saving | False | (bool) Set to true if you use the custom coordinates fields and want to save the coordinates | | allow_coordinates_saving | False | (bool) Set to true if you use the custom coordinates fields and want to save the coordinates |
| ignore_cable_type | 'power outlet,power port' | The cable types that you want to ignore in the views | | ignore_cable_type | 'power outlet,power port' | The cable types that you want to ignore in the views |
| preselected_tags | '' | The name of tags you want to preload | | preselected_tags | '' | The name of tags you want to preload |
| enable_circuit_terminations | False | (bool) Set to true if you want to see circuit terminations in the topology |
### Custom Images ### Custom Images
+3 -2
View File
@@ -4,7 +4,7 @@ class TopologyViewsConfig(PluginConfig):
name = 'netbox_topology_views' name = 'netbox_topology_views'
verbose_name = 'Topology views' verbose_name = 'Topology views'
description = 'An plugin to render toplogoy maps' description = 'An plugin to render toplogoy maps'
version = '0.4.6' version = '0.4.7'
author = 'Mattijs Vanhaverbeke' author = 'Mattijs Vanhaverbeke'
author_email = 'author@example.com' author_email = 'author@example.com'
base_url = 'topology-views' base_url = 'topology-views'
@@ -14,7 +14,8 @@ class TopologyViewsConfig(PluginConfig):
'ignore_cable_type': 'power outlet,power port', 'ignore_cable_type': 'power outlet,power port',
'device_img': 'access-switch,core-switch,firewall,router,distribution-switch,backup,storage,wan-network,wireless-ap,server,internal-switch,isp-cpe-material,non-racked-devices,power-units', 'device_img': 'access-switch,core-switch,firewall,router,distribution-switch,backup,storage,wan-network,wireless-ap,server,internal-switch,isp-cpe-material,non-racked-devices,power-units',
'allow_coordinates_saving': False, 'allow_coordinates_saving': False,
'preselected_tags' : '' 'preselected_tags' : '',
'enable_circuit_terminations': False
} }
config = TopologyViewsConfig config = TopologyViewsConfig
+56 -4
View File
@@ -9,6 +9,7 @@ from django.conf import settings
from utilities.api import IsAuthenticatedOrLoginNotRequired from utilities.api import IsAuthenticatedOrLoginNotRequired
from dcim.models import DeviceRole, Device, Cable from dcim.models import DeviceRole, Device, Cable
from circuits.models import Circuit
from extras.models import Tag, CustomField, CustomFieldValue from extras.models import Tag, CustomField, CustomFieldValue
ignore_cable_type_raw = settings.PLUGINS_CONFIG["netbox_topology_views"]["ignore_cable_type"] ignore_cable_type_raw = settings.PLUGINS_CONFIG["netbox_topology_views"]["ignore_cable_type"]
@@ -120,6 +121,7 @@ class SearchViewSet(GenericViewSet):
edges = [] edges = []
edge_ids = 0 edge_ids = 0
cable_ids = [] cable_ids = []
circuit_ids = []
for device in devices: for device in devices:
cables = device.get_cables() cables = device.get_cables()
for cable in cables: for cable in cables:
@@ -146,14 +148,61 @@ class SearchViewSet(GenericViewSet):
edge["id"] = edge_ids edge["id"] = edge_ids
edge["from"] = cable.termination_a.device.id edge["from"] = cable.termination_a.device.id
edge["to"] = cable.termination_b.device.id edge["to"] = cable.termination_b.device.id
edge["title"] = "Connection between <br> " + cable_a_dev_name + " [" + cable_a_name + "]<br>" + cable_b_dev_name + " [" + cable_b_name + "]" edge["title"] = "Cable between <br> " + cable_a_dev_name + " [" + cable_a_name + "]<br>" + cable_b_dev_name + " [" + cable_b_name + "]"
if cable.color != "": if cable.color != "":
edge["color"] = "#" + cable.color edge["color"] = "#" + cable.color
edges.append(edge) edges.append(edge)
else: else:
pass if cable.termination_a_type.name == "circuit termination":
#circuittermination not supported for now if settings.PLUGINS_CONFIG["netbox_topology_views"]["enable_circuit_terminations"]:
if cable.termination_a.circuit.id not in circuit_ids:
circuit_ids.append(cable.termination_a.circuit.id)
edge_ids += 1
cable_b_dev_name = cable.termination_b.device.name
if cable_b_dev_name is None:
cable_b_dev_name = "device B name unknown"
cable_b_name = cable.termination_b.name
if cable_b_name is None:
cable_b_name = "cable B name unknown"
edge = {}
edge["id"] = edge_ids
edge["to"] = cable.termination_b.device.id
edge["dashes"] = True
title = ""
title += "Circuit provider: " + cable.termination_a.circuit.provider.name + "<br>"
title += "Termination between <br>"
title += cable_b_dev_name + " [" + cable_b_name + "]<br>"
if cable.termination_a.circuit.termination_a is not None:
if cable.termination_a.circuit.termination_a.cable is not None:
if cable.termination_a.circuit.termination_a.cable.id != cable.id:
edge["from"] = cable.termination_a.circuit.termination_a.cable.termination_b.device.id
cable_a_dev_name = cable.termination_a.circuit.termination_a.cable.termination_b.device.name
if cable_a_dev_name is None:
cable_a_dev_name = "device B name unknown"
cable_b_name = cable.termination_a.circuit.termination_a.cable.termination_b.name
if cable_a_name is None:
cable_a_name = "cable B name unknown"
title += cable_a_dev_name + " [" + cable_a_name + "]<br>"
if cable.termination_a.circuit.termination_z is not None:
if cable.termination_a.circuit.termination_z.cable is not None:
if cable.termination_a.circuit.termination_z.cable.id != cable.id:
edge["from"] = cable.termination_a.circuit.termination_z.cable.termination_b.device.id
cable_a_dev_name = cable.termination_a.circuit.termination_z.cable.termination_b.device.name
if cable_a_dev_name is None:
cable_a_dev_name = "device B name unknown"
cable_a_name = cable.termination_a.circuit.termination_z.cable.termination_b.name
if cable_a_name is None:
cable_a_name = "cable B name unknown"
title += cable_a_dev_name + " [" + cable_a_name + "]<br>"
edge["title"] = title
edges.append(edge)
dev_name = device.name dev_name = device.name
if dev_name is None: if dev_name is None:
dev_name = "device name unknown" dev_name = "device name unknown"
@@ -182,6 +231,9 @@ class SearchViewSet(GenericViewSet):
else: else:
node["image"] = "../../static/netbox_topology_views/img/role-unknown.png" node["image"] = "../../static/netbox_topology_views/img/role-unknown.png"
if device.device_role.color != "":
node["color.border"] = "#" + device.device_role.color
for device_custom_field in device.custom_field_values.all(): for device_custom_field in device.custom_field_values.all():
if device_custom_field.field.name == "coordinates": if device_custom_field.field.name == "coordinates":
cords = device_custom_field.serialized_value.split(";") cords = device_custom_field.serialized_value.split(";")
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"private": true, "private": true,
"name": "netbox_topology_views", "name": "netbox_topology_views",
"version": "0.4.6", "version": "0.4.7",
"scripts": { "scripts": {
"resources": "gulp build", "resources": "gulp build",
"resources_dev": "gulp build_dev" "resources_dev": "gulp build_dev"
+1 -1
View File
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup( setup(
name='netbox-topology-views', name='netbox-topology-views',
version='0.4.6', version='0.4.7',
description='An NetBox plugin to create Topology maps', description='An NetBox plugin to create Topology maps',
url='https://github.com/mattieserver/netbox-topology-views', url='https://github.com/mattieserver/netbox-topology-views',
author='Mattijs Vanhaverbeke', author='Mattijs Vanhaverbeke',