Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
Re2o
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levy--Falk Hugo
Re2o
Commits
0dc5d562
Commit
0dc5d562
authored
Apr 13, 2018
by
grisel-davy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Création et affichage du graph des switchs
parent
badad163
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2047 additions
and
3 deletions
+2047
-3
jquery.ez-plus.js
static/js/jquery.ez-plus.js
+1929
-0
aff_switch.html
topologie/templates/topologie/aff_switch.html
+4
-2
index.html
topologie/templates/topologie/index.html
+15
-1
views.py
topologie/views.py
+99
-0
No files found.
static/js/jquery.ez-plus.js
0 → 100644
View file @
0dc5d562
This diff is collapsed.
Click to expand it.
topologie/templates/topologie/aff_switch.html
View file @
0dc5d562
...
@@ -24,11 +24,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
...
@@ -24,11 +24,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %}
{% load acl %}
<div
class=
"table-responsive"
>
{% if switch_list.paginator %}
{% if switch_list.paginator %}
{% include "pagination.html" with list=switch_list %}
{% include "pagination.html" with list=switch_list %}
{% endif %}
{% endif %}
<div
class=
"table-responsive"
>
<table
class=
"table table-striped"
>
<table
class=
"table table-striped"
>
<thead>
<thead>
<tr>
<tr>
...
@@ -72,8 +73,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
...
@@ -72,8 +73,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</tr>
</tr>
{% endfor %}
{% endfor %}
</table>
</table>
</div>
{% if switch_list.paginator %}
{% if switch_list.paginator %}
{% include "pagination.html" with list=switch_list %}
{% include "pagination.html" with list=switch_list %}
{% endif %}
{% endif %}
</div>
topologie/templates/topologie/index.html
View file @
0dc5d562
...
@@ -29,7 +29,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
...
@@ -29,7 +29,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block title %}Switchs{% endblock %}
{% block title %}Switchs{% endblock %}
{% block content %}
{% 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 %}
{% 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>
<hr>
<hr>
...
@@ -38,4 +50,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
...
@@ -38,4 +50,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<br
/>
<br
/>
<br
/>
<br
/>
<br
/>
<br
/>
{% endblock %}
{% endblock %}
topologie/views.py
View file @
0dc5d562
...
@@ -43,6 +43,7 @@ from django.db import IntegrityError
...
@@ -43,6 +43,7 @@ from django.db import IntegrityError
from
django.db
import
transaction
from
django.db
import
transaction
from
django.db.models
import
ProtectedError
,
Prefetch
from
django.db.models
import
ProtectedError
,
Prefetch
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.contrib.staticfiles.storage
import
staticfiles_storage
from
topologie.models
import
(
from
topologie.models
import
(
Switch
,
Switch
,
...
@@ -88,6 +89,8 @@ from machines.views import generate_ipv4_mbf_param
...
@@ -88,6 +89,8 @@ from machines.views import generate_ipv4_mbf_param
from
machines.models
import
Interface
from
machines.models
import
Interface
from
preferences.models
import
AssoOption
,
GeneralOption
from
preferences.models
import
AssoOption
,
GeneralOption
from
subprocess
import
Popen
,
PIPE
@
login_required
@
login_required
@
can_view_all
(
Switch
)
@
can_view_all
(
Switch
)
...
@@ -785,3 +788,99 @@ def del_constructor_switch(request, constructor_switch, constructorswitchid):
...
@@ -785,3 +788,99 @@ def del_constructor_switch(request, constructor_switch, constructorswitchid):
'objet'
:
constructor_switch
,
'objet'
:
constructor_switch
,
'objet_name'
:
'Constructeur de switch'
'objet_name'
:
'Constructeur de switch'
},
'topologie/delete.html'
,
request
)
},
'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
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment