mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-28 18:03:45 +00:00
Creation de domain, transfert
This commit is contained in:
parent
cda4548981
commit
4379a4fcc5
7 changed files with 118 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
|||
from django.contrib import admin
|
||||
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):
|
||||
list_display = ('user','name','active')
|
||||
|
@ -28,8 +28,8 @@ class IpListAdmin(VersionAdmin):
|
|||
class InterfaceAdmin(VersionAdmin):
|
||||
list_display = ('machine','type','dns','mac_address','ipv4','details')
|
||||
|
||||
class AliasAdmin(VersionAdmin):
|
||||
list_display = ('interface_parent', 'alias', 'extension')
|
||||
class DomainAdmin(VersionAdmin):
|
||||
list_display = ('interface_parent', 'name', 'extension', 'cname')
|
||||
|
||||
admin.site.register(Machine, MachineAdmin)
|
||||
admin.site.register(MachineType, MachineTypeAdmin)
|
||||
|
@ -39,4 +39,4 @@ admin.site.register(Mx, MxAdmin)
|
|||
admin.site.register(Ns, NsAdmin)
|
||||
admin.site.register(IpList, IpListAdmin)
|
||||
admin.site.register(Interface, InterfaceAdmin)
|
||||
admin.site.register(Alias, AliasAdmin)
|
||||
admin.site.register(Domain, DomainAdmin)
|
||||
|
|
15
machines/migrations/0035_auto_20161224_1201.py
Normal file
15
machines/migrations/0035_auto_20161224_1201.py
Normal 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')
|
||||
]
|
28
machines/migrations/0036_auto_20161224_1204.py
Normal file
28
machines/migrations/0036_auto_20161224_1204.py
Normal 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')]),
|
||||
),
|
||||
]
|
19
machines/migrations/0037_domain_cname.py
Normal file
19
machines/migrations/0037_domain_cname.py
Normal 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),
|
||||
),
|
||||
]
|
19
machines/migrations/0038_auto_20161224_1721.py
Normal file
19
machines/migrations/0038_auto_20161224_1721.py
Normal 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),
|
||||
),
|
||||
]
|
19
machines/migrations/0039_auto_20161224_1732.py
Normal file
19
machines/migrations/0039_auto_20161224_1732.py
Normal 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'),
|
||||
),
|
||||
]
|
|
@ -55,7 +55,7 @@ class Mx(models.Model):
|
|||
|
||||
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
priority = models.IntegerField(unique=True)
|
||||
name = models.OneToOneField('Alias', on_delete=models.PROTECT)
|
||||
name = models.OneToOneField('Domain', on_delete=models.PROTECT)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name)
|
||||
|
@ -91,33 +91,29 @@ class Interface(models.Model):
|
|||
|
||||
def clean(self, *args, **kwargs):
|
||||
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):
|
||||
return self.dns
|
||||
return self.domain_set.all().first()
|
||||
|
||||
class Alias(models.Model):
|
||||
PRETTY_NAME = "Alias dns"
|
||||
class Domain(models.Model):
|
||||
PRETTY_NAME = "Domaine 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)
|
||||
interface_parent = models.OneToOneField('Interface', on_delete=models.CASCADE, blank=True, null=True)
|
||||
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)
|
||||
cname = models.ForeignKey('self', null=True, blank=True, related_name='related_domain')
|
||||
|
||||
class Meta:
|
||||
unique_together = ("alias", "extension")
|
||||
unique_together = ("name", "extension")
|
||||
|
||||
def clean(self, *args, **kwargs):
|
||||
if hasattr(self, 'alias') and hasattr(self, 'extension'):
|
||||
if Interface.objects.filter(dns=self.alias).filter(ipv4__in=IpList.objects.filter(ip_type__in=IpType.objects.filter(extension=self.extension))):
|
||||
raise ValidationError("Impossible d'ajouter l'alias, déjà utilisé par une machine")
|
||||
def clean(self):
|
||||
if self.interface_parent and self.cname:
|
||||
raise ValidationError("On ne peut créer à la fois A et CNAME")
|
||||
if self.related==self:
|
||||
raise ValidationError("On ne peut créer un cname sur lui même")
|
||||
|
||||
def __str__(self):
|
||||
return str(self.alias) + str(self.extension)
|
||||
return str(self.name) + str(self.extension)
|
||||
|
||||
class IpList(models.Model):
|
||||
PRETTY_NAME = "Addresses ipv4"
|
||||
|
|
Loading…
Reference in a new issue