From b1a0e64a7b74720c4a2e6b903efef0c0fdb80182 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 9 Aug 2017 06:08:41 +0200 Subject: [PATCH] =?UTF-8?q?Bug=20fix=20pour=20interfaces=20mutliples=20+?= =?UTF-8?q?=20temps=20maximum=20g=C3=A9n=C3=A9ration=20forc=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/admin.py | 2 +- .../migrations/0047_auto_20170809_0606.py | 30 +++++++++++++++++++ machines/models.py | 5 ++-- machines/templates/machines/aff_service.html | 6 ++-- machines/views.py | 4 +-- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 machines/migrations/0047_auto_20170809_0606.py diff --git a/machines/admin.py b/machines/admin.py index 8c0ef947..147fca0f 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -54,7 +54,7 @@ class DomainAdmin(VersionAdmin): list_display = ('interface_parent', 'name', 'extension', 'cname') class ServiceAdmin(VersionAdmin): - list_display = ('service_type', 'time_regen') + list_display = ('service_type', 'min_time_regen', 'regular_time_regen') admin.site.register(Machine, MachineAdmin) admin.site.register(MachineType, MachineTypeAdmin) diff --git a/machines/migrations/0047_auto_20170809_0606.py b/machines/migrations/0047_auto_20170809_0606.py new file mode 100644 index 00000000..65cd3d1f --- /dev/null +++ b/machines/migrations/0047_auto_20170809_0606.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-08-09 04:06 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0046_auto_20170808_1423'), + ] + + operations = [ + migrations.RemoveField( + model_name='service', + name='time_regen', + ), + migrations.AddField( + model_name='service', + name='min_time_regen', + field=models.DurationField(default=datetime.timedelta(0, 60), help_text='Temps minimal avant nouvelle génération du service'), + ), + migrations.AddField( + model_name='service', + name='regular_time_regen', + field=models.DurationField(default=datetime.timedelta(0, 3600), help_text='Temps maximal avant nouvelle génération du service'), + ), + ] diff --git a/machines/models.py b/machines/models.py index 69b6f825..bc89e3c6 100644 --- a/machines/models.py +++ b/machines/models.py @@ -275,7 +275,8 @@ class IpList(models.Model): class Service(models.Model): """ Definition d'un service (dhcp, dns, etc)""" service_type = models.CharField(max_length=255, blank=True, unique=True) - time_regen = models.DurationField(default=timedelta(minutes=1)) + min_time_regen = models.DurationField(default=timedelta(minutes=1), help_text="Temps minimal avant nouvelle génération du service") + regular_time_regen = models.DurationField(default=timedelta(hours=1), help_text="Temps maximal avant nouvelle génération du service") servers = models.ManyToManyField('Interface', through='Service_link') def ask_regen(self): @@ -320,7 +321,7 @@ class Service_link(models.Model): def need_regen(self): """ Décide si le temps minimal écoulé est suffisant pour provoquer une régénération de service""" - if self.asked_regen and (self.last_regen + self.service.time_regen) < timezone.now(): + if (self.asked_regen and (self.last_regen + self.service.min_time_regen) < timezone.now()) or (self.last_regen + self.service.regular_time_regen) < timezone.now(): return True else: return False diff --git a/machines/templates/machines/aff_service.html b/machines/templates/machines/aff_service.html index f7f2b3f8..47bfee25 100644 --- a/machines/templates/machines/aff_service.html +++ b/machines/templates/machines/aff_service.html @@ -26,7 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc., Nom du service - Temps minimum de régénération + Temps minimum avant nouvelle régénération + Temps avant nouvelle génération obligatoire (max) Serveurs inclus @@ -35,7 +36,8 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for service in service_list %} {{ service.service_type }} - {{ service.time_regen }} + {{ service.min_time_regen }} + {{ service.regular_time_regen }} {% for serv in service.servers.all %}{{ serv }}, {% endfor %} {% if is_infra %} diff --git a/machines/views.py b/machines/views.py index f3a77d9e..a6c63d4e 100644 --- a/machines/views.py +++ b/machines/views.py @@ -816,9 +816,9 @@ def service_servers(request): @login_required @permission_required('serveur') def regen_achieved(request): - obj = Service_link.objects.filter(service__in=Service.objects.filter(service_type=request.POST['service']), server__in=Interface.objects.filter(domain=Domain.objects.filter(name=request.POST['server']))) + obj = Service_link.objects.filter(service__in=Service.objects.filter(service_type=request.POST['service']), server__in=Interface.objects.filter(domain__in=Domain.objects.filter(name=request.POST['server']))) if obj: - obj[0].done_regen() + obj.first().done_regen() return HttpReponse("Ok") @csrf_exempt