8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

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

This commit is contained in:
Gabriel Detraz 2017-08-09 06:08:41 +02:00 committed by root
parent 014cd80960
commit b1a0e64a7b
5 changed files with 40 additions and 7 deletions

View file

@ -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)

View file

@ -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'),
),
]

View file

@ -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

View file

@ -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 %}

View file

@ -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