2017-01-15 23:01:18 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
2019-09-29 14:02:28 +00:00
|
|
|
# Copyright © 2017 Lara Kermarec
|
2017-01-15 23:01:18 +00:00
|
|
|
# Copyright © 2017 Augustin Lemesle
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2017-10-13 23:43:01 +00:00
|
|
|
"""
|
2020-04-29 13:00:47 +00:00
|
|
|
Views for the 'topologie' app of re2o.
|
|
|
|
|
|
|
|
They are used to create, edit and delete:
|
|
|
|
* a port (add_port, edit_port, del_port)
|
|
|
|
* a switch: the views call forms for switches but also machines (domain,
|
|
|
|
interface and machine), send and save them at the same time.
|
|
|
|
TODO rationalise, enforce the creation of machines (interfaces, domains
|
|
|
|
etc.) in models and forms from 'topologie'
|
|
|
|
* a room (new_room, edit_room, del_room)
|
|
|
|
* a stack
|
|
|
|
* histories of all objects mentioned.
|
2017-10-13 23:43:01 +00:00
|
|
|
"""
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-10-26 15:58:41 +00:00
|
|
|
from django.urls import reverse
|
2016-07-06 19:50:15 +00:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.contrib import messages
|
2018-04-14 22:06:29 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2016-07-06 21:29:31 +00:00
|
|
|
from django.db import IntegrityError
|
2018-03-26 23:26:17 +00:00
|
|
|
from django.db.models import ProtectedError, Prefetch
|
2017-10-26 21:29:26 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2018-05-15 18:42:00 +00:00
|
|
|
from django.template import Context, Template, loader
|
2018-05-26 22:36:25 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2018-05-15 18:42:00 +00:00
|
|
|
|
2018-05-21 20:05:31 +00:00
|
|
|
import tempfile
|
2016-07-06 19:50:15 +00:00
|
|
|
|
2018-04-14 22:06:29 +00:00
|
|
|
from users.views import form
|
2019-11-04 16:55:03 +00:00
|
|
|
from re2o.base import re2o_paginator, SortTable
|
|
|
|
from re2o.acl import can_create, can_edit, can_delete, can_view, can_view_all
|
2018-05-15 18:42:00 +00:00
|
|
|
from re2o.settings import MEDIA_ROOT
|
2018-04-14 22:06:29 +00:00
|
|
|
from machines.forms import (
|
|
|
|
DomainForm,
|
|
|
|
EditInterfaceForm,
|
2018-07-08 02:08:01 +00:00
|
|
|
AddInterfaceForm,
|
2019-11-04 16:55:03 +00:00
|
|
|
EditOptionVlanForm,
|
2018-04-14 22:06:29 +00:00
|
|
|
)
|
|
|
|
from machines.views import generate_ipv4_mbf_param
|
2019-11-04 16:55:03 +00:00
|
|
|
from machines.models import Interface, Service_link, Vlan
|
2018-04-14 22:06:29 +00:00
|
|
|
from preferences.models import AssoOption, GeneralOption
|
|
|
|
|
|
|
|
from .models import (
|
2017-10-26 03:07:11 +00:00
|
|
|
Switch,
|
|
|
|
Port,
|
|
|
|
Room,
|
|
|
|
Stack,
|
|
|
|
ModelSwitch,
|
2018-03-23 23:50:11 +00:00
|
|
|
ConstructorSwitch,
|
2018-04-07 18:45:29 +00:00
|
|
|
AccessPoint,
|
|
|
|
SwitchBay,
|
2018-05-15 18:42:00 +00:00
|
|
|
Building,
|
2019-02-18 20:11:51 +00:00
|
|
|
Dormitory,
|
2018-05-19 19:20:55 +00:00
|
|
|
Server,
|
2018-05-26 22:36:25 +00:00
|
|
|
PortProfile,
|
2018-12-30 16:04:21 +00:00
|
|
|
ModuleSwitch,
|
2018-12-30 17:20:06 +00:00
|
|
|
ModuleOnSwitch,
|
2017-10-26 03:07:11 +00:00
|
|
|
)
|
2018-04-14 22:06:29 +00:00
|
|
|
from .forms import (
|
|
|
|
EditPortForm,
|
|
|
|
NewSwitchForm,
|
|
|
|
EditSwitchForm,
|
2017-10-26 03:07:11 +00:00
|
|
|
AddPortForm,
|
|
|
|
EditRoomForm,
|
|
|
|
StackForm,
|
2017-12-28 11:39:25 +00:00
|
|
|
EditModelSwitchForm,
|
2017-10-26 19:38:55 +00:00
|
|
|
EditConstructorSwitchForm,
|
2018-03-23 23:50:11 +00:00
|
|
|
CreatePortsForm,
|
2018-03-25 22:08:24 +00:00
|
|
|
AddAccessPointForm,
|
2018-04-07 18:45:29 +00:00
|
|
|
EditAccessPointForm,
|
|
|
|
EditSwitchBayForm,
|
2018-05-26 22:36:25 +00:00
|
|
|
EditBuildingForm,
|
2019-02-18 20:11:51 +00:00
|
|
|
EditDormitoryForm,
|
2018-05-26 22:36:25 +00:00
|
|
|
EditPortProfileForm,
|
2018-12-30 17:20:06 +00:00
|
|
|
EditModuleForm,
|
|
|
|
EditSwitchModuleForm,
|
2017-10-26 03:07:11 +00:00
|
|
|
)
|
2016-10-27 17:45:31 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
from subprocess import Popen, PIPE
|
2018-05-21 19:13:44 +00:00
|
|
|
|
2018-07-11 17:37:22 +00:00
|
|
|
from os.path import isfile
|
2018-04-13 18:31:51 +00:00
|
|
|
|
2016-07-27 01:36:28 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 22:07:05 +00:00
|
|
|
@can_view_all(Switch)
|
2016-07-06 19:50:15 +00:00
|
|
|
def index(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display all switches."""
|
2019-11-04 16:55:03 +00:00
|
|
|
switch_list = (
|
|
|
|
Switch.objects.prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"interface_set",
|
|
|
|
queryset=(
|
|
|
|
Interface.objects.select_related(
|
|
|
|
"ipv4__ip_type__extension"
|
|
|
|
).select_related("domain__extension")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.select_related("stack")
|
|
|
|
.select_related("switchbay__building__dormitory")
|
|
|
|
.select_related("model__constructor")
|
|
|
|
)
|
2017-10-22 00:33:44 +00:00
|
|
|
switch_list = SortTable.sort(
|
|
|
|
switch_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX,
|
2017-10-22 00:33:44 +00:00
|
|
|
)
|
2018-05-26 22:36:25 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
2018-04-03 03:00:06 +00:00
|
|
|
switch_list = re2o_paginator(request, switch_list, pagination_number)
|
2018-05-15 18:42:00 +00:00
|
|
|
|
2018-07-11 17:37:22 +00:00
|
|
|
if any(
|
|
|
|
service_link.need_regen
|
|
|
|
for service_link in Service_link.objects.filter(
|
2019-11-04 16:55:03 +00:00
|
|
|
service__service_type="graph_topo"
|
|
|
|
)
|
2018-07-11 17:37:22 +00:00
|
|
|
):
|
2018-05-15 18:42:00 +00:00
|
|
|
make_machine_graph()
|
2018-07-11 17:37:22 +00:00
|
|
|
for service_link in Service_link.objects.filter(
|
2019-11-04 16:55:03 +00:00
|
|
|
service__service_type="graph_topo"
|
|
|
|
):
|
2018-05-15 18:42:00 +00:00
|
|
|
service_link.done_regen()
|
|
|
|
|
2018-05-21 19:13:44 +00:00
|
|
|
if not isfile("/var/www/re2o/media/images/switchs.png"):
|
|
|
|
make_machine_graph()
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "topologie/index.html", {"switch_list": switch_list})
|
2018-06-27 20:28:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_view_all(PortProfile)
|
|
|
|
def index_port_profile(request):
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
|
|
|
port_profile_list = (
|
|
|
|
PortProfile.objects.all()
|
|
|
|
.select_related("vlan_untagged")
|
|
|
|
.select_related("on_dormitory")
|
|
|
|
.prefetch_related("vlan_tagged")
|
|
|
|
)
|
|
|
|
port_profile_list = re2o_paginator(request, port_profile_list, pagination_number)
|
|
|
|
vlan_list = Vlan.objects.all().order_by("vlan_id")
|
2018-06-27 20:28:54 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/index_portprofile.html",
|
|
|
|
{"port_profile_list": port_profile_list, "vlan_list": vlan_list},
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-06 19:50:15 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 22:07:05 +00:00
|
|
|
@can_view_all(Port)
|
|
|
|
@can_view(Switch)
|
2018-03-28 18:32:03 +00:00
|
|
|
def index_port(request, switch, switchid):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display all ports related to the given switch."""
|
2019-11-04 16:55:03 +00:00
|
|
|
port_list = (
|
|
|
|
Port.objects.filter(switch=switch)
|
|
|
|
.select_related("room__building__dormitory")
|
|
|
|
.select_related("machine_interface__domain__extension")
|
|
|
|
.select_related("machine_interface__machine__user")
|
|
|
|
.select_related("machine_interface__machine__accesspoint")
|
|
|
|
.select_related("related__switch__switchbay__building__dormitory")
|
|
|
|
.prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"related__switch__interface_set",
|
|
|
|
queryset=(Interface.objects.select_related("domain__extension")),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.select_related("switch__switchbay__building__dormitory")
|
|
|
|
.select_related("switch__model__constructor")
|
|
|
|
)
|
2017-10-22 00:33:44 +00:00
|
|
|
port_list = SortTable.sort(
|
|
|
|
port_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_PORT,
|
2017-10-22 00:33:44 +00:00
|
|
|
)
|
2018-04-14 00:20:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/index_p.html",
|
|
|
|
{"port_list": port_list, "id_switch": switchid, "switch": switch},
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-06 21:29:31 +00:00
|
|
|
|
2016-07-19 00:30:52 +00:00
|
|
|
@login_required
|
2017-12-27 22:07:05 +00:00
|
|
|
@can_view_all(Room)
|
2016-07-19 00:30:52 +00:00
|
|
|
def index_room(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display all rooms."""
|
2019-11-04 16:55:03 +00:00
|
|
|
room_list = Room.objects.select_related("building__dormitory")
|
2017-10-22 00:33:44 +00:00
|
|
|
room_list = SortTable.sort(
|
|
|
|
room_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_ROOM,
|
2017-10-22 00:33:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
2018-04-03 03:00:06 +00:00
|
|
|
room_list = re2o_paginator(request, room_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "topologie/index_room.html", {"room_list": room_list})
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-19 00:30:52 +00:00
|
|
|
|
2018-03-23 23:50:11 +00:00
|
|
|
@login_required
|
2018-03-25 22:08:24 +00:00
|
|
|
@can_view_all(AccessPoint)
|
|
|
|
def index_ap(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display all APs."""
|
2019-11-04 16:55:03 +00:00
|
|
|
ap_list = AccessPoint.objects.prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"interface_set",
|
|
|
|
queryset=(
|
|
|
|
Interface.objects.select_related(
|
|
|
|
"ipv4__ip_type__extension"
|
|
|
|
).select_related("domain__extension")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
).distinct()
|
2018-03-25 22:08:24 +00:00
|
|
|
ap_list = SortTable.sort(
|
|
|
|
ap_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_BORNE,
|
2018-03-23 23:50:11 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
2018-04-03 03:00:06 +00:00
|
|
|
ap_list = re2o_paginator(request, ap_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "topologie/index_ap.html", {"ap_list": ap_list})
|
2018-03-23 23:50:11 +00:00
|
|
|
|
|
|
|
|
2017-08-17 22:17:56 +00:00
|
|
|
@login_required
|
2019-02-18 20:11:51 +00:00
|
|
|
@can_view_all(Stack, Building, Dormitory, SwitchBay)
|
2018-04-10 12:11:48 +00:00
|
|
|
def index_physical_grouping(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display the list of stacks (display all switches)."""
|
2019-11-04 16:55:03 +00:00
|
|
|
stack_list = Stack.objects.prefetch_related(
|
|
|
|
"switch_set__interface_set__domain__extension"
|
|
|
|
)
|
|
|
|
building_list = Building.objects.all().select_related("dormitory")
|
|
|
|
dormitory_list = Dormitory.objects.all().prefetch_related("building_set")
|
|
|
|
switch_bay_list = SwitchBay.objects.select_related(
|
|
|
|
"building__dormitory"
|
|
|
|
).prefetch_related("switch_set__interface_set__domain")
|
2017-10-22 00:33:44 +00:00
|
|
|
stack_list = SortTable.sort(
|
|
|
|
stack_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_STACK,
|
2017-10-22 00:33:44 +00:00
|
|
|
)
|
2018-04-10 11:56:17 +00:00
|
|
|
building_list = SortTable.sort(
|
|
|
|
building_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_BUILDING,
|
2018-04-10 11:56:17 +00:00
|
|
|
)
|
2019-02-18 20:11:51 +00:00
|
|
|
dormitory_list = SortTable.sort(
|
|
|
|
dormitory_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_DORMITORY,
|
2019-02-18 20:11:51 +00:00
|
|
|
)
|
2018-04-10 11:56:17 +00:00
|
|
|
switch_bay_list = SortTable.sort(
|
|
|
|
switch_bay_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_SWITCH_BAY,
|
2018-04-10 11:56:17 +00:00
|
|
|
)
|
2018-04-14 00:20:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/index_physical_grouping.html",
|
2018-04-14 00:20:44 +00:00
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"stack_list": stack_list,
|
|
|
|
"switch_bay_list": switch_bay_list,
|
|
|
|
"building_list": building_list,
|
|
|
|
"dormitory_list": dormitory_list,
|
|
|
|
},
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-08-17 22:17:56 +00:00
|
|
|
|
|
|
|
|
2017-10-26 03:07:11 +00:00
|
|
|
@login_required
|
2018-05-07 17:43:53 +00:00
|
|
|
@can_view_all(ModelSwitch, ConstructorSwitch)
|
2017-10-26 03:07:11 +00:00
|
|
|
def index_model_switch(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display all switch models."""
|
2019-11-04 16:55:03 +00:00
|
|
|
model_switch_list = ModelSwitch.objects.select_related(
|
|
|
|
"constructor"
|
|
|
|
).prefetch_related("switch_set__interface_set__domain")
|
2017-10-26 03:07:11 +00:00
|
|
|
constructor_switch_list = ConstructorSwitch.objects
|
|
|
|
model_switch_list = SortTable.sort(
|
|
|
|
model_switch_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_MODEL_SWITCH,
|
2017-10-26 03:07:11 +00:00
|
|
|
)
|
|
|
|
constructor_switch_list = SortTable.sort(
|
|
|
|
constructor_switch_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH,
|
2017-10-26 03:07:11 +00:00
|
|
|
)
|
2018-04-14 00:20:44 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/index_model_switch.html",
|
2018-04-14 00:20:44 +00:00
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"model_switch_list": model_switch_list,
|
|
|
|
"constructor_switch_list": constructor_switch_list,
|
|
|
|
},
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
2018-12-30 16:04:21 +00:00
|
|
|
@login_required
|
|
|
|
@can_view_all(ModuleSwitch)
|
|
|
|
def index_module(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to display all switch modules."""
|
2018-12-30 16:04:21 +00:00
|
|
|
module_list = ModuleSwitch.objects.all()
|
2019-11-04 16:55:03 +00:00
|
|
|
modular_switchs = (
|
|
|
|
Switch.objects.filter(model__is_modular=True)
|
|
|
|
.select_related("model")
|
|
|
|
.prefetch_related("moduleonswitch_set__module")
|
|
|
|
)
|
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
2018-12-30 16:04:21 +00:00
|
|
|
module_list = re2o_paginator(request, module_list, pagination_number)
|
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/index_module.html",
|
|
|
|
{"module_list": module_list, "modular_switchs": modular_switchs},
|
2018-12-30 16:04:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-07-08 02:08:01 +00:00
|
|
|
@login_required
|
|
|
|
@can_edit(Vlan)
|
|
|
|
def edit_vlanoptions(request, vlan_instance, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit options for switch of VLAN object."""
|
2018-07-08 02:08:01 +00:00
|
|
|
vlan = EditOptionVlanForm(request.POST or None, instance=vlan_instance)
|
|
|
|
if vlan.is_valid():
|
|
|
|
if vlan.changed_data:
|
|
|
|
vlan.save()
|
2019-01-08 23:40:48 +00:00
|
|
|
messages.success(request, _("The VLAN was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-port-profile"))
|
2018-07-08 02:08:01 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"vlanform": vlan, "action_name": _("Edit")}, "machines/machine.html", request
|
2018-07-08 02:08:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(Port)
|
2018-03-28 18:32:03 +00:00
|
|
|
def new_port(request, switchid):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create ports."""
|
2016-07-06 21:29:31 +00:00
|
|
|
try:
|
2018-03-28 18:32:03 +00:00
|
|
|
switch = Switch.objects.get(pk=switchid)
|
2016-07-06 21:29:31 +00:00
|
|
|
except Switch.DoesNotExist:
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.error(request, _("Nonexistent switch."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index"))
|
2016-07-06 21:29:31 +00:00
|
|
|
port = AddPortForm(request.POST or None)
|
|
|
|
if port.is_valid():
|
|
|
|
port = port.save(commit=False)
|
|
|
|
port.switch = switch
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
port.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The port was added."))
|
2016-07-06 21:29:31 +00:00
|
|
|
except IntegrityError:
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.error(request, _("The port already exists."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-port", kwargs={"switchid": switchid}))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"id_switch": switchid, "topoform": port, "action_name": _("Add")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-06 19:50:15 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(Port)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_port(request, port_object, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit ports.
|
2017-12-28 11:39:25 +00:00
|
|
|
|
2020-04-29 13:00:47 +00:00
|
|
|
It enables to change the related switch and the port assignment.
|
|
|
|
"""
|
2016-11-18 23:34:42 +00:00
|
|
|
port = EditPortForm(request.POST or None, instance=port_object)
|
2016-07-06 19:50:15 +00:00
|
|
|
if port.is_valid():
|
2018-03-31 16:10:24 +00:00
|
|
|
if port.changed_data:
|
|
|
|
port.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The port was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse(
|
|
|
|
"topologie:index-port", kwargs={"switchid": str(port_object.switch.id)}
|
|
|
|
)
|
|
|
|
)
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"id_switch": str(port_object.switch.id),
|
|
|
|
"topoform": port,
|
|
|
|
"action_name": _("Edit"),
|
2018-04-14 00:20:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
|
2017-08-17 22:17:56 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_delete(Port)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_port(request, port, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete ports."""
|
2017-09-04 02:45:36 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
port.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The port was deleted."))
|
2017-09-04 02:45:36 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The port %s is used by another object, impossible to"
|
|
|
|
" delete it."
|
|
|
|
)
|
|
|
|
% port
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("topologie:index-port", kwargs={"switchid": str(port.switch.id)})
|
|
|
|
)
|
|
|
|
return form({"objet": port}, "topologie/delete.html", request)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2017-09-04 02:45:36 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(Stack)
|
2017-08-17 22:17:56 +00:00
|
|
|
def new_stack(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create stacks."""
|
2017-08-17 22:17:56 +00:00
|
|
|
stack = StackForm(request.POST or None)
|
2017-10-13 23:43:01 +00:00
|
|
|
if stack.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
stack.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The stack was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": stack, "action_name": _("Add")}, "topologie/topo.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-08-17 22:17:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(Stack)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_stack(request, stack, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit stacks."""
|
2017-08-17 22:17:56 +00:00
|
|
|
stack = StackForm(request.POST or None, instance=stack)
|
|
|
|
if stack.is_valid():
|
2018-03-31 16:10:24 +00:00
|
|
|
if stack.changed_data:
|
|
|
|
stack.save()
|
2019-11-16 14:14:22 +00:00
|
|
|
messages.success(request, _("The stack was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": stack, "action_name": _("Edit")}, "topologie/topo.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2017-08-17 22:17:56 +00:00
|
|
|
|
2017-08-18 12:20:51 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_delete(Stack)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_stack(request, stack, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete stacks."""
|
2017-08-18 12:20:51 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
stack.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The stack was deleted."))
|
2017-08-18 12:20:51 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The stack %s is used by another object, impossible to"
|
|
|
|
" deleted it."
|
|
|
|
)
|
|
|
|
% stack
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
|
|
|
return form({"objet": stack}, "topologie/delete.html", request)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2017-08-18 12:20:51 +00:00
|
|
|
|
2017-08-18 23:16:51 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(Stack)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_switchs_stack(request, stack, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit the list of switches of the given stack."""
|
2017-08-18 23:16:51 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
pass
|
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
context = {"stack": stack}
|
|
|
|
context["switchs_stack"] = stack.switchs_set.all()
|
|
|
|
context["switchs_autres"] = Switch.object.filter(stack=None)
|
2017-08-18 23:16:51 +00:00
|
|
|
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(Switch)
|
2016-07-06 21:29:31 +00:00
|
|
|
def new_switch(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create switches.
|
|
|
|
|
|
|
|
At the same time, it creates the related interface and machine. The view
|
|
|
|
successively calls the 4 appropriate forms: machine, interface, domain and
|
|
|
|
switch.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
switch = NewSwitchForm(request.POST or None, user=request.user)
|
|
|
|
interface = AddInterfaceForm(request.POST or None, user=request.user)
|
|
|
|
domain = DomainForm(request.POST or None, user=request.user)
|
2018-03-26 03:12:01 +00:00
|
|
|
if switch.is_valid() and interface.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
user = AssoOption.get_cached_value("utilisateur_asso")
|
2017-08-25 02:35:49 +00:00
|
|
|
if not user:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The organisation's user doesn't exist yet, please create"
|
|
|
|
" or link it in the preferences."
|
|
|
|
)
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index"))
|
2018-04-14 22:06:29 +00:00
|
|
|
new_switch_obj = switch.save(commit=False)
|
|
|
|
new_switch_obj.user = user
|
|
|
|
new_interface_obj = interface.save(commit=False)
|
|
|
|
domain.instance.interface_parent = new_interface_obj
|
2018-03-25 02:05:26 +00:00
|
|
|
if domain.is_valid():
|
2018-04-14 22:06:29 +00:00
|
|
|
new_domain_obj = domain.save(commit=False)
|
|
|
|
new_switch_obj.save()
|
|
|
|
new_interface_obj.machine = new_switch_obj
|
|
|
|
new_interface_obj.save()
|
|
|
|
new_domain_obj.interface_parent = new_interface_obj
|
|
|
|
new_domain_obj.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index"))
|
2018-03-26 03:12:01 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface, False)
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"topoform": interface,
|
|
|
|
"machineform": switch,
|
|
|
|
"domainform": domain,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
2019-11-16 14:14:22 +00:00
|
|
|
"device": _("switch"),
|
2018-04-14 00:20:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo_more.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:56:14 +00:00
|
|
|
|
2016-07-06 21:29:31 +00:00
|
|
|
|
2017-10-26 08:41:48 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(Port)
|
2018-03-28 18:32:03 +00:00
|
|
|
def create_ports(request, switchid):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create port lists for the given switch."""
|
2017-10-26 08:41:48 +00:00
|
|
|
try:
|
2018-03-28 18:32:03 +00:00
|
|
|
switch = Switch.objects.get(pk=switchid)
|
2017-10-26 08:41:48 +00:00
|
|
|
except Switch.DoesNotExist:
|
2019-01-08 23:40:48 +00:00
|
|
|
messages.error(request, _("Nonexistent switch."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index"))
|
2019-10-17 18:20:19 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
first_port = getattr(switch.ports.order_by("port").first(), "port", 1)
|
2018-12-30 13:31:36 +00:00
|
|
|
last_port = switch.number + first_port - 1
|
2017-10-26 08:41:48 +00:00
|
|
|
port_form = CreatePortsForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, initial={"begin": first_port, "end": last_port}
|
2017-10-26 08:41:48 +00:00
|
|
|
)
|
|
|
|
if port_form.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
begin = port_form.cleaned_data["begin"]
|
|
|
|
end = port_form.cleaned_data["end"]
|
2017-10-26 21:29:26 +00:00
|
|
|
try:
|
|
|
|
switch.create_ports(begin, end)
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The ports were created."))
|
2017-10-26 21:29:26 +00:00
|
|
|
except ValidationError as e:
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.error(request, "".join(e))
|
|
|
|
return redirect(reverse("topologie:index-port", kwargs={"switchid": switchid}))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"id_switch": switchid, "topoform": port_form}, "topologie/switch.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 19:29:34 +00:00
|
|
|
|
2016-07-06 21:29:31 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(Switch)
|
2018-03-28 18:32:03 +00:00
|
|
|
def edit_switch(request, switch, switchid):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit switches.
|
2017-12-09 04:49:29 +00:00
|
|
|
|
2020-04-29 13:00:47 +00:00
|
|
|
It enables to change the number of ports, location in the stack, or the
|
|
|
|
related interface and machine.
|
|
|
|
"""
|
2018-03-25 02:05:26 +00:00
|
|
|
switch_form = EditSwitchForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=switch, user=request.user
|
2018-07-11 17:37:22 +00:00
|
|
|
)
|
2018-03-26 03:12:01 +00:00
|
|
|
interface_form = EditInterfaceForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=switch.interface_set.first(), user=request.user
|
2018-07-11 17:37:22 +00:00
|
|
|
)
|
2017-10-18 00:27:42 +00:00
|
|
|
domain_form = DomainForm(
|
2017-10-13 23:43:01 +00:00
|
|
|
request.POST or None,
|
2019-10-17 18:20:19 +00:00
|
|
|
instance=switch.interface_set.first().domain,
|
2019-11-04 16:55:03 +00:00
|
|
|
user=request.user,
|
2018-07-11 17:37:22 +00:00
|
|
|
)
|
2018-03-26 03:12:01 +00:00
|
|
|
if switch_form.is_valid() and interface_form.is_valid():
|
2018-04-14 22:06:29 +00:00
|
|
|
new_switch_obj = switch_form.save(commit=False)
|
|
|
|
new_interface_obj = interface_form.save(commit=False)
|
|
|
|
new_domain_obj = domain_form.save(commit=False)
|
2018-03-31 16:10:24 +00:00
|
|
|
if switch_form.changed_data:
|
2018-04-14 22:06:29 +00:00
|
|
|
new_switch_obj.save()
|
2018-03-31 16:10:24 +00:00
|
|
|
if interface_form.changed_data:
|
2018-04-14 22:06:29 +00:00
|
|
|
new_interface_obj.save()
|
2018-03-31 16:10:24 +00:00
|
|
|
if domain_form.changed_data:
|
2018-04-14 22:06:29 +00:00
|
|
|
new_domain_obj.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index"))
|
2018-04-14 00:20:44 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
|
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"id_switch": switchid,
|
|
|
|
"topoform": interface_form,
|
|
|
|
"machineform": switch_form,
|
|
|
|
"domainform": domain_form,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
2019-11-16 14:14:22 +00:00
|
|
|
"device": _("switch"),
|
2018-04-14 00:20:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo_more.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:56:14 +00:00
|
|
|
|
2016-07-19 00:30:52 +00:00
|
|
|
|
2018-03-23 23:50:11 +00:00
|
|
|
@login_required
|
2018-03-25 22:08:24 +00:00
|
|
|
@can_create(AccessPoint)
|
|
|
|
def new_ap(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create APs.
|
|
|
|
|
|
|
|
At the same time, it creates the related interface and machine. The view
|
|
|
|
successively calls the 3 appropriate forms: machine, interface, domain.
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
ap = AddAccessPointForm(request.POST or None, user=request.user)
|
|
|
|
interface = AddInterfaceForm(request.POST or None, user=request.user)
|
|
|
|
domain = DomainForm(request.POST or None, user=request.user)
|
2018-03-26 01:09:42 +00:00
|
|
|
if ap.is_valid() and interface.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
user = AssoOption.get_cached_value("utilisateur_asso")
|
2018-03-23 23:50:11 +00:00
|
|
|
if not user:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The organisation's user doesn't exist yet, please create"
|
|
|
|
" or link it in the preferences."
|
|
|
|
)
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index"))
|
2018-04-14 22:06:29 +00:00
|
|
|
new_ap_obj = ap.save(commit=False)
|
|
|
|
new_ap_obj.user = user
|
|
|
|
new_interface_obj = interface.save(commit=False)
|
|
|
|
domain.instance.interface_parent = new_interface_obj
|
2018-03-23 23:50:11 +00:00
|
|
|
if domain.is_valid():
|
2018-04-14 22:06:29 +00:00
|
|
|
new_domain_obj = domain.save(commit=False)
|
|
|
|
new_ap_obj.save()
|
|
|
|
new_interface_obj.machine = new_ap_obj
|
|
|
|
new_interface_obj.save()
|
|
|
|
new_domain_obj.interface_parent = new_interface_obj
|
|
|
|
new_domain_obj.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The access point was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-ap"))
|
2018-03-26 01:09:42 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface, False)
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"topoform": interface,
|
|
|
|
"machineform": ap,
|
|
|
|
"domainform": domain,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
2019-11-16 14:14:22 +00:00
|
|
|
"device": _("access point"),
|
2018-04-14 00:20:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo_more.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-03-23 23:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2018-03-25 22:08:24 +00:00
|
|
|
@can_edit(AccessPoint)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_ap(request, ap, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit APs."""
|
2018-03-26 01:09:42 +00:00
|
|
|
interface_form = EditInterfaceForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, user=request.user, instance=ap.interface_set.first()
|
2018-03-23 23:50:11 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
ap_form = EditAccessPointForm(request.POST or None, user=request.user, instance=ap)
|
2018-03-23 23:50:11 +00:00
|
|
|
domain_form = DomainForm(
|
|
|
|
request.POST or None,
|
2019-10-17 18:20:19 +00:00
|
|
|
instance=ap.interface_set.first().domain,
|
2019-11-04 16:55:03 +00:00
|
|
|
user=request.user,
|
2018-07-11 17:37:22 +00:00
|
|
|
)
|
2018-03-26 01:09:42 +00:00
|
|
|
if ap_form.is_valid() and interface_form.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
user = AssoOption.get_cached_value("utilisateur_asso")
|
2018-03-23 23:50:11 +00:00
|
|
|
if not user:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The organisation's user doesn't exist yet, please create"
|
|
|
|
" or link it in the preferences."
|
|
|
|
)
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-ap"))
|
2018-04-14 22:06:29 +00:00
|
|
|
new_ap_obj = ap_form.save(commit=False)
|
|
|
|
new_interface_obj = interface_form.save(commit=False)
|
|
|
|
new_domain_obj = domain_form.save(commit=False)
|
2018-03-31 16:10:24 +00:00
|
|
|
if ap_form.changed_data:
|
2018-04-14 22:06:29 +00:00
|
|
|
new_ap_obj.save()
|
2018-03-31 16:10:24 +00:00
|
|
|
if interface_form.changed_data:
|
2018-04-14 22:06:29 +00:00
|
|
|
new_interface_obj.save()
|
2018-03-31 16:10:24 +00:00
|
|
|
if domain_form.changed_data:
|
2018-04-14 22:06:29 +00:00
|
|
|
new_domain_obj.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The access point was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-ap"))
|
2018-04-14 00:20:44 +00:00
|
|
|
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
|
|
|
|
return form(
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"topoform": interface_form,
|
|
|
|
"machineform": ap_form,
|
|
|
|
"domainform": domain_form,
|
|
|
|
"i_mbf_param": i_mbf_param,
|
2019-11-16 14:14:22 +00:00
|
|
|
"device": _("access point"),
|
2018-04-14 00:20:44 +00:00
|
|
|
},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo_more.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
|
|
|
|
2018-03-23 23:50:11 +00:00
|
|
|
|
2016-07-19 00:30:52 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(Room)
|
2016-07-19 00:30:52 +00:00
|
|
|
def new_room(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create rooms."""
|
2016-07-19 00:30:52 +00:00
|
|
|
room = EditRoomForm(request.POST or None)
|
|
|
|
if room.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
room.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The room was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-room"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": room, "action_name": _("Add")}, "topologie/topo.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-19 00:30:52 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(Room)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_room(request, room, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit rooms."""
|
2016-07-19 00:30:52 +00:00
|
|
|
room = EditRoomForm(request.POST or None, instance=room)
|
|
|
|
if room.is_valid():
|
2018-03-31 16:10:24 +00:00
|
|
|
if room.changed_data:
|
|
|
|
room.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The room was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-room"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": room, "action_name": _("Edit")}, "topologie/topo.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-13 23:43:01 +00:00
|
|
|
|
2016-07-19 00:30:52 +00:00
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_delete(Room)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_room(request, room, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete rooms."""
|
2016-07-19 00:30:52 +00:00
|
|
|
if request.method == "POST":
|
2017-08-17 22:17:56 +00:00
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
room.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The room was deleted."))
|
2017-08-17 22:17:56 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The room %s is used by another object, impossible to"
|
|
|
|
" deleted it."
|
|
|
|
)
|
|
|
|
% room
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-room"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": room, "objet_name": _("room")}, "topologie/delete.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(ModelSwitch)
|
2017-10-26 03:07:11 +00:00
|
|
|
def new_model_switch(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create switch models."""
|
2017-10-26 03:07:11 +00:00
|
|
|
model_switch = EditModelSwitchForm(request.POST or None)
|
|
|
|
if model_switch.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
model_switch.save()
|
2019-01-08 23:40:48 +00:00
|
|
|
messages.success(request, _("The switch model was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-model-switch"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": model_switch, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(ModelSwitch)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_model_switch(request, model_switch, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit switch models."""
|
2019-11-04 16:55:03 +00:00
|
|
|
model_switch = EditModelSwitchForm(request.POST or None, instance=model_switch)
|
2017-10-26 03:07:11 +00:00
|
|
|
if model_switch.is_valid():
|
2018-03-31 16:10:24 +00:00
|
|
|
if model_switch.changed_data:
|
|
|
|
model_switch.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch model was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-model-switch"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": model_switch, "action_name": _("Edit")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_delete(ModelSwitch)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_model_switch(request, model_switch, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete switch models."""
|
2017-10-26 03:07:11 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
model_switch.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch model was deleted."))
|
2017-10-26 03:07:11 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The switch model %s is used by another object,"
|
|
|
|
" impossible to delete it."
|
|
|
|
)
|
|
|
|
% model_switch
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-model-switch"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": model_switch, "objet_name": _("switch model")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/delete.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
2018-04-07 18:45:29 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(SwitchBay)
|
|
|
|
def new_switch_bay(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create switch bays."""
|
2018-04-07 18:45:29 +00:00
|
|
|
switch_bay = EditSwitchBayForm(request.POST or None)
|
|
|
|
if switch_bay.is_valid():
|
|
|
|
switch_bay.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch bay was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": switch_bay, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-04-07 18:45:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(SwitchBay)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_switch_bay(request, switch_bay, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit switch bays."""
|
2018-04-07 18:45:29 +00:00
|
|
|
switch_bay = EditSwitchBayForm(request.POST or None, instance=switch_bay)
|
|
|
|
if switch_bay.is_valid():
|
|
|
|
if switch_bay.changed_data:
|
|
|
|
switch_bay.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch bay was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": switch_bay, "action_name": _("Edit")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-04-07 18:45:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(SwitchBay)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_switch_bay(request, switch_bay, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete switch bays."""
|
2018-04-07 18:45:29 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
|
|
|
switch_bay.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch bay was deleted."))
|
2018-04-07 18:45:29 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The switch bay %s is used by another object,"
|
|
|
|
" impossible to delete it."
|
|
|
|
)
|
|
|
|
% switch_bay
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": switch_bay, "objet_name": _("switch bay")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/delete.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-04-07 18:45:29 +00:00
|
|
|
|
|
|
|
|
2018-04-08 02:01:32 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(Building)
|
|
|
|
def new_building(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create buildings."""
|
2018-04-08 02:01:32 +00:00
|
|
|
building = EditBuildingForm(request.POST or None)
|
|
|
|
if building.is_valid():
|
|
|
|
building.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The building was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": building, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-04-08 02:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(Building)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_building(request, building, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit buildings."""
|
2018-04-08 02:01:32 +00:00
|
|
|
building = EditBuildingForm(request.POST or None, instance=building)
|
|
|
|
if building.is_valid():
|
|
|
|
if building.changed_data:
|
|
|
|
building.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The building was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": building, "action_name": _("Edit")}, "topologie/topo.html", request
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-04-08 02:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(Building)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_building(request, building, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete buildings."""
|
2018-04-08 02:01:32 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
|
|
|
building.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The building was deleted."))
|
2018-04-08 02:01:32 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The building %s is used by another object, impossible"
|
|
|
|
" to delete it."
|
|
|
|
)
|
|
|
|
% building
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": building, "objet_name": _("building")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/delete.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2018-04-08 02:01:32 +00:00
|
|
|
|
|
|
|
|
2019-02-18 20:11:51 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(Dormitory)
|
|
|
|
def new_dormitory(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create dormitories."""
|
2019-02-18 20:11:51 +00:00
|
|
|
dormitory = EditDormitoryForm(request.POST or None)
|
|
|
|
if dormitory.is_valid():
|
|
|
|
dormitory.save()
|
|
|
|
messages.success(request, _("The dormitory was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2019-02-18 20:11:51 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": dormitory, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2019-02-18 20:11:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(Dormitory)
|
|
|
|
def edit_dormitory(request, dormitory, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit dormitories."""
|
2019-02-18 20:11:51 +00:00
|
|
|
dormitory = EditDormitoryForm(request.POST or None, instance=dormitory)
|
|
|
|
if dormitory.is_valid():
|
|
|
|
if dormitory.changed_data:
|
|
|
|
dormitory.save()
|
|
|
|
messages.success(request, _("The dormitory was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2019-02-18 20:11:51 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": dormitory, "action_name": _("Edit")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2019-02-18 20:11:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(Dormitory)
|
|
|
|
def del_dormitory(request, dormitory, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete dormitories."""
|
2019-02-18 20:11:51 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
|
|
|
dormitory.delete()
|
|
|
|
messages.success(request, _("The dormitory was deleted."))
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The dormitory %s is used by another object, impossible"
|
|
|
|
" to delete it."
|
|
|
|
)
|
|
|
|
% dormitory
|
|
|
|
),
|
2019-02-18 20:11:51 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-physical-grouping"))
|
2019-02-18 20:11:51 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": dormitory, "objet_name": _("dormitory")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/delete.html",
|
|
|
|
request,
|
2019-02-18 20:11:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-10-26 03:07:11 +00:00
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_create(ConstructorSwitch)
|
2017-10-26 03:07:11 +00:00
|
|
|
def new_constructor_switch(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create switch constructors."""
|
2017-10-26 03:07:11 +00:00
|
|
|
constructor_switch = EditConstructorSwitchForm(request.POST or None)
|
|
|
|
if constructor_switch.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
constructor_switch.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch constructor was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-model-switch"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": constructor_switch, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_edit(ConstructorSwitch)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_constructor_switch(request, constructor_switch, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit switch constructors."""
|
2018-04-14 00:20:44 +00:00
|
|
|
constructor_switch = EditConstructorSwitchForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=constructor_switch
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
if constructor_switch.is_valid():
|
2018-03-31 16:10:24 +00:00
|
|
|
if constructor_switch.changed_data:
|
|
|
|
constructor_switch.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch constructor was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-model-switch"))
|
2018-04-14 00:20:44 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": constructor_switch, "action_name": _("Edit")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2017-10-26 03:07:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2017-12-09 04:49:29 +00:00
|
|
|
@can_delete(ConstructorSwitch)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_constructor_switch(request, constructor_switch, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete switch constructors."""
|
2017-10-26 03:07:11 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
constructor_switch.delete()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The switch constructor was deleted."))
|
2017-10-26 03:07:11 +00:00
|
|
|
except ProtectedError:
|
2018-04-14 00:20:44 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The switch constructor %s is used by another object,"
|
|
|
|
" impossible to delete it."
|
|
|
|
)
|
|
|
|
% constructor_switch
|
|
|
|
),
|
2018-04-14 00:20:44 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-model-switch"))
|
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": constructor_switch, "objet_name": _("switch constructor")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/delete.html",
|
|
|
|
request,
|
|
|
|
)
|
2018-04-13 18:31:51 +00:00
|
|
|
|
|
|
|
|
2018-05-26 22:36:25 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(PortProfile)
|
|
|
|
def new_port_profile(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create port profiles."""
|
2018-06-26 23:29:40 +00:00
|
|
|
port_profile = EditPortProfileForm(request.POST or None)
|
2018-05-26 22:36:25 +00:00
|
|
|
if port_profile.is_valid():
|
|
|
|
port_profile.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The port profile was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-port-profile"))
|
2018-05-26 22:36:25 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": port_profile, "action_name": _("Add")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-05-26 22:36:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(PortProfile)
|
|
|
|
def edit_port_profile(request, port_profile, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit port profiles."""
|
2019-11-04 16:55:03 +00:00
|
|
|
port_profile = EditPortProfileForm(request.POST or None, instance=port_profile)
|
2018-05-26 22:36:25 +00:00
|
|
|
if port_profile.is_valid():
|
|
|
|
if port_profile.changed_data:
|
|
|
|
port_profile.save()
|
2018-08-05 16:48:56 +00:00
|
|
|
messages.success(request, _("The port profile was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-port-profile"))
|
2018-05-26 22:36:25 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": port_profile, "action_name": _("Edit")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-05-26 22:36:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(PortProfile)
|
|
|
|
def del_port_profile(request, port_profile, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete port profiles."""
|
2019-11-04 16:55:03 +00:00
|
|
|
if request.method == "POST":
|
2018-05-26 22:36:25 +00:00
|
|
|
try:
|
|
|
|
port_profile.delete()
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(request, _("The port profile was deleted."))
|
2018-05-26 22:36:25 +00:00
|
|
|
except ProtectedError:
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(request, _("Impossible to delete the port profile."))
|
|
|
|
return redirect(reverse("topologie:index-port-profile"))
|
2018-05-26 22:36:25 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": port_profile, "objet_name": _("port profile")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"topologie/delete.html",
|
|
|
|
request,
|
2018-05-26 22:36:25 +00:00
|
|
|
)
|
|
|
|
|
2018-07-11 17:37:22 +00:00
|
|
|
|
2018-12-30 17:20:06 +00:00
|
|
|
@login_required
|
2018-12-30 16:04:21 +00:00
|
|
|
@can_create(ModuleSwitch)
|
|
|
|
def add_module(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to create switch modules."""
|
2018-12-30 16:04:21 +00:00
|
|
|
module = EditModuleForm(request.POST or None)
|
|
|
|
if module.is_valid():
|
|
|
|
module.save()
|
|
|
|
messages.success(request, _("The module was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-module"))
|
2018-12-30 16:04:21 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"topoform": module, "action_name": _("Add")}, "topologie/topo.html", request
|
2018-12-30 16:04:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(ModuleSwitch)
|
|
|
|
def edit_module(request, module_instance, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit switch modules."""
|
2018-12-30 16:04:21 +00:00
|
|
|
module = EditModuleForm(request.POST or None, instance=module_instance)
|
|
|
|
if module.is_valid():
|
|
|
|
if module.changed_data:
|
|
|
|
module.save()
|
|
|
|
messages.success(request, _("The module was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-module"))
|
2018-12-30 16:04:21 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": module, "action_name": _("Edit")}, "topologie/topo.html", request
|
2018-12-30 16:04:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(ModuleSwitch)
|
|
|
|
def del_module(request, module, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete switch modules."""
|
2018-12-30 16:04:21 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
|
|
|
module.delete()
|
|
|
|
messages.success(request, _("The module was deleted."))
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The module %s is used by another object, impossible to"
|
|
|
|
" deleted it."
|
|
|
|
)
|
|
|
|
% module
|
|
|
|
),
|
2018-12-30 16:04:21 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-module"))
|
2018-12-30 16:04:21 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": module, "objet_name": _("module")}, "topologie/delete.html", request
|
2018-12-30 16:04:21 +00:00
|
|
|
)
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-12-30 17:20:06 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(ModuleOnSwitch)
|
|
|
|
def add_module_on(request):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to add a module to a switch."""
|
2018-12-30 17:20:06 +00:00
|
|
|
module_switch = EditSwitchModuleForm(request.POST or None)
|
|
|
|
if module_switch.is_valid():
|
|
|
|
module_switch.save()
|
2019-01-08 23:40:48 +00:00
|
|
|
messages.success(request, _("The module was added."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-module"))
|
2018-12-30 17:20:06 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": module_switch, "action_name": _("Add")},
|
|
|
|
"topologie/topo.html",
|
|
|
|
request,
|
2018-12-30 17:20:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(ModuleOnSwitch)
|
|
|
|
def edit_module_on(request, module_instance, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to edit a module on a switch."""
|
2018-12-30 17:20:06 +00:00
|
|
|
module = EditSwitchModuleForm(request.POST or None, instance=module_instance)
|
|
|
|
if module.is_valid():
|
|
|
|
if module.changed_data:
|
|
|
|
module.save()
|
|
|
|
messages.success(request, _("The module was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-module"))
|
2018-12-30 17:20:06 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"topoform": module, "action_name": _("Edit")}, "topologie/topo.html", request
|
2018-12-30 17:20:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(ModuleOnSwitch)
|
|
|
|
def del_module_on(request, module, **_kwargs):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""View used to delete a module on a switch."""
|
2018-12-30 17:20:06 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
try:
|
|
|
|
module.delete()
|
|
|
|
messages.success(request, _("The module was deleted."))
|
|
|
|
except ProtectedError:
|
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
_(
|
|
|
|
"The module %s is used by another object, impossible to"
|
|
|
|
" deleted it."
|
|
|
|
)
|
|
|
|
% module
|
|
|
|
),
|
2018-12-30 17:20:06 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("topologie:index-module"))
|
2018-12-30 17:20:06 +00:00
|
|
|
return form(
|
2019-11-16 14:14:22 +00:00
|
|
|
{"objet": module, "objet_name": _("module")}, "topologie/delete.html", request
|
2018-12-30 17:20:06 +00:00
|
|
|
)
|
|
|
|
|
2018-12-30 16:04:21 +00:00
|
|
|
|
2018-04-13 18:31:51 +00:00
|
|
|
def make_machine_graph():
|
2020-04-29 13:00:47 +00:00
|
|
|
"""Create the graph of switches, machines and access points."""
|
2018-05-15 18:42:00 +00:00
|
|
|
dico = {
|
2019-11-04 16:55:03 +00:00
|
|
|
"subs": [],
|
|
|
|
"links": [],
|
|
|
|
"alone": [],
|
|
|
|
"colors": {
|
|
|
|
"head": "#7f0505", # Color parameters for the graph
|
|
|
|
"back": "#b5adad",
|
|
|
|
"texte": "#563d01",
|
|
|
|
"border_bornes": "#02078e",
|
|
|
|
"head_bornes": "#25771c",
|
|
|
|
"head_server": "#1c3777",
|
|
|
|
},
|
2018-07-11 17:37:22 +00:00
|
|
|
}
|
2019-11-04 16:55:03 +00:00
|
|
|
missing = list(
|
|
|
|
Switch.objects.prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"interface_set",
|
|
|
|
queryset=(
|
|
|
|
Interface.objects.select_related(
|
|
|
|
"ipv4__ip_type__extension"
|
|
|
|
).select_related("domain__extension")
|
|
|
|
),
|
|
|
|
)
|
2019-08-06 02:11:17 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
)
|
2018-05-15 18:42:00 +00:00
|
|
|
detected = []
|
2018-05-21 19:13:44 +00:00
|
|
|
for building in Building.objects.all(): # Visit all buildings
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
dico["subs"].append(
|
2018-05-15 18:42:00 +00:00
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"bat_id": building.id,
|
|
|
|
"bat_name": building,
|
|
|
|
"switchs": [],
|
|
|
|
"bornes": [],
|
|
|
|
"machines": [],
|
2018-05-15 18:42:00 +00:00
|
|
|
}
|
|
|
|
)
|
2020-04-29 13:00:47 +00:00
|
|
|
# Visit all switches in this building
|
2019-11-04 16:55:03 +00:00
|
|
|
for switch in (
|
|
|
|
Switch.objects.filter(switchbay__building=building)
|
|
|
|
.prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"interface_set",
|
|
|
|
queryset=(
|
|
|
|
Interface.objects.select_related(
|
|
|
|
"ipv4__ip_type__extension"
|
|
|
|
).select_related("domain__extension")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.select_related("switchbay__building")
|
|
|
|
.select_related("switchbay__building__dormitory")
|
|
|
|
.select_related("model__constructor")
|
|
|
|
):
|
|
|
|
dico["subs"][-1]["switchs"].append(
|
|
|
|
{
|
|
|
|
"name": switch.get_name,
|
|
|
|
"nombre": switch.number,
|
|
|
|
"model": switch.model,
|
|
|
|
"id": switch.id,
|
|
|
|
"batiment": building,
|
|
|
|
"ports": [],
|
|
|
|
}
|
|
|
|
)
|
2020-04-29 13:00:47 +00:00
|
|
|
# visit all ports of this switch and add the switches linked to it
|
2019-11-04 16:55:03 +00:00
|
|
|
for port in switch.ports.filter(related__isnull=False).select_related(
|
|
|
|
"related__switch"
|
2019-08-06 02:11:17 +00:00
|
|
|
):
|
2019-11-04 16:55:03 +00:00
|
|
|
dico["subs"][-1]["switchs"][-1]["ports"].append(
|
|
|
|
{"numero": port.port, "related": port.related.switch.get_name}
|
|
|
|
)
|
|
|
|
|
|
|
|
for ap in AccessPoint.all_ap_in(building).prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"interface_set",
|
|
|
|
queryset=(
|
|
|
|
Interface.objects.select_related(
|
|
|
|
"ipv4__ip_type__extension"
|
|
|
|
).select_related("domain__extension")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
):
|
2019-08-06 02:11:17 +00:00
|
|
|
switch = ap.switch().first()
|
2019-11-04 16:55:03 +00:00
|
|
|
dico["subs"][-1]["bornes"].append(
|
|
|
|
{
|
|
|
|
"name": ap.short_name,
|
|
|
|
"switch": switch.get_name,
|
|
|
|
"port": switch.ports.filter(machine_interface__machine=ap)
|
|
|
|
.first()
|
|
|
|
.port,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
for server in Server.all_server_in(building).prefetch_related(
|
|
|
|
Prefetch(
|
|
|
|
"interface_set",
|
|
|
|
queryset=(
|
|
|
|
Interface.objects.select_related(
|
|
|
|
"ipv4__ip_type__extension"
|
|
|
|
).select_related("domain__extension")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
):
|
|
|
|
dico["subs"][-1]["machines"].append(
|
|
|
|
{
|
|
|
|
"name": server.short_name,
|
|
|
|
"switch": server.switch().first().get_name,
|
|
|
|
"port": Port.objects.filter(machine_interface__machine=server)
|
|
|
|
.first()
|
|
|
|
.port,
|
|
|
|
}
|
|
|
|
)
|
2018-05-15 18:42:00 +00:00
|
|
|
|
2018-05-21 19:13:44 +00:00
|
|
|
# While the list of forgotten ones is not empty
|
2018-05-15 18:42:00 +00:00
|
|
|
while missing:
|
2018-05-21 19:13:44 +00:00
|
|
|
if missing[0].ports.count(): # The switch is not empty
|
2019-11-04 16:55:03 +00:00
|
|
|
links, new_detected = recursive_switchs(missing[0], None, [missing[0]])
|
2018-05-15 18:42:00 +00:00
|
|
|
for link in links:
|
2019-11-04 16:55:03 +00:00
|
|
|
dico["links"].append(link)
|
2020-04-29 13:00:47 +00:00
|
|
|
# Update the lists of missings and already detected switches
|
2018-07-11 17:37:22 +00:00
|
|
|
missing = [i for i in missing if i not in new_detected]
|
2018-05-15 18:42:00 +00:00
|
|
|
detected += new_detected
|
2020-04-29 13:00:47 +00:00
|
|
|
# If the switch has no ports, don't explore it and hop to the next one
|
2018-07-11 17:37:22 +00:00
|
|
|
else:
|
2018-05-15 18:42:00 +00:00
|
|
|
del missing[0]
|
2020-04-29 13:00:47 +00:00
|
|
|
# Switches that are not connected or not in a building
|
2019-11-04 16:55:03 +00:00
|
|
|
for switch in Switch.objects.filter(switchbay__isnull=True).exclude(
|
|
|
|
ports__related__isnull=False
|
|
|
|
):
|
|
|
|
dico["alone"].append({"id": switch.id, "name": switch.get_name})
|
2018-05-19 19:20:55 +00:00
|
|
|
|
2020-04-29 13:00:47 +00:00
|
|
|
# Generate the dot file
|
2019-11-04 16:55:03 +00:00
|
|
|
dot_data = generate_dot(dico, "topologie/graph_switch.dot")
|
2018-05-21 20:05:31 +00:00
|
|
|
|
2018-07-11 17:37:22 +00:00
|
|
|
# Create a temporary file to store the dot data
|
2019-11-04 16:55:03 +00:00
|
|
|
f = tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8", delete=False)
|
2018-05-21 20:05:31 +00:00
|
|
|
with f:
|
2018-07-11 17:37:22 +00:00
|
|
|
f.write(dot_data)
|
2020-04-29 13:00:47 +00:00
|
|
|
unflatten = Popen( # Unflatten the graph to make it look better
|
2019-11-04 16:55:03 +00:00
|
|
|
["unflatten", "-l", "3", f.name], stdout=PIPE
|
2018-05-15 18:42:00 +00:00
|
|
|
)
|
2020-04-29 13:00:47 +00:00
|
|
|
Popen( # Pipe the result of the first command into the second
|
2018-05-15 18:42:00 +00:00
|
|
|
["dot", "-Tpng", "-o", MEDIA_ROOT + "/images/switchs.png"],
|
|
|
|
stdin=unflatten.stdout,
|
2019-11-04 16:55:03 +00:00
|
|
|
stdout=PIPE,
|
2018-05-15 18:42:00 +00:00
|
|
|
)
|
2018-05-14 21:58:05 +00:00
|
|
|
|
2018-07-11 17:37:22 +00:00
|
|
|
|
|
|
|
def generate_dot(data, template):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""Generate a dot file from the data and template given.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
data: dictionary passed to the template.
|
|
|
|
template: path to the dot template.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
All the lines of the dot file.
|
|
|
|
"""
|
2018-05-15 18:42:00 +00:00
|
|
|
t = loader.get_template(template)
|
2019-11-04 16:55:03 +00:00
|
|
|
if not isinstance(t, Template) and not (
|
|
|
|
hasattr(t, "template") and isinstance(t.template, Template)
|
|
|
|
):
|
|
|
|
raise Exception(
|
|
|
|
_(
|
|
|
|
"The default Django template isn't used. This can"
|
|
|
|
" lead to rendering errors. Check the parameters."
|
|
|
|
)
|
|
|
|
)
|
2018-05-15 18:42:00 +00:00
|
|
|
c = Context(data).flatten()
|
|
|
|
dot = t.render(c)
|
2019-11-04 16:55:03 +00:00
|
|
|
return dot
|
2018-05-15 18:42:00 +00:00
|
|
|
|
2018-07-11 17:37:22 +00:00
|
|
|
|
2018-05-19 19:20:55 +00:00
|
|
|
def recursive_switchs(switch_start, switch_before, detected):
|
2020-04-29 13:00:47 +00:00
|
|
|
"""Visit the switch and travel to the switches linked to it.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
switch_start: the switch to begin the visit on.
|
|
|
|
switch_before: the switch that you come from. None if switch_start is the first one.
|
|
|
|
detected: list of all switches already visited. None if switch_start is the first one.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of all the links found and a list of all the switches visited.
|
2018-07-11 17:37:22 +00:00
|
|
|
"""
|
2018-05-30 20:07:43 +00:00
|
|
|
detected.append(switch_start)
|
2020-04-29 13:00:47 +00:00
|
|
|
links_return = [] # List of dictionaries of the links to be detected
|
|
|
|
# Create links to every switches below
|
2018-07-11 17:37:22 +00:00
|
|
|
for port in switch_start.ports.filter(related__isnull=False):
|
|
|
|
# Not the switch that we come from, not the current switch
|
2019-11-04 16:55:03 +00:00
|
|
|
if (
|
|
|
|
port.related.switch != switch_before
|
|
|
|
and port.related.switch != port.switch
|
|
|
|
and port.related.switch not in detected
|
|
|
|
):
|
2018-05-21 19:13:44 +00:00
|
|
|
links = { # Dictionary of a link
|
2019-11-04 16:55:03 +00:00
|
|
|
"depart": switch_start.id,
|
|
|
|
"arrive": port.related.switch.id,
|
2018-05-15 18:42:00 +00:00
|
|
|
}
|
2018-05-21 19:13:44 +00:00
|
|
|
links_return.append(links) # Add current and below levels links
|
2018-05-30 20:07:43 +00:00
|
|
|
|
2020-04-29 13:00:47 +00:00
|
|
|
# Go down on every related switches
|
2018-07-11 17:37:22 +00:00
|
|
|
for port in switch_start.ports.filter(related__isnull=False):
|
|
|
|
# The switch at the end of this link has not been visited
|
|
|
|
if port.related.switch not in detected:
|
2020-04-29 13:00:47 +00:00
|
|
|
# Explore it and get the results
|
2018-07-11 17:37:22 +00:00
|
|
|
links_down, detected = recursive_switchs(
|
2019-11-04 16:55:03 +00:00
|
|
|
port.related.switch, switch_start, detected
|
|
|
|
)
|
2018-07-11 17:37:22 +00:00
|
|
|
# Add the non empty links to the current list
|
|
|
|
for link in links_down:
|
2018-05-30 20:07:43 +00:00
|
|
|
if link:
|
2018-07-11 17:37:22 +00:00
|
|
|
links_return.append(link)
|
2018-05-15 18:42:00 +00:00
|
|
|
return (links_return, detected)
|