diff --git a/netbox_topology_views/__init__.py b/netbox_topology_views/__init__.py index 8a2f7e3..528f2e2 100644 --- a/netbox_topology_views/__init__.py +++ b/netbox_topology_views/__init__.py @@ -4,7 +4,7 @@ class TopologyViewsConfig(PluginConfig): name = 'netbox_topology_views' verbose_name = 'Topology views' description = 'An plugin to render topology maps' - version = '1.0.0-alpha.2' + version = '1.0.0-alpha.3' author = 'Mattijs Vanhaverbeke' author_email = 'author@example.com' base_url = 'netbox_topology_views' @@ -15,7 +15,7 @@ class TopologyViewsConfig(PluginConfig): '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, 'preselected_tags' : [], - 'enable_circuit_terminations': False, + 'enable_circuit_terminations': True, 'draw_default_layout': False } diff --git a/netbox_topology_views/api/serializers.py b/netbox_topology_views/api/serializers.py index f713887..b4a209b 100644 --- a/netbox_topology_views/api/serializers.py +++ b/netbox_topology_views/api/serializers.py @@ -3,18 +3,6 @@ from rest_framework.serializers import ModelSerializer from dcim.models import DeviceRole, Device from extras.models import Tag -class PreDeviceRoleSerializer(ModelSerializer): - - class Meta: - model = DeviceRole - fields = ('id', 'name') - -class PreTagSerializer(ModelSerializer): - - class Meta: - model = Tag - fields = ('id', 'name') - class TopologyDummySerializer(ModelSerializer): diff --git a/netbox_topology_views/api/urls.py b/netbox_topology_views/api/urls.py index 506e2ff..1fe59ac 100644 --- a/netbox_topology_views/api/urls.py +++ b/netbox_topology_views/api/urls.py @@ -3,9 +3,6 @@ from . import views router = routers.DefaultRouter() -router.register('preselectdeviceroles', views.PreSelectDeviceRolesViewSet) -router.register('preselecttags', views.PreSelectTagsViewSet) -router.register('search', views.SearchViewSet, basename='search') router.register('save-coords', views.SaveCoordsViewSet, basename='save_coords') urlpatterns = router.urls \ No newline at end of file diff --git a/netbox_topology_views/api/views.py b/netbox_topology_views/api/views.py index 94469c9..e3be3ed 100644 --- a/netbox_topology_views/api/views.py +++ b/netbox_topology_views/api/views.py @@ -4,7 +4,7 @@ from rest_framework.response import Response from django.contrib.contenttypes.models import ContentType from rest_framework.routers import APIRootView -from .serializers import PreDeviceRoleSerializer, TopologyDummySerializer, PreTagSerializer +from .serializers import TopologyDummySerializer from django.conf import settings from dcim.models import DeviceRole, Device, Cable @@ -25,13 +25,6 @@ class TopologyViewsRootView(APIRootView): def get_view_name(self): return 'TopologyViews' -class PreSelectDeviceRolesViewSet(ReadOnlyModelViewSet): - queryset = DeviceRole.objects.filter(name__in=preselected_device_roles) - serializer_class = PreDeviceRoleSerializer - -class PreSelectTagsViewSet(ReadOnlyModelViewSet): - queryset = Tag.objects.filter(name__in=preselected_tags) - serializer_class = PreTagSerializer class SaveCoordsViewSet(ReadOnlyModelViewSet): queryset = Device.objects.all() @@ -74,200 +67,3 @@ class SaveCoordsViewSet(ReadOnlyModelViewSet): results["status"] = "not allowed to save coords" return Response(results, status=500) -class SearchViewSet(ReadOnlyModelViewSet): - queryset = Device.objects.all() - serializer_class = TopologyDummySerializer - - def _filter(self, site, role, name, tags, region, location): - filter_devices = Device.objects.all() - if name is not None: - filter_devices = filter_devices.filter(name__contains=name) - if site is not None: - filter_devices = filter_devices.filter(site__id__in=site) - if role is not None: - filter_devices = filter_devices.filter(device_role__id__in=role) - if tags is not None: - filter_devices = filter_devices.filter(tags__id__in=tags) - if region is not None: - filter_devices = filter_devices.filter(site__region__id__in=region) - if location is not None: - filter_devices = filter_devices.filter(location__id__in=location) - return filter_devices - - - @action(detail=False, methods=['get']) - def search(self, request): - name = request.query_params.get('name', None) - if name == "": - name = None - - sites = request.query_params.getlist('sites[]', None) - if sites == []: - sites = None - - devicerole = request.query_params.getlist('devicerole[]', None) - if devicerole == []: - devicerole = None - - tags = request.query_params.getlist('tags[]', None) - if tags == []: - tags = None - - regions = request.query_params.getlist('regions[]', None) - if regions == []: - regions = None - - locations = request.query_params.getlist('locations[]', None) - if locations == []: - locations = None - - hide_unconnected = request.query_params.get('hide_unconnected', None) - if hide_unconnected == "": - hide_unconnected = None - - devices = self._filter(sites, devicerole, name, tags, regions, locations) - - nodes = [] - edges = [] - edge_ids = 0 - cable_ids = [] - circuit_ids = [] - for device in devices: - cables = device.get_cables() - if cables.exists(): - device_has_connections = True - for cable in cables: - if cable.termination_a_type.name != "circuit termination" and cable.termination_b_type.name != "circuit termination": - if cable.id not in cable_ids: - if cable.termination_a_type.name not in ignore_cable_type and cable.termination_b_type.name not in ignore_cable_type: - cable_ids.append(cable.id) - edge_ids += 1 - - cable_a_dev_name = cable.termination_a.device.name - if cable_a_dev_name is None: - cable_a_dev_name = "device A name unknown" - cable_a_name = cable.termination_a.name - if cable_a_name is None: - cable_a_name = "cable A name unknown" - 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["from"] = cable.termination_a.device.id - edge["to"] = cable.termination_b.device.id - edge["title"] = "Cable between
" + cable_a_dev_name + " [" + cable_a_name + "]
" + cable_b_dev_name + " [" + cable_b_name + "]" - if cable.color != "": - edge["color"] = "#" + cable.color - edges.append(edge) - else: - if cable.termination_a_type.name == "circuit termination": - 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 + "
" - title += "Termination between
" - title += cable_b_dev_name + " [" + cable_b_name + "]
" - # To Many if's - 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: - if cable.termination_a.circuit.termination_a.cable.termination_b is not None: - if cable.termination_a.circuit.termination_a.cable.termination_b.device is not None: - 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 + "]
" - edge["title"] = title - edges.append(edge) - # To Many if's - 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: - if cable.termination_a.circuit.termination_z.cable.termination_b is not None: - if cable.termination_a.circuit.termination_z.cable.termination_b.device is not None: - 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 + "]
" - edge["title"] = title - edges.append(edge) - else: - device_has_connections = False - - if hide_unconnected == 'false' or (hide_unconnected == 'true' and device_has_connections is True): - dev_name = device.name - if dev_name is None: - dev_name = "device name unknown" - - node_content = "" - - if device.device_type.display_name is not None: - node_content += "Type: " + device.device_type.display_name + "" - if device.device_role.name is not None: - node_content += "Role: " + device.device_role.name + "" - if device.serial != "": - node_content += "Serial: " + device.serial + "" - if device.primary_ip is not None: - node_content += "IP Address: " + str(device.primary_ip.address) + "" - - dev_title = " %s
" % (node_content) - - node = {} - node["id"] = device.id - node["name"] = dev_name - node["label"] = dev_name - node["title"] = dev_title - node["shape"] = 'image' - if device.device_role.slug in settings.PLUGINS_CONFIG["netbox_topology_views"]["device_img"]: - node["image"] = '../../static/netbox_topology_views/img/' + device.device_role.slug + ".png" - else: - node["image"] = "../../static/netbox_topology_views/img/role-unknown.png" - - if device.device_role.color != "": - node["color.border"] = "#" + device.device_role.color - - if "coordinates" in device.custom_field_data: - if device.custom_field_data["coordinates"] != "": - cords = device.custom_field_data["coordinates"].split(";") - node["x"] = int(cords[0]) - node["y"] = int(cords[1]) - node["physics"] = False - - nodes.append(node) - - results = {} - results["nodes"] = nodes - results["edges"] = edges - - return Response(results) - \ No newline at end of file diff --git a/netbox_topology_views/static_dev/js/full.js b/netbox_topology_views/static_dev/js/full.js deleted file mode 100644 index c3cd364..0000000 --- a/netbox_topology_views/static_dev/js/full.js +++ /dev/null @@ -1,33 +0,0 @@ -var graph = null; -var container = null; - -function iniPlotboxFull() { - document.addEventListener('DOMContentLoaded', function () { - container = document.getElementById('fullvisgraph'); - startRender(); - }, false); -} - -function startRender() { - var url = location.search; - - $.ajax({ - type: "GET", - url: "../../api/plugins/topology-views/search/search/" + url, - contentType: "application/json; charset=utf-8", - success: function (data_result, status, xhr) { - graph = null; - nodes = new vis.DataSet(); - edges = new vis.DataSet(); - graph = new vis.Network(container, { nodes: nodes, edges: edges }, options); - $.each(data_result["nodes"], function (index, device) { - nodes.add(device); - }); - $.each(data_result["edges"], function (index, edge) { - edges.add(edge); - }); - graph.fit(); - canvas = document.getElementById('fullvisgraph').getElementsByTagName('canvas')[0]; - } -}); -} \ No newline at end of file diff --git a/netbox_topology_views/templates/netbox_topology_views/full.html b/netbox_topology_views/templates/netbox_topology_views/full.html deleted file mode 100644 index 3ebae46..0000000 --- a/netbox_topology_views/templates/netbox_topology_views/full.html +++ /dev/null @@ -1,24 +0,0 @@ -{% load static %} -{% load helpers %} - -{% block content %} -{% with config=settings.PLUGINS_CONFIG.netbox_topology_views %} - - - - -
-
-
- - -{% endwith %} -{% endblock %} - -{% block javascript %} - - - - - -{% endblock %} diff --git a/netbox_topology_views/templates/netbox_topology_views/index.html b/netbox_topology_views/templates/netbox_topology_views/index.html index 874ac36..a656fd1 100644 --- a/netbox_topology_views/templates/netbox_topology_views/index.html +++ b/netbox_topology_views/templates/netbox_topology_views/index.html @@ -20,10 +20,6 @@ Download - - - Share - {% endblock controls %} diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index a1b7cb5..452c105 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -25,6 +25,8 @@ def get_topology_data(queryset, hide_unconnected): if not queryset: return None + ignore_cable_type = settings.PLUGINS_CONFIG["netbox_topology_views"]["ignore_cable_type"] + device_ids = [d.id for d in queryset] for qs_device in queryset: @@ -33,35 +35,36 @@ def get_topology_data(queryset, hide_unconnected): links_device = Cable.objects.filter(Q(_termination_a_device_id=qs_device.id) | Q(_termination_b_device_id=qs_device.id) ) for link_from in links_device: if link_from.termination_a_type.name != "circuit termination" and link_from.termination_b_type.name != "circuit termination": - if link_from.id not in cable_ids: - if link_from.termination_a.device.id in device_ids and link_from.termination_b.device.id in device_ids: - device_has_connections = True - cable_ids.append(link_from.id) - edge_ids += 1 - cable_a_dev_name = link_from.termination_a.device.name - if cable_a_dev_name is None: - cable_a_dev_name = "device A name unknown" - cable_a_name = link_from.termination_a.name - if cable_a_name is None: - cable_a_name = "cable A name unknown" - cable_b_dev_name = link_from.termination_b.device.name - if cable_b_dev_name is None: - cable_b_dev_name = "device B name unknown" - cable_b_name = link_from.termination_b.name - if cable_b_name is None: - cable_b_name = "cable B name unknown" + if link_from.termination_a_type.name not in ignore_cable_type and link_from.termination_b_type.name not in ignore_cable_type: + if link_from.id not in cable_ids: + if link_from.termination_a.device.id in device_ids and link_from.termination_b.device.id in device_ids: + device_has_connections = True + cable_ids.append(link_from.id) + edge_ids += 1 + cable_a_dev_name = link_from.termination_a.device.name + if cable_a_dev_name is None: + cable_a_dev_name = "device A name unknown" + cable_a_name = link_from.termination_a.name + if cable_a_name is None: + cable_a_name = "cable A name unknown" + cable_b_dev_name = link_from.termination_b.device.name + if cable_b_dev_name is None: + cable_b_dev_name = "device B name unknown" + cable_b_name = link_from.termination_b.name + if cable_b_name is None: + cable_b_name = "cable B name unknown" - edge = {} - edge["id"] = edge_ids - edge["from"] = link_from.termination_a.device.id - edge["to"] = link_from.termination_b.device.id - edge["title"] = "Cable between
" + cable_a_dev_name + " [" + cable_a_name + "]
" + cable_b_dev_name + " [" + cable_b_name + "]" - if link_from.color != "": - edge["color"] = "#" + link_from.color - edges.append(edge) - else: - if link_from.termination_a.device.id in device_ids and link_from.termination_b.device.id in device_ids: - device_has_connections = True + edge = {} + edge["id"] = edge_ids + edge["from"] = link_from.termination_a.device.id + edge["to"] = link_from.termination_b.device.id + edge["title"] = "Cable between
" + cable_a_dev_name + " [" + cable_a_name + "]
" + cable_b_dev_name + " [" + cable_b_name + "]" + if link_from.color != "": + edge["color"] = "#" + link_from.color + edges.append(edge) + else: + if link_from.termination_a.device.id in device_ids and link_from.termination_b.device.id in device_ids: + device_has_connections = True else: if settings.PLUGINS_CONFIG["netbox_topology_views"]["enable_circuit_terminations"]: if link_from.termination_a.circuit.id not in circuit_ids: diff --git a/package-lock.json b/package-lock.json index 0661a67..0a16018 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "netbox_topology_views", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index f0c45a6..f333d34 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "netbox_topology_views", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "scripts": { "resources": "gulp build", "resources_dev": "gulp build_dev" diff --git a/setup.py b/setup.py index 566e23e..8e24e97 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup( name='netbox-topology-views', - version='1.0.0-alpha.2', + version='1.0.0-alpha.3', description='An NetBox plugin to create Topology maps', url='https://github.com/mattieserver/netbox-topology-views', author='Mattijs Vanhaverbeke',