Commit 51c725f3 authored by chirac's avatar chirac

Ajoute le support des alias dns

parent 176fcbbc
......@@ -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)
......
# -*- 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')]),
),
]
......@@ -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
......
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