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

Creation de domain, transfert

This commit is contained in:
chirac 2016-12-24 18:07:09 +01:00
parent cda4548981
commit 4379a4fcc5
7 changed files with 118 additions and 22 deletions

View file

@ -1,7 +1,7 @@
from django.contrib import admin from django.contrib import admin
from reversion.admin import VersionAdmin from reversion.admin import VersionAdmin
from .models import IpType, Machine, MachineType, Alias, IpList, Interface, Extension, Mx, Ns from .models import IpType, Machine, MachineType, Domain, IpList, Interface, Extension, Mx, Ns
class MachineAdmin(VersionAdmin): class MachineAdmin(VersionAdmin):
list_display = ('user','name','active') list_display = ('user','name','active')
@ -28,8 +28,8 @@ class IpListAdmin(VersionAdmin):
class InterfaceAdmin(VersionAdmin): class InterfaceAdmin(VersionAdmin):
list_display = ('machine','type','dns','mac_address','ipv4','details') list_display = ('machine','type','dns','mac_address','ipv4','details')
class AliasAdmin(VersionAdmin): class DomainAdmin(VersionAdmin):
list_display = ('interface_parent', 'alias', 'extension') list_display = ('interface_parent', 'name', 'extension', 'cname')
admin.site.register(Machine, MachineAdmin) admin.site.register(Machine, MachineAdmin)
admin.site.register(MachineType, MachineTypeAdmin) admin.site.register(MachineType, MachineTypeAdmin)
@ -39,4 +39,4 @@ admin.site.register(Mx, MxAdmin)
admin.site.register(Ns, NsAdmin) admin.site.register(Ns, NsAdmin)
admin.site.register(IpList, IpListAdmin) admin.site.register(IpList, IpListAdmin)
admin.site.register(Interface, InterfaceAdmin) admin.site.register(Interface, InterfaceAdmin)
admin.site.register(Alias, AliasAdmin) admin.site.register(Domain, DomainAdmin)

View file

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0034_iplist_need_infra'),
]
operations = [
migrations.RenameModel('Alias', 'Domain')
]

View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0035_auto_20161224_1201'),
]
operations = [
migrations.RenameField(
model_name='domain',
old_name='alias',
new_name='name',
),
migrations.AlterField(
model_name='domain',
name='interface_parent',
field=models.ForeignKey(to='machines.Interface', null=True, blank=True),
),
migrations.AlterUniqueTogether(
name='domain',
unique_together=set([('name', 'extension')]),
),
]

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0036_auto_20161224_1204'),
]
operations = [
migrations.AddField(
model_name='domain',
name='cname',
field=models.OneToOneField(related_name='related_domain', null=True, to='machines.Domain', blank=True),
),
]

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0037_domain_cname'),
]
operations = [
migrations.AlterField(
model_name='domain',
name='cname',
field=models.ForeignKey(null=True, to='machines.Domain', related_name='related_domain', blank=True),
),
]

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0038_auto_20161224_1721'),
]
operations = [
migrations.AlterField(
model_name='domain',
name='interface_parent',
field=models.OneToOneField(blank=True, null=True, to='machines.Interface'),
),
]

View file

@ -55,7 +55,7 @@ class Mx(models.Model):
zone = models.ForeignKey('Extension', on_delete=models.PROTECT) zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
priority = models.IntegerField(unique=True) priority = models.IntegerField(unique=True)
name = models.OneToOneField('Alias', on_delete=models.PROTECT) name = models.OneToOneField('Domain', on_delete=models.PROTECT)
def __str__(self): def __str__(self):
return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name) return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name)
@ -91,33 +91,29 @@ class Interface(models.Model):
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
self.mac_address = str(EUI(self.mac_address)) or None self.mac_address = str(EUI(self.mac_address)) or None
if self.ipv4:
alias = Alias.objects.filter(alias=self.dns).filter(extension=self.ipv4.ip_type.extension)
else:
alias = Alias.objects.filter(alias=self.dns)
if alias:
raise ValidationError("Impossible, le dns est déjà utilisé par un alias (%s)" % alias[0])
def __str__(self): def __str__(self):
return self.dns return self.domain_set.all().first()
class Alias(models.Model): class Domain(models.Model):
PRETTY_NAME = "Alias dns" PRETTY_NAME = "Domaine dns"
interface_parent = models.ForeignKey('Interface', on_delete=models.CASCADE) interface_parent = models.OneToOneField('Interface', on_delete=models.CASCADE, blank=True, null=True)
alias = models.CharField(help_text="Obligatoire et unique, ne doit pas comporter de points", max_length=255) name = models.CharField(help_text="Obligatoire et unique, ne doit pas comporter de points", max_length=255)
extension = models.ForeignKey('Extension', on_delete=models.PROTECT) extension = models.ForeignKey('Extension', on_delete=models.PROTECT)
cname = models.ForeignKey('self', null=True, blank=True, related_name='related_domain')
class Meta: class Meta:
unique_together = ("alias", "extension") unique_together = ("name", "extension")
def clean(self, *args, **kwargs): def clean(self):
if hasattr(self, 'alias') and hasattr(self, 'extension'): if self.interface_parent and self.cname:
if Interface.objects.filter(dns=self.alias).filter(ipv4__in=IpList.objects.filter(ip_type__in=IpType.objects.filter(extension=self.extension))): raise ValidationError("On ne peut créer à la fois A et CNAME")
raise ValidationError("Impossible d'ajouter l'alias, déjà utilisé par une machine") if self.related==self:
raise ValidationError("On ne peut créer un cname sur lui même")
def __str__(self): def __str__(self):
return str(self.alias) + str(self.extension) return str(self.name) + str(self.extension)
class IpList(models.Model): class IpList(models.Model):
PRETTY_NAME = "Addresses ipv4" PRETTY_NAME = "Addresses ipv4"