mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Switch hérite de interface
This commit is contained in:
parent
cb87b3f6c0
commit
3a2e007372
13 changed files with 253 additions and 126 deletions
|
@ -78,7 +78,7 @@ class EditPortForm(ModelForm):
|
||||||
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
||||||
.select_related('domain__extension')
|
.select_related('domain__extension')
|
||||||
self.fields['related'].queryset = Port.objects.all()\
|
self.fields['related'].queryset = Port.objects.all()\
|
||||||
.select_related('switch__switch_interface__domain__extension')\
|
.select_related('switch__domain__extension')\
|
||||||
.order_by('switch', 'port')
|
.order_by('switch', 'port')
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class AddPortForm(ModelForm):
|
||||||
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
||||||
.select_related('domain__extension')
|
.select_related('domain__extension')
|
||||||
self.fields['related'].queryset = Port.objects.all()\
|
self.fields['related'].queryset = Port.objects.all()\
|
||||||
.select_related('switch__switch_interface__domain__extension')\
|
.select_related('switch__domain__extension')\
|
||||||
.order_by('switch', 'port')
|
.order_by('switch', 'port')
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,32 +126,30 @@ class EditBorneForm(EditInterfaceForm):
|
||||||
fields = ['machine', 'type', 'ipv4', 'mac_address', 'details', 'location']
|
fields = ['machine', 'type', 'ipv4', 'mac_address', 'details', 'location']
|
||||||
|
|
||||||
|
|
||||||
class EditSwitchForm(ModelForm):
|
class EditSwitchForm(EditInterfaceForm):
|
||||||
"""Permet d'éditer un switch : nom et nombre de ports"""
|
"""Permet d'éditer un switch : nom et nombre de ports"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Switch
|
model = Switch
|
||||||
fields = '__all__'
|
fields = ['machine', 'type', 'ipv4', 'mac_address', 'details', 'location', 'number', 'stack', 'stack_member_id']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
# def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
# prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(EditSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
# super(EditInterfaceForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['switch_interface'].queryset = Interface.objects.all()\
|
# self.fields['location'].label = 'Localisation'
|
||||||
.select_related('domain__extension')
|
# self.fields['number'].label = 'Nombre de ports'
|
||||||
self.fields['location'].label = 'Localisation'
|
|
||||||
self.fields['number'].label = 'Nombre de ports'
|
|
||||||
|
|
||||||
|
|
||||||
class NewSwitchForm(ModelForm):
|
class NewSwitchForm(EditInterfaceForm):
|
||||||
"""Permet de créer un switch : emplacement, paramètres machine,
|
"""Permet de créer un switch : emplacement, paramètres machine,
|
||||||
membre d'un stack (option), nombre de ports (number)"""
|
membre d'un stack (option), nombre de ports (number)"""
|
||||||
class Meta(EditSwitchForm.Meta):
|
class Meta(EditSwitchForm.Meta):
|
||||||
fields = ['location', 'number', 'details', 'stack', 'stack_member_id']
|
fields = ['type', 'ipv4', 'mac_address', 'details', 'location', 'number', 'stack', 'stack_member_id']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
#def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
# prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(NewSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
# super(NewSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['location'].label = 'Localisation'
|
# self.fields['location'].label = 'Localisation'
|
||||||
self.fields['number'].label = 'Nombre de ports'
|
# self.fields['number'].label = 'Nombre de ports'
|
||||||
|
|
||||||
class EditRoomForm(ModelForm):
|
class EditRoomForm(ModelForm):
|
||||||
"""Permet d'éediter le nom et commentaire d'une prise murale"""
|
"""Permet d'éediter le nom et commentaire d'une prise murale"""
|
||||||
|
|
33
topologie/migrations/0037_auto_20180325_0127.py
Normal file
33
topologie/migrations/0037_auto_20180325_0127.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-03-25 00:27
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('machines', '0076_auto_20180130_1623'),
|
||||||
|
('topologie', '0036_transferborne'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NewSwitch',
|
||||||
|
fields=[
|
||||||
|
('interface_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='machines.Interface')),
|
||||||
|
('location', models.CharField(max_length=255)),
|
||||||
|
('number', models.PositiveIntegerField()),
|
||||||
|
('stack_member_id', models.PositiveIntegerField(blank=True, null=True)),
|
||||||
|
('model', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='topologie.ModelSwitch')),
|
||||||
|
('stack', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='topologie.Stack')),
|
||||||
|
],
|
||||||
|
bases=('machines.interface',),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='newswitch',
|
||||||
|
unique_together=set([('stack', 'stack_member_id')]),
|
||||||
|
),
|
||||||
|
]
|
37
topologie/migrations/0038_transfersw.py
Normal file
37
topologie/migrations/0038_transfersw.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2017-12-31 19:53
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0037_auto_20180325_0127'),
|
||||||
|
]
|
||||||
|
|
||||||
|
def transfer_sw(apps, schema_editor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
newswitch = apps.get_model("topologie", "NewSwitch")
|
||||||
|
switch = apps.get_model("topologie", "Switch")
|
||||||
|
interface = apps.get_model("machines", "Interface")
|
||||||
|
sw_list = switch.objects.using(db_alias).all()
|
||||||
|
for sw in sw_list:
|
||||||
|
new_sw = newswitch()
|
||||||
|
new_sw.location = sw.location
|
||||||
|
new_sw.number = sw.number
|
||||||
|
new_sw.details = sw.details
|
||||||
|
new_sw.stack = sw.stack
|
||||||
|
new_sw.stack_member_id = sw.stack_member_id
|
||||||
|
new_sw.model = sw.model
|
||||||
|
new_sw.interface_ptr_id = sw.switch_interface.pk
|
||||||
|
new_sw.__dict__.update(sw.switch_interface.__dict__)
|
||||||
|
new_sw.save()
|
||||||
|
|
||||||
|
def untransfer_sw(apps, schema_editor):
|
||||||
|
return
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(transfer_sw, untransfer_sw),
|
||||||
|
]
|
21
topologie/migrations/0039_port_new_switch.py
Normal file
21
topologie/migrations/0039_port_new_switch.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-03-25 00:52
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0038_transfersw'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='port',
|
||||||
|
name='new_switch',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ports', to='topologie.NewSwitch'),
|
||||||
|
),
|
||||||
|
]
|
28
topologie/migrations/0040_transferports.py
Normal file
28
topologie/migrations/0040_transferports.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2017-12-31 19:53
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0039_port_new_switch'),
|
||||||
|
]
|
||||||
|
|
||||||
|
def transfer_port(apps, schema_editor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
port = apps.get_model("topologie", "Port")
|
||||||
|
switch = apps.get_model("topologie", "NewSwitch")
|
||||||
|
port_list = port.objects.using(db_alias).all()
|
||||||
|
for p in port_list:
|
||||||
|
p.new_switch = switch.objects.filter(interface_ptr=p.switch.switch_interface).first()
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
def untransfer_port(apps, schema_editor):
|
||||||
|
return
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(transfer_port, untransfer_port),
|
||||||
|
]
|
20
topologie/migrations/0041_transferportsw.py
Normal file
20
topologie/migrations/0041_transferportsw.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2017-12-31 19:53
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0040_transferports'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='port',
|
||||||
|
name='switch',
|
||||||
|
),
|
||||||
|
migrations.RenameField('Port', 'new_switch', 'switch')
|
||||||
|
]
|
18
topologie/migrations/0042_transferswitch.py
Normal file
18
topologie/migrations/0042_transferswitch.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2017-12-31 19:53
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0041_transferportsw'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Switch',
|
||||||
|
),
|
||||||
|
]
|
16
topologie/migrations/0043_renamenewswitch.py
Normal file
16
topologie/migrations/0043_renamenewswitch.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2017-12-31 19:53
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0042_transferswitch'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameModel(old_name='NewSwitch', new_name='Switch'),
|
||||||
|
]
|
|
@ -156,7 +156,7 @@ class Borne(Interface):
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
|
||||||
class Switch(models.Model):
|
class Switch(Interface):
|
||||||
""" Definition d'un switch. Contient un nombre de ports (number),
|
""" Definition d'un switch. Contient un nombre de ports (number),
|
||||||
un emplacement (location), un stack parent (optionnel, stack)
|
un emplacement (location), un stack parent (optionnel, stack)
|
||||||
et un id de membre dans le stack (stack_member_id)
|
et un id de membre dans le stack (stack_member_id)
|
||||||
|
@ -170,13 +170,9 @@ class Switch(models.Model):
|
||||||
id_max de la stack parente"""
|
id_max de la stack parente"""
|
||||||
PRETTY_NAME = "Switch / Commutateur"
|
PRETTY_NAME = "Switch / Commutateur"
|
||||||
|
|
||||||
switch_interface = models.OneToOneField(
|
|
||||||
'machines.Interface',
|
|
||||||
on_delete=models.CASCADE
|
|
||||||
)
|
|
||||||
location = models.CharField(max_length=255)
|
location = models.CharField(max_length=255)
|
||||||
number = models.PositiveIntegerField()
|
number = models.PositiveIntegerField()
|
||||||
details = models.CharField(max_length=255, blank=True)
|
|
||||||
stack = models.ForeignKey(
|
stack = models.ForeignKey(
|
||||||
'topologie.Stack',
|
'topologie.Stack',
|
||||||
blank=True,
|
blank=True,
|
||||||
|
@ -194,7 +190,7 @@ class Switch(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('stack', 'stack_member_id')
|
unique_together = ('stack', 'stack_member_id')
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_switch", "Peut voir un objet switch"),
|
("view_newswitch", "Peut voir un objet switch"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(switch_id, *args, **kwargs):
|
def get_instance(switch_id, *args, **kwargs):
|
||||||
|
@ -224,8 +220,8 @@ class Switch(models.Model):
|
||||||
return False, u"Vous n'avez pas le droit de voir les switch"
|
return False, u"Vous n'avez pas le droit de voir les switch"
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def __str__(self):
|
# def __str__(self):
|
||||||
return self.location + ' ' + str(self.switch_interface)
|
# return self.location + ' ' + str(self.switch_interface)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
""" Verifie que l'id stack est dans le bon range"""
|
""" Verifie que l'id stack est dans le bon range"""
|
||||||
|
@ -421,7 +417,7 @@ class Port(models.Model):
|
||||||
|
|
||||||
def get_instance(port_id, *args, **kwargs):
|
def get_instance(port_id, *args, **kwargs):
|
||||||
return Port.objects\
|
return Port.objects\
|
||||||
.select_related('switch__switch_interface__domain__extension')\
|
.select_related('switch__domain__extension')\
|
||||||
.select_related('machine_interface__domain__extension')\
|
.select_related('machine_interface__domain__extension')\
|
||||||
.select_related('machine_interface__switch')\
|
.select_related('machine_interface__switch')\
|
||||||
.select_related('room')\
|
.select_related('room')\
|
||||||
|
|
|
@ -46,10 +46,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a title="Configuer" href="{% url 'topologie:index-port' switch.pk %}">
|
<a title="Configuer" href="{% url 'topologie:index-port' switch.pk %}">
|
||||||
{{switch.switch_interface}}
|
{{switch}}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{switch.switch_interface.ipv4}}</td>
|
<td>{{switch.ipv4}}</td>
|
||||||
<td>{{switch.location}}</td>
|
<td>{{switch.location}}</td>
|
||||||
<td>{{switch.number}}</td>
|
<td>{{switch.number}}</td>
|
||||||
<td>{{switch.stack.name}}</td>
|
<td>{{switch.stack.name}}</td>
|
||||||
|
@ -62,7 +62,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% include 'buttons/edit.html' with href='topologie:edit-switch' id=switch.pk %}
|
{% include 'buttons/edit.html' with href='topologie:edit-switch' id=switch.pk %}
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% can_delete switch %}
|
{% can_delete switch %}
|
||||||
{% include 'buttons/suppr.html' with href='machines:del-interface' id=switch.switch_interface.id %}
|
{% include 'buttons/suppr.html' with href='machines:del-interface' id=switch.id %}
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% can_create Port %}
|
{% can_create Port %}
|
||||||
{% include 'buttons/add.html' with href='topologie:create-ports' id=switch.pk desc='Création de ports'%}
|
{% include 'buttons/add.html' with href='topologie:create-ports' id=switch.pk desc='Création de ports'%}
|
||||||
|
|
|
@ -32,44 +32,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% if topoform %}
|
{% if topoform %}
|
||||||
{% bootstrap_form_errors topoform %}
|
{% bootstrap_form_errors topoform %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if machineform %}
|
|
||||||
{% bootstrap_form_errors machineform %}
|
|
||||||
{% endif %}
|
|
||||||
{% if interfaceform %}
|
|
||||||
{% bootstrap_form_errors interfaceform %}
|
|
||||||
{% endif %}
|
|
||||||
{% if domainform %}
|
|
||||||
{% bootstrap_form_errors domainform %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% if id_switch %}
|
|
||||||
<a class="btn btn-primary" href="{% url "topologie:index-port" id_switch %}" role="button">{% bootstrap_icon "list" %} Aller à la liste des ports</a>
|
<a class="btn btn-primary" href="{% url "topologie:index-port" id_switch %}" role="button">{% bootstrap_icon "list" %} Aller à la liste des ports</a>
|
||||||
{% endif %}
|
|
||||||
<form class="form" method="post">
|
<form class="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if topoform %}
|
{% if topoform %}
|
||||||
<h3>Réglage spécifiques du switch</h3>
|
<h3>Réglage spécifiques du switch</h3>
|
||||||
{% massive_bootstrap_form topoform 'switch_interface' %}
|
{% massive_bootstrap_form topoform 'switch_interface' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if machineform %}
|
{% bootstrap_button "Créer" button_type="submit" icon="ok" %}
|
||||||
<h3>Réglages généraux de la machine associée au switch</h3>
|
|
||||||
{% massive_bootstrap_form machineform 'user' %}
|
|
||||||
{% endif %}
|
|
||||||
{% if interfaceform %}
|
|
||||||
<h3>Réglages généraux de l'interface associée au switch</h3>
|
|
||||||
{% if i_mbf_param %}
|
|
||||||
{% massive_bootstrap_form interfaceform 'ipv4,machine' mbf_param=i_mbf_param %}
|
|
||||||
{% else %}
|
|
||||||
{% massive_bootstrap_form interfaceform 'ipv4,machine' %}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% if domainform %}
|
|
||||||
<h3>Nom de la machine</h3>
|
|
||||||
{% bootstrap_form domainform %}
|
|
||||||
{% endif %}
|
|
||||||
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="ok" %}
|
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% load bootstrap3 %}
|
{% load bootstrap3 %}
|
||||||
{% load massive_bootstrap_form %}
|
{% load massive_bootstrap_form %}
|
||||||
|
|
||||||
{% block title %}Création et modification d'une borne{% endblock %}
|
{% block title %}Création et modification d'un objet topologie{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if topoform %}
|
{% if topoform %}
|
||||||
|
@ -44,11 +44,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<form class="form" method="post">
|
<form class="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if topoform %}
|
{% if topoform %}
|
||||||
<h3>Réglage spécifiques de la borne</h3>
|
<h3>Réglage spécifiques du {{ device }}</h3>
|
||||||
{% massive_bootstrap_form topoform 'ipv4,machine' mbf_param=i_mbf_param%}
|
{% massive_bootstrap_form topoform 'ipv4,machine' mbf_param=i_mbf_param%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if machineform %}
|
{% if machineform %}
|
||||||
<h3>Réglages généraux de la machine associée à la borne</h3>
|
<h3>Réglages généraux de la machine associée au {{ device }}</h3>
|
||||||
{% massive_bootstrap_form machineform 'user' %}
|
{% massive_bootstrap_form machineform 'user' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if domainform %}
|
{% if domainform %}
|
|
@ -92,9 +92,9 @@ from preferences.models import AssoOption, GeneralOption
|
||||||
def index(request):
|
def index(request):
|
||||||
""" Vue d'affichage de tous les swicthes"""
|
""" Vue d'affichage de tous les swicthes"""
|
||||||
switch_list = Switch.objects\
|
switch_list = Switch.objects\
|
||||||
.select_related('switch_interface__domain__extension')\
|
.select_related('domain__extension')\
|
||||||
.select_related('switch_interface__ipv4')\
|
.select_related('ipv4')\
|
||||||
.select_related('switch_interface__domain')\
|
.select_related('domain')\
|
||||||
.select_related('stack')
|
.select_related('stack')
|
||||||
switch_list = SortTable.sort(
|
switch_list = SortTable.sort(
|
||||||
switch_list,
|
switch_list,
|
||||||
|
@ -128,7 +128,7 @@ def index_port(request, switch, switch_id):
|
||||||
.select_related('machine_interface__domain__extension')\
|
.select_related('machine_interface__domain__extension')\
|
||||||
.select_related('machine_interface__machine__user')\
|
.select_related('machine_interface__machine__user')\
|
||||||
.select_related(
|
.select_related(
|
||||||
'related__switch__switch_interface__domain__extension'
|
'related__switch__domain__extension'
|
||||||
)\
|
)\
|
||||||
.select_related('switch')
|
.select_related('switch')
|
||||||
port_list = SortTable.sort(
|
port_list = SortTable.sort(
|
||||||
|
@ -203,7 +203,7 @@ def index_borne(request):
|
||||||
def index_stack(request):
|
def index_stack(request):
|
||||||
"""Affichage de la liste des stacks (affiche l'ensemble des switches)"""
|
"""Affichage de la liste des stacks (affiche l'ensemble des switches)"""
|
||||||
stack_list = Stack.objects\
|
stack_list = Stack.objects\
|
||||||
.prefetch_related('switch_set__switch_interface__domain__extension')
|
.prefetch_related('switch_set__domain__extension')
|
||||||
stack_list = SortTable.sort(
|
stack_list = SortTable.sort(
|
||||||
stack_list,
|
stack_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
@ -381,19 +381,18 @@ def new_switch(request):
|
||||||
""" Creation d'un switch. Cree en meme temps l'interface et la machine
|
""" Creation d'un switch. Cree en meme temps l'interface et la machine
|
||||||
associée. Vue complexe. Appelle successivement les 4 models forms
|
associée. Vue complexe. Appelle successivement les 4 models forms
|
||||||
adaptés : machine, interface, domain et switch"""
|
adaptés : machine, interface, domain et switch"""
|
||||||
switch = NewSwitchForm(request.POST or None)
|
switch = NewSwitchForm(
|
||||||
|
request.POST or None,
|
||||||
|
user=request.user
|
||||||
|
)
|
||||||
machine = NewMachineForm(
|
machine = NewMachineForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
user=request.user
|
user=request.user
|
||||||
)
|
)
|
||||||
interface = AddInterfaceForm(
|
|
||||||
request.POST or None,
|
|
||||||
user=request.user
|
|
||||||
)
|
|
||||||
domain = DomainForm(
|
domain = DomainForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
)
|
)
|
||||||
if switch.is_valid() and machine.is_valid() and interface.is_valid():
|
if switch.is_valid() and machine.is_valid():
|
||||||
user = AssoOption.get_cached_value('utilisateur_asso')
|
user = AssoOption.get_cached_value('utilisateur_asso')
|
||||||
if not user:
|
if not user:
|
||||||
messages.error(request, "L'user association n'existe pas encore,\
|
messages.error(request, "L'user association n'existe pas encore,\
|
||||||
|
@ -401,38 +400,34 @@ def new_switch(request):
|
||||||
return redirect(reverse('topologie:index'))
|
return redirect(reverse('topologie:index'))
|
||||||
new_machine = machine.save(commit=False)
|
new_machine = machine.save(commit=False)
|
||||||
new_machine.user = user
|
new_machine.user = user
|
||||||
new_interface = interface.save(commit=False)
|
|
||||||
new_switch_instance = switch.save(commit=False)
|
new_switch_instance = switch.save(commit=False)
|
||||||
new_domain_instance = domain.save(commit=False)
|
domain.instance.interface_parent = new_switch_instance
|
||||||
with transaction.atomic(), reversion.create_revision():
|
if domain.is_valid():
|
||||||
new_machine.save()
|
new_domain_instance = domain.save(commit=False)
|
||||||
reversion.set_user(request.user)
|
with transaction.atomic(), reversion.create_revision():
|
||||||
reversion.set_comment("Création")
|
new_machine.save()
|
||||||
new_interface.machine = new_machine
|
reversion.set_user(request.user)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
reversion.set_comment("Création")
|
||||||
new_interface.save()
|
new_switch_instance.machine = new_machine
|
||||||
reversion.set_user(request.user)
|
with transaction.atomic(), reversion.create_revision():
|
||||||
reversion.set_comment("Création")
|
new_switch_instance.save()
|
||||||
new_domain_instance.interface_parent = new_interface
|
reversion.set_user(request.user)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
reversion.set_comment("Création")
|
||||||
new_domain_instance.save()
|
new_domain_instance.interface_parent = new_switch_instance
|
||||||
reversion.set_user(request.user)
|
with transaction.atomic(), reversion.create_revision():
|
||||||
reversion.set_comment("Création")
|
new_domain_instance.save()
|
||||||
new_switch_instance.switch_interface = new_interface
|
reversion.set_user(request.user)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
reversion.set_comment("Création")
|
||||||
new_switch_instance.save()
|
messages.success(request, "Le switch a été créé")
|
||||||
reversion.set_user(request.user)
|
return redirect(reverse('topologie:index'))
|
||||||
reversion.set_comment("Création")
|
i_mbf_param = generate_ipv4_mbf_param(switch, False)
|
||||||
messages.success(request, "Le switch a été créé")
|
|
||||||
return redirect(reverse('topologie:index'))
|
|
||||||
i_mbf_param = generate_ipv4_mbf_param( interface, False)
|
|
||||||
return form({
|
return form({
|
||||||
'topoform': switch,
|
'topoform': switch,
|
||||||
'machineform': machine,
|
'machineform': machine,
|
||||||
'interfaceform': interface,
|
|
||||||
'domainform': domain,
|
'domainform': domain,
|
||||||
'i_mbf_param': i_mbf_param
|
'i_mbf_param': i_mbf_param,
|
||||||
}, 'topologie/switch.html', request)
|
'device' : 'switch',
|
||||||
|
}, 'topologie/topo_more.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -470,7 +465,6 @@ def create_ports(request, switch_id):
|
||||||
'topologie:index-port',
|
'topologie:index-port',
|
||||||
kwargs={'switch_id':switch_id}
|
kwargs={'switch_id':switch_id}
|
||||||
))
|
))
|
||||||
|
|
||||||
return form({'id_switch': switch_id, 'topoform': port_form}, 'topologie/switch.html', request)
|
return form({'id_switch': switch_id, 'topoform': port_form}, 'topologie/switch.html', request)
|
||||||
|
|
||||||
|
|
||||||
|
@ -480,24 +474,21 @@ def edit_switch(request, switch, switch_id):
|
||||||
""" Edition d'un switch. Permet de chambre nombre de ports,
|
""" Edition d'un switch. Permet de chambre nombre de ports,
|
||||||
place dans le stack, interface et machine associée"""
|
place dans le stack, interface et machine associée"""
|
||||||
|
|
||||||
switch_form = EditSwitchForm(request.POST or None, instance=switch)
|
switch_form = EditSwitchForm(
|
||||||
machine_form = EditMachineForm(
|
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=switch.switch_interface.machine,
|
instance=switch,
|
||||||
user=request.user
|
user=request.user
|
||||||
)
|
)
|
||||||
interface_form = EditInterfaceForm(
|
machine_form = EditMachineForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=switch.switch_interface,
|
instance=switch.machine,
|
||||||
user=request.user
|
user=request.user
|
||||||
)
|
)
|
||||||
domain_form = DomainForm(
|
domain_form = DomainForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=switch.switch_interface.domain
|
instance=switch.domain
|
||||||
)
|
)
|
||||||
if switch_form.is_valid() and machine_form.is_valid()\
|
if switch_form.is_valid() and machine_form.is_valid():
|
||||||
and interface_form.is_valid():
|
|
||||||
new_interface = interface_form.save(commit=False)
|
|
||||||
new_machine = machine_form.save(commit=False)
|
new_machine = machine_form.save(commit=False)
|
||||||
new_switch_instance = switch_form.save(commit=False)
|
new_switch_instance = switch_form.save(commit=False)
|
||||||
new_domain = domain_form.save(commit=False)
|
new_domain = domain_form.save(commit=False)
|
||||||
|
@ -510,10 +501,10 @@ def edit_switch(request, switch, switch_id):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
new_interface.save()
|
new_switch_instance.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
||||||
field for field in interface_form.changed_data)
|
field for field in switch_form.changed_data)
|
||||||
)
|
)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
new_domain.save()
|
new_domain.save()
|
||||||
|
@ -521,23 +512,17 @@ def edit_switch(request, switch, switch_id):
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
||||||
field for field in domain_form.changed_data)
|
field for field in domain_form.changed_data)
|
||||||
)
|
)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
|
||||||
new_switch_instance.save()
|
|
||||||
reversion.set_user(request.user)
|
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
|
||||||
field for field in switch_form.changed_data)
|
|
||||||
)
|
|
||||||
messages.success(request, "Le switch a bien été modifié")
|
messages.success(request, "Le switch a bien été modifié")
|
||||||
return redirect(reverse('topologie:index'))
|
return redirect(reverse('topologie:index'))
|
||||||
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
|
i_mbf_param = generate_ipv4_mbf_param(switch_form, False )
|
||||||
return form({
|
return form({
|
||||||
'id_switch': switch_id,
|
'id_switch': switch_id,
|
||||||
'topoform': switch_form,
|
'topoform': switch_form,
|
||||||
'machineform': machine_form,
|
'machineform': machine_form,
|
||||||
'interfaceform': interface_form,
|
|
||||||
'domainform': domain_form,
|
'domainform': domain_form,
|
||||||
'i_mbf_param': i_mbf_param
|
'i_mbf_param': i_mbf_param,
|
||||||
}, 'topologie/switch.html', request)
|
'device' : 'switch',
|
||||||
|
}, 'topologie/topo_more.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -590,8 +575,9 @@ def new_borne(request):
|
||||||
'topoform': borne,
|
'topoform': borne,
|
||||||
'machineform': machine,
|
'machineform': machine,
|
||||||
'domainform': domain,
|
'domainform': domain,
|
||||||
'i_mbf_param': i_mbf_param
|
'i_mbf_param': i_mbf_param,
|
||||||
}, 'topologie/borne.html', request)
|
'device' : 'wifi ap',
|
||||||
|
}, 'topologie/topo_more.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -649,8 +635,9 @@ def edit_borne(request, borne, borne_id):
|
||||||
'topoform': borne_form,
|
'topoform': borne_form,
|
||||||
'machineform': machine_form,
|
'machineform': machine_form,
|
||||||
'domainform': domain_form,
|
'domainform': domain_form,
|
||||||
'i_mbf_param': i_mbf_param
|
'i_mbf_param': i_mbf_param,
|
||||||
}, 'topologie/borne.html', request)
|
'device' : 'wifi ap',
|
||||||
|
}, 'topologie/topo_more.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in a new issue