mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-28 01:43:46 +00:00
Merge branch 'domaine_network' into 'dev'
Domaine network See merge request federez/re2o!229
This commit is contained in:
commit
49646ae34b
4 changed files with 72 additions and 6 deletions
|
@ -217,10 +217,7 @@ class IpTypeForm(FormRevMixin, ModelForm):
|
|||
stop après creation"""
|
||||
class Meta:
|
||||
model = IpType
|
||||
fields = ['type', 'extension', 'need_infra', 'domaine_ip_start',
|
||||
'domaine_ip_stop', 'dnssec_reverse_v4', 'prefix_v6',
|
||||
'prefix_v6_length','dnssec_reverse_v6', 'vlan',
|
||||
'ouverture_ports']
|
||||
fields = '__all__'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
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
|
||||
synchroniser les objets iplist"""
|
||||
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',
|
||||
'ouverture_ports']
|
||||
|
||||
|
|
26
machines/migrations/0091_auto_20180806_2310.py
Normal file
26
machines/migrations/0091_auto_20180806_2310.py
Normal 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'),
|
||||
),
|
||||
]
|
|
@ -278,6 +278,20 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
need_infra = models.BooleanField(default=False)
|
||||
domaine_ip_start = 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(
|
||||
default=False,
|
||||
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"""
|
||||
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
|
||||
def ip_set_full_info(self):
|
||||
"""Iter sur les range cidr, et renvoie network, broacast , etc"""
|
||||
|
@ -358,6 +377,24 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
else:
|
||||
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
|
||||
def complete_prefixv6(self):
|
||||
"""Return the complete prefix v6 as cidr"""
|
||||
|
@ -442,6 +479,11 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
# On formate le prefix v6
|
||||
if self.prefix_v6:
|
||||
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
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
|
@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<td>{{ type.type }}</td>
|
||||
<td>{{ type.extension }}</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.dnssec_reverse_v4|tick }}/{{ type.dnssec_reverse_v6|tick }}</td>
|
||||
<td>{{ type.vlan }}</td>
|
||||
|
|
Loading…
Reference in a new issue