Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Added VC collapse/expand display mode
  • Loading branch information
den-it committed Aug 13, 2020
2 parents bdd0634 + 91c2cf0 commit 3157c0b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
15 changes: 9 additions & 6 deletions backend/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def getMap(id):
d.id AS netbox_id,
d.serial AS serial,
vc.domain AS virtual_chassis,
vc.master_id AS virtual_chassis_master_netbox_id,
c.name AS cluster,
r.name AS type,
t.model AS model,
Expand Down Expand Up @@ -441,29 +442,31 @@ def getMap(id):
})

for node in graphJson["results"]["nodes"]:
if not (node["cluster"]):
if not node["cluster"]:
node.pop("cluster", None)
if not (node["virtual_chassis"]):
if not node["virtual_chassis"]:
node.pop("virtual_chassis", None)
if not node["virtual_chassis_master_netbox_id"]:
node.pop("virtual_chassis_master_netbox_id")

for node in graphJson["results"]["interfaces"]:
for interface in graphJson["results"]["interfaces"][node]:
if not (interface["lag"]):
if not interface["lag"]:
interface.pop("lag", None)
interface.pop("lag_netbox_id", None)

if not (interface["neighbor"]):
if not interface["neighbor"]:
interface.pop("neighbor", None)
interface.pop("neighbor_interface", None)
interface.pop("neighbor_interface_netbox_id", None)
interface.pop("neighbor_netbox_id", None)

for i, value in enumerate(graphJson["results"]["links"]):
if (graphJson["results"]["links"][i]["quantity"] > 1):
if graphJson["results"]["links"][i]["quantity"] > 1:
graphJson["results"]["links"][i]["quantity"] = int(graphJson["results"]["links"][i]["quantity"] / 2)

for i, value in enumerate(graphJson["results"]["mng_links"]):
if (graphJson["results"]["mng_links"][i]["quantity"] > 1):
if graphJson["results"]["mng_links"][i]["quantity"] > 1:
graphJson["results"]["mng_links"][i]["quantity"] = int(graphJson["results"]["mng_links"][i]["quantity"] / 2)

graphJson["result"] = "success"
Expand Down
Binary file modified docs/media/dc1_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/media/dc1_mng_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@
</div>

<footer>
<table width="100%">
<div style="height: 1px; background: #aaaaaa;"></div>
<table style="width: 100%; height: calc(100% - 1px);">
<tr>
<td style="padding: 10px; padding-left: 21px;" class="secondary_text">v0.3.1</td>
<td style="padding: 10px; padding-right: 21px; text-align: right;" class="secondary_text"><a href="https://github.com/den-it/ntmap/blob/master/docs/index.md">Docs</a></td>
<td style="padding-left: 21px;" class="secondary_text">v0.3.2</td>
<td style="padding-right: 21px; text-align: right;" class="secondary_text"><a href="https://github.com/den-it/ntmap/blob/master/docs/index.md">Docs</a></td>
</tr>
</table>
</footer>
Expand Down
27 changes: 17 additions & 10 deletions www/js/l1map.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,18 @@ function getL1Map() {
}


