mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Ajout et transfert des anciennes données vers le nouveau système de profil de ports
This commit is contained in:
parent
d123ce920d
commit
447919a2af
7 changed files with 129 additions and 19 deletions
|
@ -80,8 +80,8 @@ class EditPortForm(FormRevMixin, ModelForm):
|
|||
optimiser le temps de chargement avec select_related (vraiment
|
||||
lent sans)"""
|
||||
class Meta(PortForm.Meta):
|
||||
fields = ['room', 'related', 'machine_interface', 'radius',
|
||||
'vlan_force', 'details']
|
||||
fields = ['room', 'related', 'machine_interface', 'custom_profil',
|
||||
'details']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
|
@ -109,8 +109,7 @@ class AddPortForm(FormRevMixin, ModelForm):
|
|||
'room',
|
||||
'machine_interface',
|
||||
'related',
|
||||
'radius',
|
||||
'vlan_force',
|
||||
'custom_profil',
|
||||
'details'
|
||||
]
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255, verbose_name='Name')),
|
||||
('profil_default', models.CharField(blank=True, choices=[('room', 'room'), ('accespoint', 'accesspoint'), ('uplink', 'uplink'), ('asso_machine', 'asso_machine')], max_length=32, null=True, unique=True, verbose_name='profil default')),
|
||||
('profil_default', models.CharField(blank=True, choices=[('room', 'room'), ('nothing', 'nothing'), ('accespoint', 'accesspoint'), ('uplink', 'uplink'), ('asso_machine', 'asso_machine')], max_length=32, null=True, unique=True, verbose_name='profil default')),
|
||||
('radius_type', models.CharField(choices=[('NO', 'NO'), ('802.1X', '802.1X'), ('MAC-radius', 'MAC-radius')], max_length=32, verbose_name='RADIUS type')),
|
||||
('radius_mode', models.CharField(choices=[('STRICT', 'STRICT'), ('COMMON', 'COMMON')], default='COMMON', max_length=32, verbose_name='RADIUS mode')),
|
||||
('speed', models.CharField(choices=[('10-half', '10-half'), ('100-half', '100-half'), ('10-full', '10-full'), ('100-full', '100-full'), ('1000-full', '1000-full'), ('auto', 'auto'), ('auto-10', 'auto-10'), ('auto-100', 'auto-100')], default='auto', help_text='Mode de transmission et vitesse du port', max_length=32, verbose_name='Speed')),
|
||||
|
|
21
topologie/migrations/0063_port_custom_profil.py
Normal file
21
topologie/migrations/0063_port_custom_profil.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-06-28 07:49
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('topologie', '0062_auto_20180627_0123'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='port',
|
||||
name='custom_profil',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='topologie.PortProfile'),
|
||||
),
|
||||
]
|
57
topologie/migrations/0064_createprofil.py
Normal file
57
topologie/migrations/0064_createprofil.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# -*- 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', '0063_port_custom_profil'),
|
||||
]
|
||||
|
||||
def transfer_profil(apps, schema_editor):
|
||||
db_alias = schema_editor.connection.alias
|
||||
port = apps.get_model("topologie", "Port")
|
||||
profil = apps.get_model("topologie", "PortProfile")
|
||||
vlan = apps.get_model("machines", "Vlan")
|
||||
port_list = port.objects.using(db_alias).all()
|
||||
profil_nothing = profil.objects.using(db_alias).create(name='nothing', profil_default='nothing', radius_type='NO')
|
||||
profil_uplink = profil.objects.using(db_alias).create(name='uplink', profil_default='uplink', radius_type='NO')
|
||||
profil_machine = profil.objects.using(db_alias).create(name='asso_machine', profil_default='asso_machine', radius_type='NO')
|
||||
profil_room = profil.objects.using(db_alias).create(name='room', profil_default='room', radius_type='NO')
|
||||
profil_borne = profil.objects.using(db_alias).create(name='accesspoint', profil_default='accesspoint', radius_type='NO')
|
||||
for vlan_instance in vlan.objects.using(db_alias).all():
|
||||
if port.objects.using(db_alias).filter(vlan_force=vlan_instance):
|
||||
custom_profil = profil.objects.using(db_alias).create(name='vlan-force-' + str(vlan_instance.vlan_id), radius_type='NO', vlan_untagged=vlan_instance)
|
||||
port.objects.using(db_alias).filter(vlan_force=vlan_instance).update(custom_profil=custom_profil)
|
||||
if port.objects.using(db_alias).filter(room__isnull=False).filter(radius='STRICT').count() > port.objects.using(db_alias).filter(room__isnull=False).filter(radius='NO').count() and port.objects.using(db_alias).filter(room__isnull=False).filter(radius='STRICT').count() > port.objects.using(db_alias).filter(room__isnull=False).filter(radius='COMMON').count():
|
||||
profil_room.radius_type = 'MAC-radius'
|
||||
profil_room.radius_mode = 'STRICT'
|
||||
common_profil = profil.objects.using(db_alias).create(name='mac-radius-common', radius_type='MAC-radius', radius_mode='COMMON')
|
||||
no_rad_profil = profil.objects.using(db_alias).create(name='no-radius', radius_type='NO')
|
||||
port.objects.using(db_alias).filter(room__isnull=False).filter(radius='COMMON').update(custom_profil=common_profil)
|
||||
port.objects.using(db_alias).filter(room__isnull=False).filter(radius='NO').update(custom_profil=no_rad_profil)
|
||||
elif port.objects.using(db_alias).filter(room__isnull=False).filter(radius='COMMON').count() > port.objects.using(db_alias).filter(room__isnull=False).filter(radius='NO').count() and port.objects.using(db_alias).filter(room__isnull=False).filter(radius='COMMON').count() > port.objects.using(db_alias).filter(room__isnull=False).filter(radius='STRICT').count():
|
||||
profil_room.radius_type = 'MAC-radius'
|
||||
profil_room.radius_mode = 'COMMON'
|
||||
strict_profil = profil.objects.using(db_alias).create(name='mac-radius-strict', radius_type='MAC-radius', radius_mode='STRICT')
|
||||
no_rad_profil = profil.objects.using(db_alias).create(name='no-radius', radius_type='NO')
|
||||
port.objects.using(db_alias).filter(room__isnull=False).filter(radius='STRICT').update(custom_profil=strict_profil)
|
||||
port.objects.using(db_alias).filter(room__isnull=False).filter(radius='NO').update(custom_profil=no_rad_profil)
|
||||
else:
|
||||
strict_profil = profil.objects.using(db_alias).create(name='mac-radius-strict', radius_type='MAC-radius', radius_mode='STRICT')
|
||||
common_profil = profil.objects.using(db_alias).create(name='mac-radius-common', radius_type='MAC-radius', radius_mode='COMMON')
|
||||
port.objects.using(db_alias).filter(room__isnull=False).filter(radius='STRICT').update(custom_profil=strict_profil)
|
||||
port.objects.using(db_alias).filter(room__isnull=False).filter(radius='NO').update(custom_profil=common_profil)
|
||||
profil_room.save()
|
||||
|
||||
|
||||
|
||||
def untransfer_profil(apps, schema_editor):
|
||||
return
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(transfer_profil, untransfer_profil),
|
||||
]
|
23
topologie/migrations/0065_auto_20180630_1703.py
Normal file
23
topologie/migrations/0065_auto_20180630_1703.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-06-30 15:03
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('topologie', '0064_createprofil'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='port',
|
||||
name='radius',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='port',
|
||||
name='vlan_force',
|
||||
),
|
||||
]
|
|
@ -366,12 +366,6 @@ class Port(AclMixin, RevMixin, models.Model):
|
|||
de forcer un port sur un vlan particulier. S'additionne à la politique
|
||||
RADIUS"""
|
||||
PRETTY_NAME = "Port de switch"
|
||||
STATES = (
|
||||
('NO', 'NO'),
|
||||
('STRICT', 'STRICT'),
|
||||
('BLOQ', 'BLOQ'),
|
||||
('COMMON', 'COMMON'),
|
||||
)
|
||||
|
||||
switch = models.ForeignKey(
|
||||
'Switch',
|
||||
|
@ -397,13 +391,13 @@ class Port(AclMixin, RevMixin, models.Model):
|
|||
blank=True,
|
||||
related_name='related_port'
|
||||
)
|
||||
radius = models.CharField(max_length=32, choices=STATES, default='NO')
|
||||
vlan_force = models.ForeignKey(
|
||||
'machines.Vlan',
|
||||
on_delete=models.SET_NULL,
|
||||
custom_profil = models.ForeignKey(
|
||||
'PortProfile',
|
||||
on_delete=models.PROTECT,
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
details = models.CharField(max_length=255, blank=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -412,6 +406,23 @@ class Port(AclMixin, RevMixin, models.Model):
|
|||
("view_port", "Peut voir un objet port"),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def get_port_profil(self):
|
||||
"""Return the config profil for this port"""
|
||||
if self.custom_profil:
|
||||
return custom_profil
|
||||
elif self.related:
|
||||
return PortProfil.objects.get(profil_default='uplink')
|
||||
elif self.machine_interface:
|
||||
if isinstance(self.machine_interface.machine, AccessPoint):
|
||||
return PortProfil.objects.get(profil_default='access_point')
|
||||
else:
|
||||
return PortProfil.objects.get(profil_default='asso_machine')
|
||||
elif self.room:
|
||||
return PortProfil.objects.get(profil_default='room')
|
||||
else:
|
||||
return PortProfil.objects.get(profil_default='nothing')
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls, portid, *_args, **kwargs):
|
||||
return (cls.objects
|
||||
|
@ -515,6 +526,7 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
|||
('accespoint', 'accesspoint'),
|
||||
('uplink', 'uplink'),
|
||||
('asso_machine', 'asso_machine'),
|
||||
('nothing', 'nothing'),
|
||||
)
|
||||
name = models.CharField(max_length=255, verbose_name=_("Name"))
|
||||
profil_default = models.CharField(
|
||||
|
|
|
@ -32,8 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<th>{% include "buttons/sort.html" with prefix='port' col='room' text='Room' %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='port' col='interface' text='Interface machine' %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='port' col='related' text='Related' %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='port' col='radius' text='Radius' %}</th>
|
||||
<th>{% include "buttons/sort.html" with prefix='port' col='vlan' text='Vlan forcé' %}</th>
|
||||
<th>Profil du port</th>
|
||||
<th>Détails</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
@ -66,8 +65,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% acl_end %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ port.radius }}</td>
|
||||
<td>{% if not port.vlan_force %}Aucun{% else %}{{ port.vlan_force }}{% endif %}</td>
|
||||
<td>{% if not port.custom_profil %}Par défaut{% else %}{{port.custom_profil}}{% endif %}</td>
|
||||
<td>{{ port.details }}</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'port' port.pk %}">
|
||||
|
|
Loading…
Reference in a new issue