8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Ajoute le support des alias dns

This commit is contained in:
chirac 2016-11-18 17:36:30 +01:00
parent 176fcbbca6
commit 51c725f36f
3 changed files with 43 additions and 2 deletions

View file

@ -23,7 +23,7 @@ class InterfaceAdmin(VersionAdmin):
list_display = ('machine','type','dns','mac_address','ipv4','details')
class AliasAdmin(VersionAdmin):
list_display = ('interface_parent', 'alias')
list_display = ('interface_parent', 'alias', 'extension')
admin.site.register(Machine, MachineAdmin)
admin.site.register(MachineType, MachineTypeAdmin)

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('machines', '0029_iptype_domaine_range'),
]
operations = [
migrations.AddField(
model_name='alias',
name='extension',
field=models.ForeignKey(to='machines.Extension', default=1, on_delete=django.db.models.deletion.PROTECT),
preserve_default=False,
),
migrations.AlterField(
model_name='alias',
name='alias',
field=models.CharField(max_length=255, help_text='Obligatoire et unique, ne doit pas comporter de points'),
),
migrations.AlterUniqueTogether(
name='alias',
unique_together=set([('alias', 'extension')]),
),
]

View file

@ -67,6 +67,9 @@ class Interface(models.Model):
def clean(self, *args, **kwargs):
self.mac_address = str(EUI(self.mac_address)) or None
alias = Alias.objects.filter(alias=self.dns).filter(extension=self.ipv4.ip_type.extension)
if alias:
raise ValidationError("Impossible, le dns est déjà utilisé par un alias (%s)" % alias[0])
def __str__(self):
return self.dns
@ -75,7 +78,15 @@ class Alias(models.Model):
PRETTY_NAME = "Alias dns"
interface_parent = models.ForeignKey('Interface', on_delete=models.CASCADE)
alias = models.CharField(help_text="Obligatoire et unique, ne doit pas comporter de points", max_length=255, unique=True)
alias = models.CharField(help_text="Obligatoire et unique, ne doit pas comporter de points", max_length=255)
extension = models.ForeignKey('Extension', on_delete=models.PROTECT)
class Meta:
unique_together = ("alias", "extension")
def clean(self, *args, **kwargs):
if Interface.objects.filter(dns=self.alias).filter(ipv4=IpList.objects.filter(ip_type=IpType.objects.filter(extension=self.extension))):
raise ValidationError("Impossible d'ajouter l'alias, déjà utilisé par une machine")
def __str__(self):
return self.alias