function drawL1Map(hide_virt_chassis, show_prod_links) {
function drawL1Map() {
// select display mode based on the position of radio buttons
if (document.querySelector('input[name="radio_prod_links_mode"]:checked').value == 1)
prodLinksMode = true;
else
prodLinksMode = false;

if (document.querySelector('input[name="radio_expand_vc_mode"]:checked').value == 1)
expandVirtChassisMode = true;
else
expandVirtChassisMode = false;

if (!globalGraph.nodes)
return false;

Expand All @@ -230,8 +241,8 @@ function drawL1Map(hide_virt_chassis, show_prod_links) {
globalSimulation.stop();

var graph = {};
Object.assign(graph, globalGraph);
var graph = JSON.parse(JSON.stringify(globalGraph)); // TODO: check if this works fine for big data structures

// initial svg height & width. Will be corrected later according to the number of elements on L1-map
var svgHeight = 0;
var svgWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) - 20;
Expand All @@ -243,15 +254,15 @@ function drawL1Map(hide_virt_chassis, show_prod_links) {
// if (error) throw error;
// graph = test_graph.results;

if (!show_prod_links)
if (!prodLinksMode)
graph.links = graph.mng_links;

var vcDict = {};
var nodesList = new Array();

// Collapse virtual chassis to one node with comprising important properties of all members of VC
// Example: all links beloning to each member should now belong to the node wich represents the whole VC
if (hide_virt_chassis) {
if (!expandVirtChassisMode) {
// Collapse virtual chassis, i.e. throw out all nodes in each VC except for one
for (i in graph.nodes) {
if (graph.nodes[i].hasOwnProperty("virtual_chassis") && graph.nodes[i].virtual_chassis) { // This is a VC node. It shouldn't be added to nodes list. Instead a VC node should be generated
Expand Down Expand Up @@ -325,10 +336,6 @@ function drawL1Map(hide_virt_chassis, show_prod_links) {
}
}

//console.log(vcDict);
//console.log(nodesList);
//console.log(linksList);

graph.nodes = nodesList;
graph.links = linksList;
}
Expand Down Expand Up @@ -421,7 +428,7 @@ function drawL1Map(hide_virt_chassis, show_prod_links) {
//graph.nodes[i].fx=1;
graph.nodes[i].fx = graph.nodes[i].group * svgWidth / groupsArray.length - 60;
}

var svg = d3.select("svg[id='svg1']");
svg
.selectAll("g").remove(); // clear previous chart if any
Expand Down
28 changes: 15 additions & 13 deletions www/map/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<table width="100%" cellspacing="0" cellpadding="0" style="padding: 0; margin: 0;">
<tr>
<td style="padding-left: 20px;">
<img src="/img/logo.png" style="margin-top: 8px; margin-bottom: 8px;"/>
<a href="/"><img src="/img/logo.png" style="margin-top: 8px; margin-bottom: 8px;" border="0"/></a>
</td>
</tr>
<tr>
Expand All @@ -23,18 +23,19 @@
<tr>
<!--<td valign=top style="padding-top:6px">&#x2190; <a href="/">Back to list</a></td>
<td width="16"></td><td width="20"><div class="div-vert-line-80"/></td>-->
<!--<td valign=top style="padding-top:6px">Virtual chassis:</td>-->
<!--<td valign="top">
<td valign=top style="padding-top:6px">Links:</td>
<td valign="top">
<table>
<tr><td><input type="radio" name="hide_clients_radio" value="1" onclick="drawL1Map(1);" checked="checked" /></td><td>collapse</td></tr>
<tr><td><input type="radio" name="hide_clients_radio" value="0" onclick="drawL1Map(0);"/></td><td>expand</td></tr>
<tr><td><input type="radio" name="radio_prod_links_mode" value="1" onclick="drawL1Map();" checked="checked" /></td><td>production</td></tr>
<tr><td><input type="radio" name="radio_prod_links_mode" value="0" onclick="drawL1Map();"/></td><td>OOB management</td></tr>
</table>
</td>-->
<td valign=top style="padding-top:6px">Links:</td>
</td>
<td width="16"></td><td width="20"><div class="div-vert-line-80"/></td>
<td valign=top style="padding-top:6px">Virtual chassis:</td>
<td valign="top">
<table>
<tr><td><input type="radio" name="radio_links_mode" value="0" onclick="drawL1Map(1, 1);" checked="checked" /></td><td>production</td></tr>
<tr><td><input type="radio" name="radio_links_mode" value="1" onclick="drawL1Map(1, 0);"/></td><td>management</td></tr>
<tr><td><input type="radio" name="radio_expand_vc_mode" value="0" onclick="drawL1Map();" checked="checked" /></td><td>collapse</td></tr>
<tr><td><input type="radio" name="radio_expand_vc_mode" value="1" onclick="drawL1Map();"/></td><td>expand</td></tr>
</table>
</td>
<td width="16"></td><td width="20"><div class="div-vert-line-80"/></td>
Expand Down Expand Up @@ -117,7 +118,7 @@
<text x="596" y="10" class="secondary_text">Standalone node:</text>
<text x="596" y="28" class="secondary_text"></text>
<image xlink:href="/img/switch.svg" width="32" height="32" x="600" y="20"></image>
<text x="640" y="40">dc2-core-sw01</text>
<text x="640" y="40">dc2-leaf-sw01</text>
</g>
</g>
</svg>
Expand All @@ -136,10 +137,11 @@
</div>

<footer>
<table width="100%">
<div style="height: 1px; background: #aaaaaa;"></div>
<table style="width: 100%; height: calc(100% - 1px);">
<tr>
<td style="padding: 10px; padding-left: 21px;" class="secondary_text">v0.3.1</td>
<td style="padding: 10px; padding-right: 21px; text-align: right;" class="secondary_text"><a href="https://github.com/den-it/ntmap/blob/master/docs/index.md">Docs</a></td>
<td style="padding-left: 21px;" class="secondary_text">v0.3.2</td>
<td style="padding-right: 21px; text-align: right;" class="secondary_text"><a href="https://github.com/den-it/ntmap/blob/master/docs/index.md">Docs</a></td>
</tr>
</table>
</footer>
Expand Down

0 comments on commit 3157c0b

Please sign in to comment.