mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Récupération de code
This commit is contained in:
parent
7e3e27be90
commit
d8f139c207
4 changed files with 287 additions and 29 deletions
|
@ -40,7 +40,8 @@ from __future__ import unicode_literals
|
|||
import itertools
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
from django.db.models.signals import pre_save, post_save, post_delete
|
||||
from django.utils.functional import cached_property
|
||||
from django.dispatch import receiver
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import IntegrityError
|
||||
|
@ -50,6 +51,11 @@ from reversion import revisions as reversion
|
|||
from machines.models import Machine, regen
|
||||
from re2o.mixins import AclMixin, RevMixin
|
||||
|
||||
from os.path import isfile
|
||||
from os import remove
|
||||
|
||||
|
||||
|
||||
|
||||
class Stack(AclMixin, RevMixin, models.Model):
|
||||
"""Un objet stack. Regrouppe des switchs en foreign key
|
||||
|
@ -103,6 +109,70 @@ class AccessPoint(AclMixin, Machine):
|
|||
("view_accesspoint", "Peut voir une borne"),
|
||||
)
|
||||
|
||||
def port(self):
|
||||
"""Return the queryset of ports for this device"""
|
||||
return Port.objects.filter(
|
||||
machine_interface__machine=self
|
||||
)
|
||||
|
||||
def switch(self):
|
||||
"""Return the switch where this is plugged"""
|
||||
return Switch.objects.filter(
|
||||
ports__machine_interface__machine=self
|
||||
)
|
||||
|
||||
def building(self):
|
||||
"""Return the building of the AP/Server (building of the switchs connected to...)"""
|
||||
return Building.objects.filter(
|
||||
switchbay__switch=self.switch()
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def short_name(self):
|
||||
return str(self.interface_set.first().domain.name)
|
||||
|
||||
@classmethod
|
||||
def all_ap_in(cls, building_instance):
|
||||
"""Get a building as argument, returns all ap of a building"""
|
||||
return cls.objects.filter(interface__port__switch__switchbay__building=building_instance)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.interface_set.first())
|
||||
|
||||
|
||||
class Server(Machine):
|
||||
"""Dummy class, to retrieve servers of a building, or get switch of a server"""
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
def port(self):
|
||||
"""Return the queryset of ports for this device"""
|
||||
return Port.objects.filter(
|
||||
machine_interface__machine=self
|
||||
)
|
||||
|
||||
def switch(self):
|
||||
"""Return the switch where this is plugged"""
|
||||
return Switch.objects.filter(
|
||||
ports__machine_interface__machine=self
|
||||
)
|
||||
|
||||
def building(self):
|
||||
"""Return the building of the AP/Server (building of the switchs connected to...)"""
|
||||
return Building.objects.filter(
|
||||
switchbay__switch=self.switch()
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def short_name(self):
|
||||
return str(self.interface_set.first().domain.name)
|
||||
|
||||
@classmethod
|
||||
def all_server_in(cls, building_instance):
|
||||
"""Get a building as argument, returns all server of a building"""
|
||||
return cls.objects.filter(interface__port__switch__switchbay__building=building_instance).exclude(accesspoint__isnull=False)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.interface_set.first())
|
||||
|
||||
|
@ -422,15 +492,47 @@ class Room(AclMixin, RevMixin, models.Model):
|
|||
def ap_post_save(**_kwargs):
|
||||
"""Regeneration des noms des bornes vers le controleur"""
|
||||
regen('unifi-ap-names')
|
||||
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_delete, sender=AccessPoint)
|
||||
def ap_post_delete(**_kwargs):
|
||||
"""Regeneration des noms des bornes vers le controleur"""
|
||||
regen('unifi-ap-names')
|
||||
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_delete, sender=Stack)
|
||||
def stack_post_delete(**_kwargs):
|
||||
"""Vide les id des switches membres d'une stack supprimée"""
|
||||
Switch.objects.filter(stack=None).update(stack_member_id=None)
|
||||
|
||||
@receiver(post_save, sender=Port)
|
||||
def port_post_save(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_delete, sender=Port)
|
||||
def port_post_delete(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_save, sender=ModelSwitch)
|
||||
def modelswitch_post_save(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_delete, sender=ModelSwitch)
|
||||
def modelswitch_post_delete(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_save, sender=Building)
|
||||
def building_post_save(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_delete, sender=Building)
|
||||
def building_post_delete(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_save, sender=Switch)
|
||||
def switch_post_save(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
||||
@receiver(post_delete, sender=Switch)
|
||||
def switch_post_delete(**_kwargs):
|
||||
regen("graph_topo")
|
||||
|
|
135
topologie/templates/topologie/graph_switch.dot
Normal file
135
topologie/templates/topologie/graph_switch.dot
Normal file
|
@ -0,0 +1,135 @@
|
|||
{% block graph_dot %}
|
||||
strict digraph {
|
||||
graph [label="TOPOLOGIE DU RÉSEAU", labelloc=t, fontsize=40];
|
||||
node [fontname=Helvetica fontsize=8 shape=plaintext];
|
||||
edge[arrowhead=none];
|
||||
|
||||
|
||||
{% block subgraphs %}
|
||||
{% for sub in subs %}
|
||||
subgraph cluster_{{ sub.bat_id }} {
|
||||
fontsize=15;
|
||||
label="Batiment {{ sub.bat_name }}";
|
||||
|
||||
{% if sub.bornes %}
|
||||
{% block bornes %}
|
||||
node [label=<
|
||||
<TABLE BGCOLOR="{{ colors.back}}" BORDER="0" CELLBORDER="0" CELLSPACING="0">
|
||||
<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>
|
||||
</TR>
|
||||
{% for borne in sub.bornes %}
|
||||
<TR>
|
||||
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BORDER="0">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ borne.name }}</FONT>
|
||||
</TD>
|
||||
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BORDER="0">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ borne.switch }}</FONT>
|
||||
</TD>
|
||||
<TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BORDER="0">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ borne.port }}</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
{% endfor %}
|
||||
</TABLE>
|
||||
>] {{sub.bat_name}}bornes;
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
||||
{% if sub.machines %}
|
||||
{% block machines %}
|
||||
node [label=<
|
||||
<TABLE BGCOLOR="{{ colors.back}}" BORDER="0" CELLBORDER="0" CELLSPACING="0">
|
||||
<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 %}
|
||||
</TABLE>
|
||||
>] {{sub.bat_name}}machines;
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% block switchs %}
|
||||
{% for switch in sub.switchs %}
|
||||
node [label=<
|
||||
<TABLE BGCOLOR="{{ colors.back }}" BORDER="0" CELLBORDER="0" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head }}">
|
||||
<FONT FACE="Helvetica Bold" COLOR="white">
|
||||
{{ switch.name }}
|
||||
</FONT></TD></TR>
|
||||
<TR><TD ALIGN="LEFT" BORDER="0">
|
||||
<FONT COLOR="{{ colors.texte }}" >Modèle</FONT>
|
||||
</TD>
|
||||
<TD ALIGN="LEFT">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ switch.model }}</FONT>
|
||||
</TD></TR>
|
||||
<TR><TD ALIGN="LEFT" BORDER="0">
|
||||
<FONT COLOR="{{ colors.texte }}" >Taille</FONT>
|
||||
</TD>
|
||||
<TD ALIGN="LEFT">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ switch.nombre }}</FONT>
|
||||
</TD></TR>
|
||||
{% block liens %}
|
||||
{% for port in switch.ports %}
|
||||
<TR><TD ALIGN="LEFT" BORDER="0">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ port.numero }}</FONT>
|
||||
</TD>
|
||||
<TD ALIGN="LEFT">
|
||||
<FONT COLOR="{{ colors.texte }}" >{{ port.related }}</FONT>
|
||||
</TD></TR>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</TABLE>
|
||||
>] "{{ switch.id }}" ;
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block isoles %}
|
||||
{% for switchs in alone %}
|
||||
"{{switchs.id}}" [label=<
|
||||
<TABLE BGCOLOR="{{ colors.back }}" BORDER="0" CELLBORDER="0" CELLSPACING="0">
|
||||
<TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="{{ colors.head }}">
|
||||
<FONT FACE="Helvetica Bold" COLOR="white">
|
||||
{{switchs.name}}
|
||||
</FONT></TD></TR>
|
||||
</TABLE>
|
||||
>]
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block links %}
|
||||
{% for link in links %}
|
||||
"{{ link.depart }}" -> "{{ link.arrive }}";
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
}
|
||||
{% endblock %}
|
|
@ -29,7 +29,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% block title %}Switchs{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<img id="zoom_01" src="/media/images/switchs.png" data-zoom-image="/media/images/switchs.png" width=100% />
|
||||
|
||||
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collImg" aria-expanded="false" aria-controls="collapse">
|
||||
Topologie des Switchs
|
||||
</button>
|
||||
|
||||
<a target="_blank" href="/media/images/switchs.png" class="btn btn-primary">
|
||||
<span class="fa fa-arrows-alt"></span>
|
||||
</a>
|
||||
|
||||
<div id="collImg">
|
||||
<img id="zoom_01" src="/media/images/switchs.png" href="/media/images/switchs.png" target="_blank" data-zoom-image="/media/images/switchs.png" width=100% />
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/static/js/jquery.ez-plus.js"></script>
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ from django.core.exceptions import ValidationError
|
|||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context, Template, loader
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
import pprint
|
||||
|
||||
|
@ -95,7 +97,13 @@ from .forms import (
|
|||
EditBuildingForm
|
||||
)
|
||||
|
||||
from subprocess import Popen,PIPE
|
||||
from subprocess import (
|
||||
Popen,
|
||||
PIPE
|
||||
)
|
||||
|
||||
from os.path import isfile
|
||||
from os import remove
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -124,6 +132,8 @@ def index(request):
|
|||
for service_link in Service_link.objects.filter(service__service_type='graph_topo'):
|
||||
service_link.done_regen()
|
||||
|
||||
if not isfile("/var/www/re2o/media/images/switchs.png"):
|
||||
make_machine_graph()
|
||||
return render(
|
||||
request,
|
||||
'topologie/index.html',
|
||||
|
@ -964,8 +974,8 @@ def make_machine_graph():
|
|||
}
|
||||
missing = list(Switch.objects.all())
|
||||
detected = []
|
||||
#Visit all buildings
|
||||
for building in Building.objects.all():
|
||||
for building in Building.objects.all(): # Visit all buildings
|
||||
|
||||
dico['subs'].append(
|
||||
{
|
||||
'bat_id': building.id,
|
||||
|
@ -1026,7 +1036,7 @@ def make_machine_graph():
|
|||
})
|
||||
|
||||
|
||||
dot_data=generate_image(dico)#generate the dot file
|
||||
dot_data=generate_dot(dico,'topologie/graph_switch.dot') # generate the dot file
|
||||
fichier = open(MEDIA_ROOT + "/images/switchs.dot","w", encoding='utf-8')
|
||||
fichier.write(dot_data)
|
||||
fichier.close()
|
||||
|
@ -1040,7 +1050,7 @@ def make_machine_graph():
|
|||
stdout=PIPE
|
||||
)
|
||||
|
||||
def generate_dot(data,template='topologie/graph_switch.dot'):
|
||||
def generate_dot(data,template):
|
||||
"""create the dot file
|
||||
:param data: dictionary passed to the template
|
||||
:param template: path to the dot template
|
||||
|
|
Loading…
Reference in a new issue