Commit d610ac6d authored by chirac's avatar chirac

Merge branch 'graph_topo' into 'master'

branche de création de graph

See merge request federez/re2o!164
parents 1ca1b28a c06d710d
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-05-21 19:13
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('machines', '0080_auto_20180502_2334'),
]
operations = [
migrations.AlterField(
model_name='extension',
name='soa',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.SOA'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-05-21 19:13
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('machines', '0081_auto_20180521_1413'),
('topologie', '0059_auto_20180415_2249'),
]
operations = [
migrations.CreateModel(
name='Server',
fields=[
],
options={
'proxy': True,
},
bases=('machines.machine',),
),
]
...@@ -40,7 +40,8 @@ from __future__ import unicode_literals ...@@ -40,7 +40,8 @@ from __future__ import unicode_literals
import itertools import itertools
from django.db import models 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.dispatch import receiver
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import IntegrityError from django.db import IntegrityError
...@@ -50,6 +51,11 @@ from reversion import revisions as reversion ...@@ -50,6 +51,11 @@ from reversion import revisions as reversion
from machines.models import Machine, regen from machines.models import Machine, regen
from re2o.mixins import AclMixin, RevMixin from re2o.mixins import AclMixin, RevMixin
from os.path import isfile
from os import remove
class Stack(AclMixin, RevMixin, models.Model): class Stack(AclMixin, RevMixin, models.Model):
"""Un objet stack. Regrouppe des switchs en foreign key """Un objet stack. Regrouppe des switchs en foreign key
...@@ -103,6 +109,70 @@ class AccessPoint(AclMixin, Machine): ...@@ -103,6 +109,70 @@ class AccessPoint(AclMixin, Machine):
("view_accesspoint", "Peut voir une borne"), ("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): def __str__(self):
return str(self.interface_set.first()) return str(self.interface_set.first())
...@@ -422,15 +492,47 @@ class Room(AclMixin, RevMixin, models.Model): ...@@ -422,15 +492,47 @@ class Room(AclMixin, RevMixin, models.Model):
def ap_post_save(**_kwargs): def ap_post_save(**_kwargs):
"""Regeneration des noms des bornes vers le controleur""" """Regeneration des noms des bornes vers le controleur"""
regen('unifi-ap-names') regen('unifi-ap-names')
regen("graph_topo")
@receiver(post_delete, sender=AccessPoint) @receiver(post_delete, sender=AccessPoint)
def ap_post_delete(**_kwargs): def ap_post_delete(**_kwargs):
"""Regeneration des noms des bornes vers le controleur""" """Regeneration des noms des bornes vers le controleur"""
regen('unifi-ap-names') regen('unifi-ap-names')
regen("graph_topo")
@receiver(post_delete, sender=Stack) @receiver(post_delete, sender=Stack)
def stack_post_delete(**_kwargs): def stack_post_delete(**_kwargs):
"""Vide les id des switches membres d'une stack supprimée""" """Vide les id des switches membres d'une stack supprimée"""
Switch.objects.filter(stack=None).update(stack_member_id=None) 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")
{% 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="Bâtiment {{ 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 %}
\ No newline at end of file
...@@ -29,18 +29,39 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -29,18 +29,39 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block title %}Switchs{% endblock %} {% block title %}Switchs{% endblock %}
{% block content %} {% block content %}
<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 type="text/javascript" src="/static/js/jquery.ez-plus.js"></script>
<script> <script>
$("#zoom_01").ezPlus({ function toggle_graph() {
scrollZoom: true, $("#collImg").collapse('toggle');
zoomType: 'inner',
cursor: 'crosshair' ezImg = $("#zoom_01").data("ezPlus");
}); if (ezImg) {
ezImg.destroy();
$("#zoom_01").removeData("ezPlus");
} else {
$("#zoom_01").ezPlus({
scrollZoom: true,
zoomType: 'inner',
cursor: 'crosshair'
});
}
}
</script> </script>
<button class="btn btn-primary" type="button" onclick="toggle_graph()">
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" class="collapse" aria-expanded="false">
<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>
<h2>Switchs</h2> <h2>Switchs</h2>
{% can_create Switch %} {% 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> <a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-switch' %}"><i class="fa fa-plus"></i> Ajouter un switch</a>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment