mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Ajoute le support des alias dns
This commit is contained in:
parent
176fcbbca6
commit
51c725f36f
3 changed files with 43 additions and 2 deletions
|
@ -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)
|
||||
|
|
30
machines/migrations/0030_auto_20161118_1730.py
Normal file
30
machines/migrations/0030_auto_20161118_1730.py
Normal 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')]),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue