8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

ajout des serveurs sur le graph

This commit is contained in:
grisel-davy 2018-04-25 20:28:56 +02:00
parent 9f153c49d8
commit 4f4d10b799
2 changed files with 46 additions and 39 deletions

View file

@ -1,28 +1,27 @@
{% block graph_dot %}
digraph Topologie {
node [
fontname=Helvetica
fontsize=8
shape=plaintext]
edge[arrowhead=odot,arrowtail=dot]
digraph {
graph [label="TOPOLOGIE DU RÉSEAU", labelloc=t, fontsize=40];
node [fontname=Helvetica fontsize=8 shape=plaintext];
edge[arrowhead=odot,arrowtail=dot];
{% block subgraphs %}
{% for sub in subs %}
subgraph cluster_{{ sub.bat_id }} {
fontsize=15;
label="Batiment {{ sub.bat_name }}";
{% if sub.bornes %}
node [label=<
<TABLE BGCOLOR="{{ colors.back}}" BORDER="1" COLOR="#021f87" CELLBORDER="0" CELLSPACING="0">
<TH>
<TR>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head_bornes }}">
<FONT FACE="Helvetica Bold" COLOR="white">Borne</FONT></TD>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head_bornes }}">
<FONT FACE="Helvetica Bold" COLOR="white">Switch</FONT></TD>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head_bornes }}">
<FONT FACE="Helvetica Bold" COLOR="white">Port</FONT></TD>
</TH>
</TR>
{% block bornes %}
{% for borne in sub.bornes %}
@ -40,6 +39,31 @@ node [label=<
{% endfor %}
{% endblock %}
{% if sub.machines %}
<TR>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head_server }}">
<FONT FACE="Helvetica Bold" COLOR="white">Machine</FONT></TD>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head_server }}">
<FONT FACE="Helvetica Bold" COLOR="white">Switch</FONT></TD>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head_server }}">
<FONT FACE="Helvetica Bold" COLOR="white">Port</FONT></TD>
</TR>
{% for machine in sub.machines %}
<TR>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BORDER="0">
<FONT COLOR="{{ colors.texte }}" >{{ machine.name }}</FONT>
</TD>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BORDER="0">
<FONT COLOR="{{ colors.texte }}" >{{ machine.switch }}</FONT>
</TD>
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BORDER="0">
<FONT COLOR="{{ colors.texte }}" >{{ machine.port }}</FONT>
</TD>
</TR>
{% endfor %}
{% endif %}
</TABLE>
>] {{sub.bat_name}}bornes;
{% endif %}

View file

@ -75,7 +75,8 @@ from .models import (
ConstructorSwitch,
AccessPoint,
SwitchBay,
Building
Building,
Server
)
from .forms import (
EditPortForm,
@ -116,6 +117,9 @@ def index(request):
)
pagination_number = GeneralOption.get_cached_value('pagination_number')
switch_list = re2o_paginator(request, switch_list, pagination_number)
# make_machine_graph()
return render(
request,
'topologie/index.html',
@ -944,45 +948,36 @@ def make_machine_graph():
"""
Crée le fichier dot et l'image du graph des Switchs
"""
dico={'subs':[],'links':[],'alone':[],'bornes':[]}
dico={'subs':[],'links':[],'alone':[],'colors':{'head':"#7f0505",'back':"#b5adad",'texte':"#563d01",'border_bornes':"#02078e",'head_bornes':"#25771c",'head_server':"#1c3777"}}
missing=[]
detected=[]
for sw in Switch.objects.all():
if(sw not in detected):
missing.append(sw)
for building in Building.objects.all():#Parcour tous les batiments
dico['subs'].append({'bat_id':building.id,'bat_name':building,'switchs':[],'bornes':[]})
dico['subs'].append({'bat_id':building.id,'bat_name':building,'switchs':[],'bornes':[],'machines':[]})
for switch in Switch.objects.filter(switchbay__building=building):#Parcour tous les switchs de ce batiment
dico['subs'][-1]['switchs'].append({'name':switch.main_interface().domain.name,'nombre':switch.number,'model':switch.model,'id':switch.id,'batiment':building,'ports':[]})
for p in switch.ports.all().filter(related__isnull=False):#Parcour tout les ports liés de ce switch
dico['subs'][-1]['switchs'][-1]['ports'].append({'numero':p.port,'related':p.related.switch.main_interface().domain.name})
for ap in AccessPoint.all_ap_in(building):
dico['subs'][-1]['bornes'].append({'name':ap.short_name,'id':ap.id})
dico['links'].append({'depart':ap.switch()[0].id,'arrive':ap.id})
dico['subs'][-1]['bornes'].append({'name':ap.short_name,'switch':ap.switch()[0].main_interface().domain.name,'port':ap.switch()[0].ports.filter(machine_interface__machine=ap)[0].port})
for server in Server.all_server_in(building):
dico['subs'][-1]['machines'].append({'name':server.short_name,'switch':server.switch()[0].main_interface().domain.name,'port':Port.objects.filter(machine_interface__machine=server)[0].port})
# for ma in Allmachines_in(building):
# dico['subs'][-1]['machines'].append({'name':ma.short_name,'id':ma.id,'switch':ma.switch()[0].main_interface().domain.name,'port':ma.switch()[0].ports.filter(machine_interface__machine=ap)[0].port})
for ap in AccessPoint.objects.all():
dico['bornes'].append({'name':str(ap)})
while(missing!=[]):#Tant que la liste des oubliés n'est pas vide i.e on les a pas tous passer
links,new_detected=recursive_switchs(missing[0].ports.all().filter(related=None).first(),None,[missing[0]])
for link in links:
dico['links'].append(link)
#on recrée la liste des oubliés et des detectés
missing=[i for i in missing if i not in new_detected]
missing=[i for i in missing if i not in new_detected]#on recrée la liste des oubliés et des detectés
detected+=new_detected
for switch in Switch.objects.all().filter(switchbay__isnull=True).exclude(ports__related__isnull=False):#Tous ceux qui ne sont ni connectés ni dans un batiment
dico['alone'].append({'id':switch.id,'name':switch.main_interface().domain.name})
dot_data=generate_image(dico)
fichier = open("media/images/switchs.dot","w")
fichier.write(dot_data)
@ -991,18 +986,13 @@ def make_machine_graph():
image = Popen(["dot", "-Tpng", "-o", "media/images/switchs.png"], stdin=unflatten.stdout, stdout=PIPE)
def generate_image(data,template='topologie/graph_switch.dot'):
t = loader.get_template(template)
if not isinstance(t, Template) and not (hasattr(t, 'template') and isinstance(t.template, Template)):
raise Exception("Le template par défaut de Django n'est pas utilisé."
"Cela peut mener à des erreurs de rendu."
"Vérifiez les paramètres")
c = Context(data).flatten()
dot = t.render(c)
return(dot)
def recursive_switchs(port_start, switch_before, detected):
@ -1010,23 +1000,16 @@ def recursive_switchs(port_start, switch_before, detected):
Parcour récursivement le switchs auquel appartient port_start pour trouver les ports suivants liés
"""
links_return=[]#Liste de dictionaires qui stockes les nouveaux liens détéctés
l_ports=port_start.switch.ports.filter(related__isnull=False)#Liste des ports dont le related est non null
for port in l_ports:
if port.related.switch!=switch_before and port.related.switch!=port.switch:#Pas le switch dont on vient, pas le switch actuel
detected.append(port_start.switch)
detected.append(port.related.switch)
links={'depart':port_start.switch.id,'arrive':port.related.switch.id}
links_down, detected = recursive_switchs(port.related, port_start.switch, detected)
links_return.append(links)
for link in links_down:
if(link!=[]):
links_return.append(link)
return (links_return, detected)