mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +00:00
Création et affichage du graph des switchs
This commit is contained in:
parent
badad16376
commit
0dc5d56250
4 changed files with 2047 additions and 3 deletions
1929
static/js/jquery.ez-plus.js
Normal file
1929
static/js/jquery.ez-plus.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -24,11 +24,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
{% load acl %}
|
||||
|
||||
<div class="table-responsive">
|
||||
{% if switch_list.paginator %}
|
||||
{% include "pagination.html" with list=switch_list %}
|
||||
{% endif %}
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -72,8 +73,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if switch_list.paginator %}
|
||||
{% include "pagination.html" with list=switch_list %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
|
|
@ -29,7 +29,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% block title %}Switchs{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Switchs</h2>
|
||||
<img id="zoom_01" src="/media/images/switchs.png" data-zoom-image="/media/images/switchs.png" width=100% />
|
||||
|
||||
<script type="text/javascript" src="/static/js/jquery.ez-plus.js"></script>
|
||||
|
||||
<script>
|
||||
$("#zoom_01").ezPlus({
|
||||
scrollZoom: true,
|
||||
zoomType: 'inner',
|
||||
cursor: 'crosshair'
|
||||
});
|
||||
</script>
|
||||
|
||||
<h2>Switchs</h2>
|
||||
{% can_create Switch %}
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-switch' %}"><i class="fa fa-plus"></i> Ajouter un switch</a>
|
||||
<hr>
|
||||
|
@ -38,4 +50,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -43,6 +43,7 @@ from django.db import IntegrityError
|
|||
from django.db import transaction
|
||||
from django.db.models import ProtectedError, Prefetch
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
|
||||
from topologie.models import (
|
||||
Switch,
|
||||
|
@ -88,6 +89,8 @@ from machines.views import generate_ipv4_mbf_param
|
|||
from machines.models import Interface
|
||||
from preferences.models import AssoOption, GeneralOption
|
||||
|
||||
from subprocess import Popen,PIPE
|
||||
|
||||
|
||||
@login_required
|
||||
@can_view_all(Switch)
|
||||
|
@ -785,3 +788,99 @@ def del_constructor_switch(request, constructor_switch, constructorswitchid):
|
|||
'objet': constructor_switch,
|
||||
'objet_name': 'Constructeur de switch'
|
||||
}, 'topologie/delete.html', request)
|
||||
|
||||
|
||||
def make_machine_graph():
|
||||
"""
|
||||
Crée le fichier dot et l'image du graph des Switchs
|
||||
"""
|
||||
#Syntaxe DOT temporaire, A mettre dans un template:
|
||||
lignes=['''digraph Switchs {
|
||||
node [
|
||||
fontname=Helvetica
|
||||
fontsize=8
|
||||
shape=plaintext]
|
||||
edge[arrowhead=odot,arrowtail=dot]''']
|
||||
node_fixe='''node [label=<
|
||||
<TABLE BGCOLOR="palegoldenrod" BORDER="0" CELLBORDER="0" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="olivedrab4">
|
||||
<FONT FACE="Helvetica Bold" COLOR="white">
|
||||
{}
|
||||
</FONT></TD></TR>
|
||||
<TR><TD ALIGN="LEFT" BORDER="0">
|
||||
<FONT COLOR="#7B7B7B" >{}</FONT>
|
||||
</TD>
|
||||
<TD ALIGN="LEFT">
|
||||
<FONT COLOR="#7B7B7B" >{}</FONT>
|
||||
</TD></TR>
|
||||
<TR><TD ALIGN="LEFT" BORDER="0">
|
||||
<FONT COLOR="#7B7B7B" >{}</FONT>
|
||||
</TD>
|
||||
<TD ALIGN="LEFT">
|
||||
<FONT>{}</FONT>
|
||||
</TD></TR>'''
|
||||
node_ports='''<TR><TD ALIGN="LEFT" BORDER="0">
|
||||
<FONT COLOR="#7B7B7B" >{}</FONT>
|
||||
</TD>
|
||||
<TD ALIGN="LEFT">
|
||||
<FONT>{}</FONT>
|
||||
</TD></TR>'''
|
||||
cluster='''subgraph cluster_{} {{
|
||||
color=blue;
|
||||
label="Batiment {}";'''
|
||||
end_table='''</TABLE>
|
||||
>] \"{}_{}\" ;'''
|
||||
switch_alone='''{} [label=<
|
||||
<TABLE BGCOLOR="palegoldenrod" BORDER="0" CELLBORDER="0" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="olivedrab4">
|
||||
<FONT FACE="Helvetica Bold" COLOR="white">
|
||||
{}
|
||||
</FONT></TD></TR>
|
||||
</TABLE>
|
||||
>]'''
|
||||
missing=[]
|
||||
detected=[]
|
||||
for sw in Switch.objects.all():
|
||||
if(sw not in detected):
|
||||
missing.append(sw)
|
||||
for building in Building.objects.all():
|
||||
lignes.append(cluster.format(len(lignes),building))
|
||||
for switch in Switch.objects.filter(switchbay__building=building):
|
||||
lignes.append(node_fixe.format(switch.main_interface().domain.name,"Modèle",switch.model,"Nombre de ports",switch.number))
|
||||
for p in switch.ports.all().filter(related__isnull=False):
|
||||
lignes.append(node_ports.format(p.port,p.related.switch.main_interface().domain.name))
|
||||
lignes.append(end_table.format(building.id,switch.id))
|
||||
lignes.append("}")
|
||||
while(missing!=[]):
|
||||
lignes,new_detected=recursive_switchs(missing[0].ports.all().filter(related=None).first(),None,lignes,[missing[0]])
|
||||
missing=[i for i in missing if i not in new_detected]
|
||||
detected+=new_detected
|
||||
for switch in Switch.objects.all().filter(switchbay__isnull=True).exclude(ports__related__isnull=False):
|
||||
lignes.append(switch_alone.format(switch.id,switch.main_interface().domain.name))
|
||||
lignes.append("}")
|
||||
fichier = open("media/images/switchs.dot","w")
|
||||
for ligne in lignes:
|
||||
fichier.write(ligne+"\n")
|
||||
fichier.close()
|
||||
unflatten = Popen(["unflatten","-l", "3", "media/images/switchs.dot"], stdout=PIPE)
|
||||
image = Popen(["dot", "-Tpng", "-o", "media/images/switchs.png"], stdin=unflatten.stdout, stdout=PIPE)
|
||||
|
||||
|
||||
def recursive_switchs(port_start, switch_before, lignes,detected):
|
||||
"""
|
||||
Parcour récursivement le switchs auquel appartient port_start pour trouver les ports suivants liés
|
||||
"""
|
||||
l_ports=port_start.switch.ports.filter(related__isnull=False)
|
||||
for port in l_ports:
|
||||
if port.related.switch!=switch_before and port.related.switch!=port.switch:
|
||||
links=[]
|
||||
for sw in [switch for switch in [port_start.switch,port.related.switch]]:
|
||||
if(sw not in detected):
|
||||
detected.append(sw)
|
||||
if(sw.switchbay.building):
|
||||
links.append("\"{}_{}\"".format(sw.switchbay.building.id,sw.id))
|
||||
else:
|
||||
links.append("\"{}\"".format(sw.id))
|
||||
lignes.append(links[0]+" -> "+links[1])
|
||||
lignes, detected = recursive_switchs(port.related, port_start.switch, lignes, detected)
|
||||
return (lignes, detected)
|
Loading…
Reference in a new issue