Package: openwisp-network-topology
OpenWISP Network Topology is a network topology collector and visualizer
web application and API, it allows to collect network topology data from different
networking software (dynamic mesh routing protocols, OpenVPN), store it,
visualize it, edit its details, it also provides hooks (a.k.aDjango signals)
to execute code when the status of a link changes.When used in conjunction withOpenWISP ControllerandOpenWISP Monitoring,
itmakes the monitoring system faster in detecting change to the network.OpenWISP is not only an application designed for end users, but can also be
used as a framework on which custom network automation solutions can be built
on top of its building blocks.Other popular building blocks that are part of the OpenWISP ecosystem are:openwisp-controller:
network and WiFi controller: provisioning, configuration management,
x509 PKI management and more; works on OpenWRT, but designed to work also on other systems.openwisp-monitoring:
provides device status monitoring, collection of metrics, charts, alerts,
possibility to define custom checksopenwisp-firmware-upgrader:
automated firmware upgrades (single device or mass network upgrades)openwisp-radius:
based on FreeRADIUS, allows to implement network access authentication systems like
802.1x WPA2 Enterprise, captive portal authentication, Hotspot 2.0 (802.11u)openwisp-ipam:
it allows to manage the IP address space of networksFor a more complete overview of the OpenWISP modules and architecture,
see theOpenWISP Architecture Overview.Want to help OpenWISP?Find out how to help us grow here.Table of Contents:Available featuresInstallation instructionsDeploy it in productionInstall stable version from pypiInstall development versionInstalling for developmentSetup (integrate in an existing django project)Quickstart GuideCreating a topologySending data for topology with RECEIVE strategyManagement Commandsupdate_topologysave_snapshotupgrade_from_django_netjsongraphcreate_device_nodesLoggingStrategiesFETCH strategyRECEIVE strategyIntegration with OpenWISP Controller and OpenWISP MonitoringSettingsOPENWISP_NETWORK_TOPOLOGY_PARSERSOPENWISP_NETWORK_TOPOLOGY_SIGNALSOPENWISP_NETWORK_TOPOLOGY_TIMEOUTOPENWISP_NETWORK_TOPOLOGY_LINK_EXPIRATIONOPENWISP_NETWORK_TOPOLOGY_VISUALIZER_CSSOPENWISP_NETWORK_TOPOLOGY_NODE_EXPIRATIONOPENWISP_NETWORK_TOPOLOGY_API_URLCONFOPENWISP_NETWORK_TOPOLOGY_API_BASEURLOPENWISP_NETWORK_TOPOLOGY_API_AUTH_REQUIREDRest APILive documentationBrowsable web interfaceList of endpointsList topologiesCreate topologyDetail of a topologyChange topolgy detailPatch topology detailDelete topologyView topology historySend topology dataList linksCreate linkGet link detailChange link detailPatch link detailDelete linkList nodesCreate nodeGet node detailChange node detailPatch node detailDelete nodeOverriding visualizer templatesExample: overriding the<script>tagExtending openwisp-network-topology1. Initialize your custom module2. Installopenwisp-network-topology3. AddEXTENDED_APPS4. Addopenwisp_utils.staticfiles.DependencyFinder5. Addopenwisp_utils.loaders.DependencyLoader6. Inherit the AppConfig class7. Create your custom models8. Add swapper configurations9. Create database migrations10. Create the admin1. Monkey patching2. Inheriting admin classes11. Create root URL configuration12. Setup API urls13. Extending management commands14. Import the automated testsOther base classes that can be inherited and extended1. Extending API views2. Extending the Visualizer viewsContributingChangelogLicenseSupportAvailable featuresnetwork topology collectorsupporting different formats:NetJSON NetworkGraphOLSR (jsoninfo/txtinfo)batman-adv (jsondoc/txtinfo)BMX6 (q6m)CNML 1.0OpenVPNadditional formats can be added bywriting custom netdiff parsersnetwork topology visualizerbased onnetjsongraph.jsREST APIthat exposes data inNetJSONNetworkGraphformatadmin interfacethat allows to easily manage, audit, visualize and
debug topologies and their relative data (nodes, links)RECEIVE network topology datafrom multiple nodestopology history: allows saving daily snapshots of each topology that
can be viewed in the frontendfaster monitoring:integrates with OpenWISP Controller and OpenWISP Monitoringfor faster detection of critical events in the networkInstallation instructionsDeploy it in productionAn automated installer is provided by theOpenWISPproject:ansible-openwisp2.Ensure to follow the instructions explained in the following section:Enabling the network topology
module.Install stable version from pypiInstall from pypi:pipinstallopenwisp-network-topologyInstall development versionInstall tarball:pipinstallhttps://github.com/openwisp/openwisp-network-topology/tarball/masterAlternatively you can install via pip using git:pipinstall-egit+git://github.com/openwisp/openwisp-network-topology#egg=openwisp-network-topologyIf you want to contribute, install your cloned fork:gitclonegit@github.com:<your_fork>/openwisp-network-topology.gitcdopenwisp-network-topologypythonsetup.pydevelopInstalling for developmentInstall sqlite:sudoapt-getinstallsqlite3libsqlite3-devInstall your forked repo:gitclonegit://github.com/<your_fork>/openwisp-network-topologycdopenwisp-network-topology/pythonsetup.pydevelopInstall test requirements:pipinstall-rrequirements-test.txtCreate database:cdtests/./manage.pymigrate./manage.pycreatesuperuserYou can access the admin interface athttp://127.0.0.1:8000/admin/.Run tests with:./runtests.pyRun qa tests:./run-qa-checksSetup (integrate in an existing django project)Addopenwisp_network_topologyand its dependencies toINSTALLED_APPS:INSTALLED_APPS=[# other apps'openwisp_network_topology','openwisp_users.accounts','allauth','allauth.account','openwisp_users','rest_framework',]Add the URLs to your mainurls.py:fromdjango.contribimportadminurlpatterns=[# ... other urls in your project ...path('',include('openwisp_network_topology.urls')),path('admin/',admin.site.urls),]Then run:./manage.pymigrateQuickstart GuideThis module works by periodically collecting the network topology
graph data of thesupported networking software or formats.
The data has to be either fetched by the application or received in POST API
requests, therefore after deploying the application, additional steps are required
to make the data collection and visualization work, read on to find out how.Creating a topologyCreate a topology object by going toNetwork Topology>Topologies>Add topology.Give an appropriate label to the topology.Select thetopology formatfrom the dropdown menu. Thetopology formatdetermines which parser should be used to process topology data.Select theStrategyfor updating this topology.If you are usingFETCH strategy, then enter the
URL for fetching topology data in theUrlfield.If you are usingRECEIVE strategy, you will get theURLfor sending topology data. TheRECEIVEstrategy provides an
additional fieldexpiration time. This can be used to add delay in
marking missing links as down.Sending data for topology with RECEIVE strategyCopy theURLgenerated by OpenWISP for sending the topology data.E.g., in our case the URL ishttp://127.0.0.1:8000/api/v1/network-topology/topology/d17e539a-1793-4be2-80a4-c305eca64fd8/receive/?key=cMGsvio8q0L0BGLd5twiFHQOqIEKI423.Create a script (eg:/opt/send-topology.sh) which sends the topology
data usingPOST, in the example script below we are sending the
status log data of OpenVPN but the same code can be applied to other
formats by replacingcat /var/log/openvpn/tun0.statswith the
actual command which returns the network topology output:#!/bin/bash# Get OpenVPN topology data from OpenVPN management interfacecat/var/log/openvpn/tun0.stats|# Upload the topology data to OpenWISPcurl-s-XPOST\--data-binary@-\--header"Content-Type: text/plain"\http://127.0.0.1:8000/api/v1/network-topology/topology/d17e539a-1793-4be2-80a4-c305eca64fd8/receive/?key=cMGsvio8q0L0BGLd5twiFHQOqIEKI423Add the/opt/send-topology.shscript created in the previous step
to the crontab, here’s an example which sends the topology data every 5 minutes:# flag script as executablechmod+x/opt/send-topology.sh# open crontabcrontab-e## Add the following line and saveecho*/5****/opt/send-topology.shOnce the steps above are completed, you should see nodes and links
being created automatically, you can see the network topology graph
from the admin page of the topology change page
(you have to click on theView topology graphbutton in the upper
right part of the page)
or, alternatively, a non-admin visualizer page is also available at
the URL/topology/topology/<TOPOLOGY-UUID>/.Management Commandsupdate_topologyAfter topology URLs (URLs exposing the files that the topology of the network) have been
added in the admin, theupdate_topologymanagement command can be used to collect data
and start playing with the network graph:./manage.py update_topologyThe management command accepts a--labelargument that will be used to search in
topology labels, eg:./manage.py update_topology --label mytopologysave_snapshotThesave_snapshotmanagement command can be used to save the topology graph data which
could be used to view the network topology graph sometime in future:./manage.py save_snapshotThe management command accepts a--labelargument that will be used to search in
topology labels, eg:./manage.py save_snapshot --label mytopologyupgrade_from_django_netjsongraphIf you are upgrading from django-netjsongraph to openwisp-network-topology, there
is an easy migration script that will import your topologies, users & groups to
openwisp-network-topology instance:./manage.py upgrade_from_django_netjsongraphThe management command accepts an argument--backup, that you can pass
to give the location of the backup files, by default it looks in thetests/directory, eg:./manage.py upgrade_from_django_netjsongraph --backup /home/user/django_netjsongraph/The management command accepts another argument--organization, if you want to
import data to a specific organization, you can give its UUID for the same,
by default the data is added to the first found organization, eg:./manage.py upgrade_from_django_netjsongraph --organization 900856da-c89a-412d-8fee-45a9c763ca0bNote: you can follow thetutorial to migrate database from django-netjsongraph.create_device_nodesThis management command can be used to create the initialDeviceNoderelationships when theintegration with OpenWISP Controlleris enabled in a pre-existing system which already has some devices and topology objects in its database../manage.pycreate_device_nodesLoggingTheupdate_topologymanagement command will automatically try to log errors.For a good defaultLOGGINGconfiguration refer to thetest settings.StrategiesThere are mainly two ways of collecting topology information:FETCHstrategyRECEIVEstrategyEachTopologyinstance has astrategyfield which can be set to the desired setting.FETCH strategyTopology data will be fetched from a URL.When some links are not detected anymore they will be flagged as “down” straightaway.RECEIVE strategyTopology data is sent directly from one or more nodes of the network.The collector waits to receive data in the payload of a POST HTTP request;
when such a request is received, akeyparameter it’s first checked against
theTopologykey.If the request is authorized the collector proceeds to update the topology.If the data is sent from one node only, it’s highly advised to set theexpiration_timeof theTopologyinstance to0(seconds), this way the
system works just like in theFETCH strategy, with the only difference that
the data is sent by one node instead of fetched by the collector.If the data is sent from multiple nodes, youSHOULDset theexpiration_timeof theTopologyinstance to a value slightly higher than the interval used
by nodes to send the topology, this way links will be flagged as “down” only if
they haven’t been detected for a while. This mechanism allows to visualize the
topology even if the network has been split in several parts, the disadvantage
is that it will take a bit more time to detect links that go offline.Integration with OpenWISP Controller and OpenWISP MonitoringIf you useOpenWISP ControllerorOpenWISP Monitoringand you use OpenVPN for the management VPN, you can use the integration available inopenwisp_network_topology.integrations.device.This additional and optional module provides the following features:whenever the stauts of an OpenVPN link changes:the management IP address of the related device is updated straightawayif OpenWISP Monitoring is enabled, the device checks are triggered (e.g.: ping)This integration makes the whole system a lot faster in detecting important events in the network.In order to use this module simply addopenwisp_network_topology.integrations.devicetoINSTALLED_APPS:INSTALLED_APPS=[# other apps (eg: openwisp-controller, openwisp-monitoring)'openwisp_network_topology','openwisp_network_topology.integrations.device','openwisp_users.accounts','allauth','allauth.account','openwisp_users','rest_framework',]If you are enabling this integration on a pre-existing system, use thecreate_device_nodesmanagement command to create
the relationship between devices and nodes.SettingsOPENWISP_NETWORK_TOPOLOGY_PARSERStype:listdefault:[]Additional customnetdiff parsers.OPENWISP_NETWORK_TOPOLOGY_SIGNALStype:strdefault:NoneString representing python module to import on initialization.Useful for loading django signals or to define custom behaviour.OPENWISP_NETWORK_TOPOLOGY_TIMEOUTtype:intdefault:8Timeout when fetching topology URLs.OPENWISP_NETWORK_TOPOLOGY_LINK_EXPIRATIONtype:intdefault:60If a link is down for more days than this number, it will be deleted by theupdate_topologymanagement command.Setting this toFalsewill disable this feature.OPENWISP_NETWORK_TOPOLOGY_VISUALIZER_CSStype:strdefault:netjsongraph/css/style.cssPath of the visualizer css file. Allows customization of css according to user’s
preferences.OPENWISP_NETWORK_TOPOLOGY_NODE_EXPIRATIONtype:intdefault:FalseIf a node has not been modified since the days specified and if it has no links,
it will be deleted by theupdate_topologymanagement command. This depends onOPENWISP_NETWORK_TOPOLOGY_LINK_EXPIRATIONbeing enabled.
ReplaceFalsewith an integer to enable the feature.OPENWISP_NETWORK_TOPOLOGY_API_URLCONFtype:stringdefault:NoneUse theurlconfoption to change receive api url to point to
another module, example,myapp.urls.OPENWISP_NETWORK_TOPOLOGY_API_BASEURLtype:stringdefault:NoneIf you have a seperate instance of openwisp-network-topology on a
different domain, you can use this option to change the base
of the url, this will enable you to point all the API urls to
your openwisp-network-topology API server’s domain,
example value:https://mytopology.myapp.com.OPENWISP_NETWORK_TOPOLOGY_API_AUTH_REQUIREDtype:booleandefault:TrueWhen enabled, the APIendpointswill only allow authenticated users
who have the necessary permissions to access the objects which
belong to the organizations the user manages.Rest APILive documentationA general live API documentation (following the OpenAPI specification) at/api/v1/docs/.Browsable web interfaceAdditionally, opening any of the endpointslisted belowdirectly in the browser will show thebrowsable API interface of Django-REST-Framework,
which makes it even easier to find out the details of each endpoint.List of endpointsSince the detailed explanation is contained in theLive documentationand in theBrowsable web pageof each point,
here we’ll provide just a list of the available endpoints,
for further information please open the URL of the endpoint in your browser.List topologiesGET /api/v1/network-topology/topology/Available filters:strategy: Filter topologies based on their strategy (fetchorreceive).
E.g.?strategy=<topology_strategy>.parser: Filter topologies based on their parser.
E.g.?parser=<topology_parsers>.organization: Filter topologies based on their organization.
E.g.?organization=<topology_organization_id>.You can use multiple filters in one request, e.g.:/api/v1/network-topology/topology/?organization=371791ec-e3fe-4c9a-8972-3e8b882416f6&strategy=fetchNote: By default,/api/v1/network-topology/topology/does not include
unpublished topologies. If you want to include unpublished topologies in the
response, use?include_unpublished=truefilter as following:GET /api/v1/network-topology/topology/?include_unpublished=trueCreate topologyPOST /api/v1/network-topology/topology/Detail of a topologyGET /api/v1/network-topology/topology/{id}/Note: By default,/api/v1/network-topology/topology/{id}/will returnHTTP 404 Not Foundfor unpublished topologies. If you want to retrieve an
unpublished topology, use?include_unpublished=truefilter as following:GET /api/v1/network-topology/topology/{id}/?include_unpublished=trueChange topolgy detailPUT /api/v1/network-topology/topology/{id}/Patch topology detailPATCH /api/v1/network-topology/topology/{id}/Delete topologyDELETE /api/v1/network-topology/topology/{id}/View topology historyThis endpoint is used to go back in time to view previous topology snapshots.
For it to work, snapshots need to be saved periodically as described insave_snapshotsection above.For example, we could use the endpoint to view the snapshot of a topology
saved on2020-08-08as follows.GET /api/v1/network-topology/topology/{id}/history/?date=2020-08-08Send topology dataPOST /api/v1/network-topology/topology/{id}/receive/List linksGET /api/v1/network-topology/link/Available filters:topology: Filter links belonging to a topology.
E.g.?topology=<topology_id>.organization: Filter links belonging to an organization.
E.g.?organization=<organization_id>.status: Filter links based on their status (upordown).
E.g.?status=<link_status>.You can use multiple filters in one request, e.g.:/api/v1/network-topology/link/?status=down&topology=7fce01bd-29c0-48b1-8fce-0508f2d75d36Create linkPOST /api/v1/network-topology/link/Get link detailGET /api/v1/network-topology/link/{id}/Change link detailPUT /api/v1/network-topology/link/{id}/Patch link detailPATCH /api/v1/network-topology/link/{id}/Delete linkDELETE /api/v1/network-topology/link/{id}/List nodesGET /api/v1/network-topology/node/Available filters:topology: Filter nodes belonging to a topology.
E.g.?topology=<topology_id>.organization: Filter nodes belonging to an organization.
E.g.?organization=<organization_id>.You can use multiple filters in one request, e.g.:/api/v1/network-topology/node/?organization=371791ec-e3fe-4c9a-8972-3e8b882416f6&topology=7fce01bd-29c0-48b1-8fce-0508f2d75d36Create nodePOST /api/v1/network-topology/node/Get node detailGET /api/v1/network-topology/node/{id}/Change node detailPUT /api/v1/network-topology/node/{id}/Patch node detailPATCH /api/v1/network-topology/node/{id}/Delete nodeDELETE /api/v1/network-topology/node/{id}/Overriding visualizer templatesFollow these steps to override and customise the visualizer’s default templates:create a directory in your django project and put its full path inTEMPLATES['DIRS'],
which can be found in the djangosettings.pyfilecreate a sub directory namednetjsongraphand add all the templates which shall override
the defaultnetjsongraph/*templatescreate a template file with the same name of the template file you want to overrideMore information about the syntax used in django templates can be found in thedjango templates
documentation.Example: overriding the<script>tagHere’s a step by step guide on how to change the javascript options passed tonetjsongraph.js, remember to replace<project_path>with the
absolute filesytem path of your project.Step 1: create a directory in<project_path>/templates/netjsongraphStep 2: open yoursettings.pyand edit theTEMPLATES['DIRS']setting so that it looks
like the following example:# settings.pyTEMPLATES=[{'DIRS':[os.path.join(BASE_DIR,'templates')],# ... all other lines have been omitted for brevity ...}]Step 3: create a new file namednetjsongraph-script.htmlin
the new<project_path>/templates/netjsongraph/directory, eg:<!-- <project_path>/templates/netjsongraph/netjsongraph-script.html --><script>window.__njg_el__=window.__njg_el__||"body";window.__njg_default_url__="{{ graph_url }}";window.loadNetJsonGraph=function(graph){graph=graph||window.__njg_default_url__;d3.select("svg").remove();d3.select(".njg-overlay").remove();d3.select(".njg-metadata").remove();returnd3.netJsonGraph(graph,{el:window.__njg_el__,// customizations of netjsongraph.jslinkClassProperty:"status",defaultStyle:false,labelDy:"-1.4em",circleRadius:8,charge:-100,gravity:0.3,linkDistance:100,linkStrength:0.2,});};window.graph=window.loadNetJsonGraph();window.initTopologyHistory(jQuery);</script>Extending openwisp-network-topologyOne of the core values of the OpenWISP project isSoftware Reusability,
for this reasonopenwisp-network-topologyprovides a set of base classes
which can be imported, extended and reused to create derivative apps.In order to implement your custom version ofopenwisp-network-topology,
you need to perform the steps described in this section.When in doubt, the code in thetest projectand thesample appwill serve you as source of truth:
just replicate and adapt that code to get a basic derivative ofopenwisp-network-topologyworking.Premise: if you plan on using a customized version of this module,
we suggest to start with it since the beginning, because migrating your data
from the default module to your extended version may be time consuming.1. Initialize your custom moduleThe first thing you need to do is to create a new django app which will
contain your custom version ofopenwisp-network-topology.A django app is nothing more than apython package(a directory of python scripts), in the following examples we’ll call this django appsample_network_topology, but you can name it how you want:django-admin startapp sample_network_topologyIf you use the integration with openwisp-controller, you may want to extend also the
integration app if you need:django-admin startapp sample_integration_deviceKeep in mind that the command mentioned above must be called from a directory
which is available in yourPYTHON_PATHso that you can then import the result into your project.Now you need to addsample_network_topologytoINSTALLED_APPSin yoursettings.py,
ensuring also thatopenwisp_network_topologyhas been removed:INSTALLED_APPS=[# ... other apps ...'openwisp_utils.admin_theme',# all-auth'django.contrib.sites','openwisp_users.accounts','allauth','allauth.account','allauth.socialaccount',# (optional) openwisp_controller - required only if you are using the integration app'openwisp_controller.pki','openwisp_controller.config','reversion','sortedm2m',# network topology# 'sample_network_topology' <-- uncomment and replace with your app-name here# (optional) required only if you need to extend the integration app# 'sample_integration_device' <-- uncomment and replace with your integration-app-name here'openwisp_users',# admin'django.contrib.admin',# rest framework'rest_framework',]For more information about how to work with django projects and django apps,
please refer to thedjango documentation.2. Installopenwisp-network-topologyInstall (and add to the requirement of your project) openwisp-network-topology:pip install openwisp-network-topology3. AddEXTENDED_APPSAdd the following to yoursettings.py:EXTENDED_APPS=('openwisp_network_topology',)4. Addopenwisp_utils.staticfiles.DependencyFinderAddopenwisp_utils.staticfiles.DependencyFindertoSTATICFILES_FINDERSin yoursettings.py:STATICFILES_FINDERS=['django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder','openwisp_utils.staticfiles.DependencyFinder',]5. Addopenwisp_utils.loaders.DependencyLoaderAddopenwisp_utils.loaders.DependencyLoadertoTEMPLATESin yoursettings.py:TEMPLATES=[{'BACKEND':'django.template.backends.django.DjangoTemplates','OPTIONS':{'loaders':['django.template.loaders.filesystem.Loader','django.template.loaders.app_directories.Loader','openwisp_utils.loaders.DependencyLoader',],'context_processors':['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},}]6. Inherit the AppConfig classPlease refer to the following files in the sample app of the test project:sample_network_topology/__init__.py.sample_network_topology/apps.py.For the integration with openwisp-controller, see:sample_integration_device/__init__.py.sample_integration_device/apps.py.You have to replicate and adapt that code in your project.For more information regarding the concept ofAppConfigplease refer to
the“Applications” section in the django documentation.7. Create your custom modelsPlease refer tosample_app models fileuse in the test project.You have to replicate and adapt that code in your project.Note: for doubts regarding how to use, extend or develop models please refer to
the“Models” section in the django documentation.8. Add swapper configurationsOnce you have created the models, add the following to yoursettings.py:# Setting models for swapper moduleTOPOLOGY_LINK_MODEL='sample_network_topology.Link'TOPOLOGY_NODE_MODEL='sample_network_topology.Node'TOPOLOGY_SNAPSHOT_MODEL='sample_network_topology.Snapshot'TOPOLOGY_TOPOLOGY_MODEL='sample_network_topology.Topology'# if you use the integration with OpenWISP Controller and/or OpenWISP MonitoringTOPOLOGY_DEVICE_DEVICENODE_MODEL='sample_integration_device.DeviceNode'Substitutesample_network_topologywith the name you chose in step 1.9. Create database migrationsCreate and apply database migrations:./manage.py makemigrations
./manage.py migrateFor more information, refer to the“Migrations” section in the django documentation.10. Create the adminRefer to theadmin.py file of the sample app.To introduce changes to the admin, you can do it in two main ways which are described below.Note: for more information regarding how the django admin works, or how it can be customized,
please refer to“The django admin site” section in the django documentation.1. Monkey patchingIf the changes you need to add are relatively small, you can resort to monkey patching.For example:fromopenwisp_network_topology.adminimportTopologyAdmin,LinkAdmin,NodeAdmin# TopologyAdmin.list_display.insert(1, 'my_custom_field') <-- your custom change example# LinkAdmin.list_display.insert(1, 'my_custom_field') <-- your custom change example# NodeAdmin.list_display.insert(1, 'my_custom_field') <-- your custom change example2. Inheriting admin classesIf you need to introduce significant changes and/or you don’t want to resort to
monkey patching, you can proceed as follows:fromdjango.contribimportadminfromswapperimportload_modelfromopenwisp_network_topology.adminimport(TopologyAdminasBaseTopologyAdmin,LinkAdminasBaseLinkAdmin,NodeAdminasBaseNodeAdmin)Node=load_model('topology','Node')Link=load_model('topology','Link')Topology=load_model('topology','Topology')admin.site.unregister(Topology)admin.site.unregister(Link)admin.site.unregister(Node)@admin.register(Topology,TopologyAdmin)classTopologyAdmin(BaseTopologyAdmin):# add your changes here@admin.register(Link,LinkAdmin)classLinkAdmin(BaseLinkAdmin):# add your changes here@admin.register(Node,NodeAdmin)classNodeAdmin(BaseNodeAdmin):# add your changes here11. Create root URL configurationPlease read and replicate according to your project needs:Thefollowingcanbeusedtoregisteralltheurlsinyour``urls.py``.# If you've extended visualizer views (discussed below).# Import visualizer views & function to add it.# from openwisp_network_topology.utils import get_visualizer_urls# from .sample_network_topology.visualizer import viewsurlpatterns=[# If you've extended visualizer views (discussed below).# Add visualizer views in urls.py# path('topology/', include(get_visualizer_urls(views))),path('',include('openwisp_network_topology.urls')),path('admin/',admin.site.urls),]For more information about URL configuration in django, please refer to the“URL dispatcher” section in the django documentation.12. Setup API urlsYou need to create a fileapi/urls.py(the name & path of the file must match)
inside your app, which contains the following:fromopenwisp_network_topology.apiimportviews# When you want to modify views, please change views location# from . import viewsfromopenwisp_network_topology.utilsimportget_api_urlsurlpatterns=get_api_urls(views)13. Extending management commandsTo extend the management commands, createsample_network_topology/management/commandsdirectory and
two files in it:save_snapshot.pyupdate_topology.py14. Import the automated testsWhen developing a custom application based on this module, it’s a good
idea to import and run the base tests too, so that you can be sure the changes
you’re introducing are not breaking some of the existing features ofopenwisp-network-topology.Refer to thetests.py file of the sample app.In case you need to add breaking changes, you can overwrite the tests defined
in the base classes to test your own behavior.For testing you also need to extend the fixtures, you can copy the
fileopenwisp_network_topology/fixtures/test_users.jsonin your sample app’sfixtures/directory.Now, you can then run tests with:# the --parallel flag is optional
./manage.py test --parallel sample_network_topologySubstitutesample_network_topologywith the name you chose in step 1.For more information about automated tests in django, please refer to“Testing in Django”.Other base classes that can be inherited and extendedThe following steps are not required and are intended for more advanced customization.1. Extending API viewsExtending the views is only required when you want to make changes in the
behaviour of the API.
Please refer tosample_network_topology/api/views.pyand replicate it in your application.If you extend these views, remember to use these views in theapi/urls.py.2. Extending the Visualizer viewsSimilar to API views, visualizer views are only required to be extended
when you want to make changes in the Visualizer.
Please refer tosample_network_topology/visualizer/views.pyand replicate it in your application.If you extend these views, remember to use these views in theurls.py.ContributingPlease refer to theOpenWISP contributing guidelines.ChangelogSeeCHANGES.LicenseSeeLICENSE.This projects bundles third-party javascript libraries in its source code:D3.js (BSD-3-Clause)SupportSeeOpenWISP Support Channels.