Commit b1a0e64a authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Bug fix pour interfaces mutliples + temps maximum génération forcée

parent 014cd809
......@@ -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)
......
# -*- 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'),
),
]
......@@ -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
......
......@@ -26,7 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<thead>
<tr>
<th>Nom du service</th>
<th>Temps minimum de régénération</th>
<th>Temps minimum avant nouvelle régénération</th>
<th>Temps avant nouvelle génération obligatoire (max)</th>
<th>Serveurs inclus</th>
<th></th>
<th></th>
......@@ -35,7 +36,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for service in service_list %}
<tr>
<td>{{ service.service_type }}</td>
<td>{{ service.time_regen }}</td>
<td>{{ service.min_time_regen }}</td>
<td>{{ service.regular_time_regen }}</td>
<td>{% for serv in service.servers.all %}{{ serv }}, {% endfor %}</td>
<td class="text-right">
{% if is_infra %}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment