Commit 49646ae3 authored by chirac's avatar chirac

Merge branch 'domaine_network' into 'dev'

Domaine network

See merge request federez/re2o!229
parents 52685c02 34fe6e06
Pipeline #734 failed with stage
......@@ -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',
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',
# -*- 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 = [
field=models.IntegerField(default=24, help_text='Netmask for the ipv4 range domain', validators=[django.core.validators.MaxValueValidator(31), django.core.validators.MinValueValidator(8)]),
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(
help_text="Network containing the ipv4 range domain ip start/stop. Optional"
domaine_ip_netmask = models.IntegerField(
help_text="Netmask for the ipv4 range domain"
dnssec_reverse_v4 = models.BooleanField(
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]
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()]
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):
return None
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
def ip_net_full_info(self):
"""Renvoie les infos du network contenant du range"""
return {
'network' : str(,
'netmask' : str(self.ip_network.netmask),
'broadcast' : str(self.ip_network.broadcast),
'netmask_cidr' : str(self.ip_network.prefixlen),
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")
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>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment