Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

0064_createprofil.py 3.95 KB
Newer Older
1 2 3 4 5 6 7
# -*- 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


8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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()


45 46 47 48 49 50 51
class Migration(migrations.Migration):

    dependencies = [
        ('topologie', '0063_port_custom_profil'),
    ]

    operations = [
52
    migrations.RunPython(transfer_profil),
53
    ]