From eded66beb07a3049e2bdaeb931a160ee7b750ba1 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 9 Jul 2018 21:05:50 +0200 Subject: [PATCH] =?UTF-8?q?Gestion=20des=20switchs=20=C3=A0=20provisioner?= =?UTF-8?q?=20automatiquement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preferences/forms.py | 18 +++++++++++++++-- preferences/models.py | 1 + .../0064_switch_automatic_provision.py | 20 +++++++++++++++++++ topologie/models.py | 4 ++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 topologie/migrations/0064_switch_automatic_provision.py diff --git a/preferences/forms.py b/preferences/forms.py index 81a12261..5933107c 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -45,7 +45,6 @@ from .models import ( ) from topologie.models import Switch - class EditOptionalUserForm(ModelForm): """Formulaire d'édition des options de l'user. (solde, telephone..)""" class Meta: @@ -96,7 +95,14 @@ class EditOptionalMachineForm(ModelForm): class EditOptionalTopologieForm(ModelForm): - """Options de topologie, formulaire d'edition (vlan par default etc)""" + """Options de topologie, formulaire d'edition (vlan par default etc) + On rajoute un champ automatic provision switchs pour gérer facilement + l'ajout de switchs au provisionning automatique""" + automatic_provision_switchs = forms.ModelMultipleChoiceField( + Switch.objects.all(), + required=False + ) + class Meta: model = OptionalTopologie fields = '__all__' @@ -114,6 +120,14 @@ class EditOptionalTopologieForm(ModelForm): self.fields['vlan_decision_nok'].label = _("VLAN for machines rejected" " by RADIUS") + self.initial['automatic_provision_switchs'] = Switch.objects.filter(automatic_provision=True) + + def save(self, commit=True): + instance = super().save(commit) + Switch.objects.all().update(automatic_provision=False) + self.cleaned_data['automatic_provision_switchs'].update(automatic_provision=True) + return instance + class EditGeneralOptionForm(ModelForm): """Options générales (affichages de résultats de recherche, etc)""" diff --git a/preferences/models.py b/preferences/models.py index 5c2d58ba..31d382aa 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -34,6 +34,7 @@ from django.forms import ValidationError from django.utils.translation import ugettext_lazy as _ import machines.models + from re2o.mixins import AclMixin from re2o.aes_field import AESEncryptedField from datetime import timedelta diff --git a/topologie/migrations/0064_switch_automatic_provision.py b/topologie/migrations/0064_switch_automatic_provision.py new file mode 100644 index 00000000..d8d280cf --- /dev/null +++ b/topologie/migrations/0064_switch_automatic_provision.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-09-20 16:28 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0063_auto_20180919_2225'), + ] + + operations = [ + migrations.AddField( + model_name='switch', + name='automatic_provision', + field=models.BooleanField(default=False, help_text='Provision automatique de ce switch'), + ), + ] diff --git a/topologie/models.py b/topologie/models.py index 28216819..840d9c70 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -247,6 +247,10 @@ class Switch(AclMixin, Machine): on_delete=models.PROTECT, help_text="Identifiant de management de ce switch" ) + automatic_provision = models.BooleanField( + default=False, + help_text='Provision automatique de ce switch', + ) class Meta: unique_together = ('stack', 'stack_member_id')