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

Specification optionnelle du range contenant domain ipstart-stop

This commit is contained in:
Gabriel Detraz 2018-08-07 00:10:54 +02:00 committed by root
parent efbd0a18da
commit 34fe6e06b7
4 changed files with 72 additions and 6 deletions

View file

@ -217,10 +217,7 @@ class IpTypeForm(FormRevMixin, ModelForm):
stop après creation""" stop après creation"""
class Meta: class Meta:
model = IpType model = IpType
fields = ['type', 'extension', 'need_infra', 'domaine_ip_start', fields = '__all__'
'domaine_ip_stop', 'dnssec_reverse_v4', 'prefix_v6',
'prefix_v6_length','dnssec_reverse_v6', 'vlan',
'ouverture_ports']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__) prefix = kwargs.pop('prefix', self.Meta.model.__name__)
@ -232,7 +229,8 @@ class EditIpTypeForm(IpTypeForm):
"""Edition d'un iptype. Pas d'edition du rangev4 possible, car il faudrait """Edition d'un iptype. Pas d'edition du rangev4 possible, car il faudrait
synchroniser les objets iplist""" synchroniser les objets iplist"""
class Meta(IpTypeForm.Meta): class Meta(IpTypeForm.Meta):
fields = ['extension', 'type', 'need_infra', 'prefix_v6', 'prefix_v6_length', fields = ['extension', 'type', 'need_infra', 'domaine_ip_network', 'domaine_ip_netmask',
'prefix_v6', 'prefix_v6_length',
'vlan', 'dnssec_reverse_v4', 'dnssec_reverse_v6', 'vlan', 'dnssec_reverse_v4', 'dnssec_reverse_v6',
'ouverture_ports'] 'ouverture_ports']

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-08-06 21:10
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0090_auto_20180805_1459'),
]
operations = [
migrations.AddField(
model_name='iptype',
name='domaine_ip_netmask',
field=models.IntegerField(default=24, help_text='Netmask for the ipv4 range domain', validators=[django.core.validators.MaxValueValidator(31), django.core.validators.MinValueValidator(8)]),
),
migrations.AddField(
model_name='iptype',
name='domaine_ip_network',
field=models.GenericIPAddressField(blank=True, help_text='Network containing the ipv4 range domain ip start/stop. Optional', null=True, protocol='IPv4'),
),
]

View file

@ -278,6 +278,20 @@ class IpType(RevMixin, AclMixin, models.Model):
need_infra = models.BooleanField(default=False) need_infra = models.BooleanField(default=False)
domaine_ip_start = models.GenericIPAddressField(protocol='IPv4') domaine_ip_start = models.GenericIPAddressField(protocol='IPv4')
domaine_ip_stop = models.GenericIPAddressField(protocol='IPv4') domaine_ip_stop = models.GenericIPAddressField(protocol='IPv4')
domaine_ip_network = models.GenericIPAddressField(
protocol='IPv4',
null=True,
blank=True,
help_text="Network containing the ipv4 range domain ip start/stop. Optional"
)
domaine_ip_netmask = models.IntegerField(
default=24,
validators=[
MaxValueValidator(31),
MinValueValidator(8)
],
help_text="Netmask for the ipv4 range domain"
)
dnssec_reverse_v4 = models.BooleanField( dnssec_reverse_v4 = models.BooleanField(
default=False, default=False,
help_text="Activer DNSSEC sur le reverse DNS IPv4", help_text="Activer DNSSEC sur le reverse DNS IPv4",
@ -331,6 +345,11 @@ class IpType(RevMixin, AclMixin, models.Model):
""" Renvoie une liste des ip en string""" """ Renvoie une liste des ip en string"""
return [str(x) for x in self.ip_set] return [str(x) for x in self.ip_set]
@cached_property
def ip_set_cidrs_as_str(self):
"""Renvoie la liste des cidrs du range en str"""
return [str(ip_range) for ip_range in self.ip_set.iter_cidrs()]
@cached_property @cached_property
def ip_set_full_info(self): def ip_set_full_info(self):
"""Iter sur les range cidr, et renvoie network, broacast , etc""" """Iter sur les range cidr, et renvoie network, broacast , etc"""
@ -358,6 +377,24 @@ class IpType(RevMixin, AclMixin, models.Model):
else: else:
return None return None
@cached_property
def ip_network(self):
"""Renvoie le network parent du range start-stop, si spécifié
Différent de ip_set_cidrs ou iP_set, car lui est supérieur ou égal"""
if self.domaine_ip_network:
return IPNetwork(str(self.domaine_ip_network) + '/' + str(self.domaine_ip_netmask))
return None
@cached_property
def ip_net_full_info(self):
"""Renvoie les infos du network contenant du range"""
return {
'network' : str(self.ip_network.network),
'netmask' : str(self.ip_network.netmask),
'broadcast' : str(self.ip_network.broadcast),
'netmask_cidr' : str(self.ip_network.prefixlen),
}
@cached_property @cached_property
def complete_prefixv6(self): def complete_prefixv6(self):
"""Return the complete prefix v6 as cidr""" """Return the complete prefix v6 as cidr"""
@ -442,6 +479,11 @@ class IpType(RevMixin, AclMixin, models.Model):
# On formate le prefix v6 # On formate le prefix v6
if self.prefix_v6: if self.prefix_v6:
self.prefix_v6 = str(IPNetwork(self.prefix_v6 + '/64').network) self.prefix_v6 = str(IPNetwork(self.prefix_v6 + '/64').network)
# On vérifie qu'un domaine network/netmask contiens bien le domaine ip start-stop
if self.domaine_ip_network:
if not self.domaine_ip_start in self.ip_network or not self.domaine_ip_stop in self.ip_network:
raise ValidationError("If you specify a domaine ip network/netmask, it\
must contain domaine ipstart-stop range")
return return
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View file

@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ type.type }}</td> <td>{{ type.type }}</td>
<td>{{ type.extension }}</td> <td>{{ type.extension }}</td>
<td>{{ type.need_infra|tick }}</td> <td>{{ type.need_infra|tick }}</td>
<td>{{ type.domaine_ip_start }}-{{ type.domaine_ip_stop }}</td> <td>{{ type.domaine_ip_start }}-{{ type.domaine_ip_stop }}{% if type.ip_network %}<b><u> on </b></u>{{ type.ip_network }}{% endif %}</td>
<td>{{ type.prefix_v6 }}/{{ type.prefix_v6_length }}</td> <td>{{ type.prefix_v6 }}/{{ type.prefix_v6_length }}</td>
<td>{{ type.dnssec_reverse_v4|tick }}/{{ type.dnssec_reverse_v6|tick }}</td> <td>{{ type.dnssec_reverse_v4|tick }}/{{ type.dnssec_reverse_v6|tick }}</td>
<td>{{ type.vlan }}</td> <td>{{ type.vlan }}</td>