├── INSTALLATION
├── LICENSE
├── README.md
├── docs
├── screenshot-customfield.png
├── screenshot-panel.png
└── screenshot-site.png
├── install.sh
├── netbox
├── project-static
│ ├── img
│ │ └── topology
│ ├── js
│ │ ├── topology.js
│ │ └── topology_config.json
│ └── vis-4.21.0
└── static
│ ├── img
│ └── topology
│ │ ├── access-switch.png
│ │ ├── core-switch.png
│ │ ├── distribution-switch.png
│ │ ├── firewall.png
│ │ ├── role-unknown.png
│ │ └── router.png
│ ├── js
│ ├── topology.js
│ └── topology_config.json
│ └── vis-4.21.0
│ ├── vis-network.min.css
│ └── vis-network.min.js
├── topology.patch
└── uninstall.sh
/INSTALLATION:
--------------------------------------------------------------------------------
1 | INSTALLATION:
2 |
3 | 1. clone git repo
4 | git clone https://github.com/bashioo/netbox_topology.git
5 |
6 | 2. run install.sh, sudo might be required to get access to netbox installation directory:
7 | cd netbox_topology
8 | sudo ./install.sh
9 |
10 | 3. restart netbox via supervisord or apache/nginx depending on your installation
11 | sudo supervisorctl restart netbox
12 |
13 | 4. open django admin web-interface and create a custom text field named "coordinates" under dcim->device model
14 |
15 | 5. let me know if there are any issues - https://github.com/bashioo/netbox_topology/issues
16 |
17 |
18 |
19 | UNINSTALLATION:
20 | sudo ./uninstall.sh
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # netbox_topology [deprecated]
2 |
3 | ## This project is no longer supported!
4 | ### Please consider switching to one of the forks, like: https://github.com/mylivingweb/netbox_topology or https://github.com/NoOne-dev/netbox_topology
5 |
6 | While it was a great fun to create and support this addon I just cannot keep it active. I do not use Netbox as an IPAM anymore so I would not be able to keep up with its changes to make sure my topology is still compatible with the current Netbox API version.
7 |
8 | ---
9 |
10 | Patch to apply to a netbox installation to add beautiful topology view to sites
11 |
12 | Once installed your individual site's pages should look like this:
13 |
14 | 
15 |
16 | This module allows to create and delete connections between interfaces via control panel:
17 |
18 | 
19 |
20 | ## INSTALL:
21 |
22 | 1. clone git repo
23 |
24 | ```
25 | git clone https://github.com/bashioo/netbox_topology.git
26 | ```
27 |
28 | 2. run install.sh, sudo might be required to get access to netbox installation directory:
29 |
30 | ```
31 | cd netbox_topology
32 | sudo ./install.sh
33 | ```
34 |
35 | 3. restart netbox via supervisord or apache/nginx depending on your installation
36 |
37 | ```
38 | sudo supervisorctl restart netbox
39 | sudo service apache2 restart
40 | ```
41 |
42 | 4. open django admin web-interface and create a custom text field named "coordinates" under dcim->device model
43 |
44 | 
45 |
46 | 5. modify NETBOXPATH/netbox/static/js/topology_config.json to include your list on roles to hide from the topology view.
47 |
48 | please note that the list should include SLUGs, not names. please check that json is valid.
49 |
50 | 6. let me know if there are any issues - https://github.com/bashioo/netbox_topology/issues
51 |
52 |
53 |
54 | ## UNINSTALL:
55 |
56 | ```
57 | sudo ./uninstall.sh
58 | ```
59 |
60 | OR if your installation is GIT based (Option 2 from Netbox installation guide):
61 |
62 | ```
63 | cd /opt/netbox
64 | git checkout .
65 | ```
66 |
--------------------------------------------------------------------------------
/docs/screenshot-customfield.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/docs/screenshot-customfield.png
--------------------------------------------------------------------------------
/docs/screenshot-panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/docs/screenshot-panel.png
--------------------------------------------------------------------------------
/docs/screenshot-site.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/docs/screenshot-site.png
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo -n "Netbox installation directory? Press Enter for default [/opt/netbox]: "
4 | read NETBOX_DIR
5 |
6 | if [ -z "$NETBOX_DIR" ]; then
7 | NETBOX_DIR="/opt/netbox"
8 | fi
9 |
10 | cp -r -v netbox/ "$NETBOX_DIR"
11 |
12 | patch -d "$NETBOX_DIR" -b -p0 -N -r- < topology.patch
13 |
14 | echo "Done! Please restart netbox now to apply changes."
15 | echo "sudo supervisorctl restart netbox"
16 | echo ""
17 | echo "Please do not forget to create 'coordinates' custom_field in dcim/device model"
18 |
--------------------------------------------------------------------------------
/netbox/project-static/img/topology:
--------------------------------------------------------------------------------
1 | ../../static/img/topology/
--------------------------------------------------------------------------------
/netbox/project-static/js/topology.js:
--------------------------------------------------------------------------------
1 | ../../static/js/topology.js
--------------------------------------------------------------------------------
/netbox/project-static/js/topology_config.json:
--------------------------------------------------------------------------------
1 | ../../static/js/topology_config.json
--------------------------------------------------------------------------------
/netbox/project-static/vis-4.21.0:
--------------------------------------------------------------------------------
1 | ../static/vis-4.21.0/
--------------------------------------------------------------------------------
/netbox/static/img/topology/access-switch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/netbox/static/img/topology/access-switch.png
--------------------------------------------------------------------------------
/netbox/static/img/topology/core-switch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/netbox/static/img/topology/core-switch.png
--------------------------------------------------------------------------------
/netbox/static/img/topology/distribution-switch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/netbox/static/img/topology/distribution-switch.png
--------------------------------------------------------------------------------
/netbox/static/img/topology/firewall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/netbox/static/img/topology/firewall.png
--------------------------------------------------------------------------------
/netbox/static/img/topology/role-unknown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/netbox/static/img/topology/role-unknown.png
--------------------------------------------------------------------------------
/netbox/static/img/topology/router.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bashioo/netbox_topology/73b4c55c767ca1799b31ab4022bdd10d78b35a93/netbox/static/img/topology/router.png
--------------------------------------------------------------------------------
/netbox/static/js/topology.js:
--------------------------------------------------------------------------------
1 | var nodes = new vis.DataSet();
2 | var edges = new vis.DataSet();
3 | var container = document.getElementById('visjsgraph');
4 |
5 | var options = {
6 | height: '600px',
7 | // default node style
8 | nodes: {
9 | shape: 'image',
10 | brokenImage: TOPOLOGY_IMG_DIR + 'role-unknown.png',
11 | size: 35,
12 | font: {
13 | multi: 'md',
14 | face: 'helvetica',
15 | },
16 | },
17 | // default edge style
18 | edges: {
19 | length: 100,
20 | width: 2,
21 | font: {
22 | face: 'helvetica',
23 | },
24 | },
25 | physics: {
26 | solver: 'forceAtlas2Based', //best solver fot network diagrams
27 | },
28 | manipulation: {
29 | addEdge: addEdge,
30 | },
31 | };
32 |
33 | var topology = new vis.Network(container, {nodes: nodes, edges: edges}, options);
34 |
35 | topology.on("dragEnd", function (params){
36 | dragged = this.getPositions(params.nodes);
37 | $.each(dragged, function(node_id, coordinates){
38 | if (CHANGE_DEVICE_ALLOWED) {
39 | api_call('/api/dcim/devices/'+node_id+'/', 'PATCH', {custom_fields: {coordinates: coordinates.x+';'+coordinates.y}});
40 | }
41 | nodes.update({ id: node_id, physics: false });
42 | });
43 | });
44 |
45 | topology.on("click", function (params) {
46 | if (params.edges.length == 1 & params.nodes.length == 0){
47 | $( '#topology_delete_edge' ).removeClass('disabled');
48 | }else{
49 | $( '#topology_delete_edge' ).addClass('disabled');
50 | }
51 | });
52 |
53 | // load configuration
54 | api_call("/static/js/topology_config.json", "GET", undefined, function(config) {
55 | var hidden_roles = config.hidden_roles;
56 |
57 | // load devices
58 | api_call("/api/dcim/devices/?limit=0&site="+SITE_SLUG, "GET", undefined, function(response) {
59 | $.each(response.results, function(index, device) {
60 | if (hidden_roles.includes(device.device_role.slug)) {
61 | console.log(device.name+' has been hidden because of its role '+device.device_role.slug);
62 | return undefined;
63 | }
64 | var node = {
65 | id: device.id,
66 | name: device.name,
67 | label: '*'+device.name+'*\n'+device.device_type.model,
68 | image: TOPOLOGY_IMG_DIR + device.device_role.slug+'.png',
69 | title: device.device_role.name+' '
70 | +device.name+' '
71 | +device.device_type.manufacturer.name+' '+device.device_type.model+' '
72 | +'SN: '+device.serial,
73 | }
74 | if (device.custom_fields.coordinates){
75 | var coordinates = device.custom_fields.coordinates.split(";");
76 | node.x = parseInt(coordinates[0]);
77 | node.y = parseInt(coordinates[1]);
78 | node.physics = false;
79 | }
80 | nodes.add(node);
81 | });
82 | // once all nodes a loaded fit them to viewport
83 | topology.fit();
84 | });
85 |
86 | // load connections
87 | api_call("/api/dcim/interface-connections/?limit=0&site="+SITE_SLUG, "GET", undefined, function(response){
88 | $.each(response.results, function(index, connection) {
89 |
90 | // after 2.4.3 form_factor is not being returned as part of the interface
91 | if (connection.interface_a.form_factor) {
92 | var color = get_connection_color(
93 | connection.interface_a.form_factor.value,
94 | connection.interface_b.form_factor.value
95 | );
96 | } else {
97 | var color = undefined;
98 | }
99 |
100 | edges.add({
101 | id: connection.id,
102 | from: connection.interface_a.device.id,
103 | to: connection.interface_b.device.id,
104 | dashes: !connection.connection_status.value,
105 | color: {color: color, highlight: color, hover: color},
106 | title: 'Connection between '
107 | +connection.interface_a.device.name+' ['+connection.interface_a.name+'] '
108 | +connection.interface_b.device.name+' ['+connection.interface_b.name+']',
109 | });
110 | });
111 | });
112 | });
113 |
114 |
115 | $( '#topology_delete_edge' ).on('click', function() {
116 | if (topology.getSelectedEdges().length != 1) return false;
117 | var edge_id = topology.getSelectedEdges()[0];
118 | $('#delete_connection_label').html(edges.get(edge_id).title );
119 | $( "#delete_connection_dialog" ).dialog({
120 | width: 400,
121 | resizable: false,
122 | close: function(){
123 | $( '#delete_connection_confirm' ).off('click');
124 | },
125 | buttons: [
126 | {
127 | text: 'Delete',
128 | class: 'btn btn-primary',
129 | click: function() {
130 | api_call(
131 | '/api/dcim/interface-connections/'+edge_id+'/',
132 | 'DELETE',
133 | undefined,
134 | function(response, status) {
135 | // only remove edge if API DELETE returned
136 | edges.remove(edge_id);
137 | $( '#topology_delete_edge' ).addClass('disabled');
138 | },
139 | );
140 | $( this ).dialog( "close" );
141 | }
142 | },
143 | {
144 | text: "Cancel",
145 | class: 'btn btn-primary',
146 | click: function() {
147 | $( this ).dialog( "close" );
148 | }
149 | },
150 | ]
151 | });
152 | });
153 |
154 | $( '#topology_add_edge' ).on('click', function(){
155 | $( '#topology_add_edge' ).toggleClass('addMode');
156 | if ($( '#topology_add_edge' ).hasClass('addMode')) {
157 | $( '#topology_add_edge_label' ).text('Cancel');
158 | topology.addEdgeMode();
159 | }else{
160 | $( '#topology_add_edge_label' ).text('New connection');
161 | topology.disableEditMode();
162 | }
163 | });
164 |
165 | $( '#topology_reset_coordinates' ).on('click', function() {
166 | $.each(nodes.getIds(), function(undefined, node_id){
167 | nodes.update({ id: node_id, physics: true });
168 | api_call('/api/dcim/devices/'+node_id+'/', 'PATCH', {custom_fields: {coordinates: ''}});
169 | })
170 | });
171 |
172 |
173 | function addEdge(edgeData,callback) {
174 | // cancel built-in add routine
175 | callback(null);
176 | topology.disableEditMode();
177 | populate_interfaces('device_a', edgeData.from);
178 | populate_interfaces('device_b', edgeData.to);
179 | $( "#add_connection_dialog" ).dialog({
180 | width: 600,
181 | resizable: false,
182 | close: function( event, ui ) {
183 | $( '#topology_add_edge_label' ).text('New connection');
184 | $( '#topology_add_edge' ).removeClass('addMode');
185 | },
186 | buttons: [
187 | {
188 | text: "Create",
189 | class: 'btn btn-primary',
190 | click: function() {
191 | var data = {
192 | interface_a: $('#device_a_interfaces').val(),
193 | interface_b: $('#device_b_interfaces').val(),
194 | connection_status: $('#connection_status').val(),
195 | };
196 | api_call("/api/dcim/interface-connections/", "POST", data, function(response, status){
197 | // only draw edge if API call was successful
198 | var color = get_connection_color(
199 | $('#device_a_interfaces option:selected').attr('form_factor'),
200 | $('#device_b_interfaces option:selected').attr('form_factor')
201 | );
202 | edgeData.id = response.id;
203 | edgeData.dashes = !response.connection_status;
204 | edgeData.color = {color: color, highlight: color, hover: color},
205 | edgeData.title = 'Connection between '
206 | +nodes.get(edgeData.from).name+' ['+$('#device_a_interfaces option:selected').text()+'] '
207 | +nodes.get(edgeData.to).name+' ['+$('#device_b_interfaces option:selected').text()+']';
208 | edges.add(edgeData);
209 | })
210 | $( this ).dialog( "close" );
211 | }
212 | },
213 | {
214 | text: "Cancel",
215 | class: 'btn btn-primary',
216 | click: function() {
217 | $( this ).dialog( "close" );
218 | },
219 | },
220 | ],
221 | });
222 | }
223 |
224 | function api_call(url, method, data, callback){
225 | $.ajax({
226 | url: url,
227 | headers: {"X-CSRFToken": TOKEN},
228 | dataType: 'json',
229 | contentType: 'application/json',
230 | method: method || "GET",
231 | data: JSON.stringify(data),
232 | success: callback,
233 | }).fail(function(response){
234 | console.log(response);
235 | });
236 | }
237 |
238 | function get_connection_color(interface_a, interface_b) {
239 | var ff_a = Math.floor(interface_a/100);
240 | var ff_b = Math.floor(interface_b/100);
241 | if ( (ff_a == 50) & (ff_b == 50) ){
242 | // stack cable
243 | return '#000000';
244 | }
245 | // default color
246 | return undefined;
247 | }
248 |
249 | function populate_interfaces(device_tag, device_id) {
250 | api_call('/api/dcim/interfaces/?limit=0&device_id='+device_id, "GET", undefined, function(response, status) {
251 | $('#'+device_tag+'_interfaces').html('');
252 | $.each(response.results.filter(function(interface){return interface.device.id == device_id}), function(index, interface){
253 | // ignore virtual interfaces
254 | if (interface.form_factor.value < 800) return;
255 | $('#'+device_tag+'_interfaces').append($('