diff --git a/re2o/utils.py b/re2o/utils.py index fcb4f8a8..32be2432 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -213,8 +213,8 @@ class SortTable: 'default': ['-date'] } TOPOLOGIE_INDEX = { - 'switch_dns': ['switch_interface__domain__name'], - 'switch_ip': ['switch_interface__ipv4__ipv4'], + 'switch_dns': ['interface__domain__name'], + 'switch_ip': ['interface__ipv4__ipv4'], 'switch_loc': ['location'], 'switch_ports': ['number'], 'switch_stack': ['stack__name'], diff --git a/topologie/forms.py b/topologie/forms.py index 5032d15e..0337dc60 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -130,18 +130,18 @@ class EditAccessPointForm(EditMachineForm): fields = '__all__' -class EditSwitchForm(EditInterfaceForm): +class EditSwitchForm(EditMachineForm): """Permet d'éditer un switch : nom et nombre de ports""" class Meta: model = Switch - fields = ['machine', 'type', 'ipv4', 'mac_address', 'details', 'location', 'number', 'stack', 'stack_member_id'] + fields = '__all__' -class NewSwitchForm(EditInterfaceForm): +class NewSwitchForm(NewMachineForm): """Permet de créer un switch : emplacement, paramètres machine, membre d'un stack (option), nombre de ports (number)""" class Meta(EditSwitchForm.Meta): - fields = ['type', 'ipv4', 'mac_address', 'details', 'location', 'number', 'stack', 'stack_member_id'] + fields = ['name', 'location', 'number', 'stack', 'stack_member_id'] class EditRoomForm(ModelForm): diff --git a/topologie/migrations/0049_switchs_machine.py b/topologie/migrations/0049_switchs_machine.py new file mode 100644 index 00000000..040ab599 --- /dev/null +++ b/topologie/migrations/0049_switchs_machine.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-03-23 01:18 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0048_ap_machine'), + ] + + + + operations = [ + migrations.CreateModel( + name='NewSw', + fields=[ + ('machine_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='machines.Machine')), + ('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.machine',), + ), + ] diff --git a/topologie/migrations/0050_port_new_switch.py b/topologie/migrations/0050_port_new_switch.py new file mode 100644 index 00000000..b03a8ee5 --- /dev/null +++ b/topologie/migrations/0050_port_new_switch.py @@ -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', '0049_switchs_machine'), + ] + + operations = [ + migrations.AddField( + model_name='port', + name='new_sw', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ports', to='topologie.NewSw'), + ), + ] diff --git a/topologie/migrations/0051_transferports.py b/topologie/migrations/0051_transferports.py new file mode 100644 index 00000000..2a67e6be --- /dev/null +++ b/topologie/migrations/0051_transferports.py @@ -0,0 +1,33 @@ +# -*- 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', '0050_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", "NewSw") + port_list = port.objects.using(db_alias).all() + for p in port_list: + p.new_sw = switch.objects.filter(machine_ptr=p.switch.machine).first() + p.save() + + def untransfer_port(apps, schema_editor): + return + + operations = [ + migrations.RunPython(transfer_port, untransfer_port), + migrations.RemoveField( + model_name='port', + name='switch', + ), + migrations.RenameField('Port', 'new_sw', 'switch') + ] diff --git a/topologie/migrations/0052_switchs_machine.py b/topologie/migrations/0052_switchs_machine.py new file mode 100644 index 00000000..b32b3c18 --- /dev/null +++ b/topologie/migrations/0052_switchs_machine.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-03-23 01:18 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0051_transferports'), + ] + + def transfer_sw(apps, schema_editor): + db_alias = schema_editor.connection.alias + newswitch = apps.get_model("topologie", "NewSw") + switch = apps.get_model("topologie", "Switch") + machine = apps.get_model("machines", "Machine") + 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.machine_ptr_id = sw.interface_ptr.machine.pk + new_sw.__dict__.update(sw.interface_ptr.machine.__dict__) + new_sw.save() + + def untransfer_sw(apps, schema_editor): + return + + + operations = [ + migrations.RunPython(transfer_sw, untransfer_sw), + migrations.DeleteModel( + name='Switch', + ), + ] diff --git a/topologie/migrations/0053_finalsw.py b/topologie/migrations/0053_finalsw.py new file mode 100644 index 00000000..561e0dc3 --- /dev/null +++ b/topologie/migrations/0053_finalsw.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-03-23 01:18 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0052_switchs_machine'), + ] + + + + operations = [ + migrations.RenameModel( + old_name='NewSw', + new_name='Switch', + ), + ] diff --git a/topologie/models.py b/topologie/models.py index 76b24652..fd4b1d3d 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -156,7 +156,7 @@ class AccessPoint(Machine): return True, None -class Switch(Interface): +class Switch(Machine): """ Definition d'un switch. Contient un nombre de ports (number), un emplacement (location), un stack parent (optionnel, stack) et un id de membre dans le stack (stack_member_id) diff --git a/topologie/templates/topologie/aff_switch.html b/topologie/templates/topologie/aff_switch.html index c8c9e6e0..948cd209 100644 --- a/topologie/templates/topologie/aff_switch.html +++ b/topologie/templates/topologie/aff_switch.html @@ -46,10 +46,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,