From 4329641899d93e6f3d599a6ec64089d89a75df33 Mon Sep 17 00:00:00 2001 From: Charlie Jacomme Date: Mon, 16 Jul 2018 20:52:39 +0200 Subject: [PATCH] Ading prefix_v6_length field to IpType --- machines/forms.py | 7 ++-- .../0088_iptype_prefix_v6_length.py | 21 +++++++++++ machines/models.py | 36 ++++++++++++++++++- machines/templates/machines/aff_iptype.html | 2 +- 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 machines/migrations/0088_iptype_prefix_v6_length.py diff --git a/machines/forms.py b/machines/forms.py index ff529295..49150349 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -219,7 +219,8 @@ class IpTypeForm(FormRevMixin, ModelForm): model = IpType fields = ['type', 'extension', 'need_infra', 'domaine_ip_start', 'domaine_ip_stop', 'dnssec_reverse_v4', 'prefix_v6', - 'dnssec_reverse_v6', 'vlan', 'ouverture_ports'] + 'prefix_v6_length','dnssec_reverse_v6', 'vlan', + 'ouverture_ports'] def __init__(self, *args, **kwargs): prefix = kwargs.pop('prefix', self.Meta.model.__name__) @@ -231,8 +232,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', 'vlan', - 'dnssec_reverse_v4', 'dnssec_reverse_v6', + fields = ['extension', 'type', 'need_infra', 'prefix_v6', 'prefix_v6_length', + 'vlan', 'dnssec_reverse_v4', 'dnssec_reverse_v6', 'ouverture_ports'] diff --git a/machines/migrations/0088_iptype_prefix_v6_length.py b/machines/migrations/0088_iptype_prefix_v6_length.py new file mode 100644 index 00000000..e061167c --- /dev/null +++ b/machines/migrations/0088_iptype_prefix_v6_length.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-07-16 18:46 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0087_dnssec'), + ] + + operations = [ + migrations.AddField( + model_name='iptype', + name='prefix_v6_length', + field=models.IntegerField(default=64, validators=[django.core.validators.MaxValueValidator(128), django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/machines/models.py b/machines/models.py index 1cfee990..2f5a6a62 100644 --- a/machines/models.py +++ b/machines/models.py @@ -41,8 +41,8 @@ from django.dispatch import receiver from django.forms import ValidationError from django.utils.functional import cached_property from django.utils import timezone -from django.core.validators import MaxValueValidator from django.utils.translation import ugettext_lazy as _l +from django.core.validators import MaxValueValidator, MinValueValidator from macaddress.fields import MACAddressField @@ -265,6 +265,13 @@ class IpType(RevMixin, AclMixin, models.Model): null=True, blank=True ) + prefix_v6_length = models.IntegerField( + default=64, + validators=[ + MaxValueValidator(128), + MinValueValidator(0) + ] + ) dnssec_reverse_v6 = models.BooleanField( default=False, help_text="Activer DNSSEC sur le reverse DNS IPv6", @@ -302,6 +309,33 @@ 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_full_info(self): + """Iter sur les range cidr, et renvoie network, broacast , etc""" + return [ + { + 'network': str(ip_set.network), + 'netmask': str(ip_set.netmask), + 'netmask_cidr': str(ip_set.prefixlen), + 'broadcast': str(ip_set.broadcast), + 'vlan': str(self.vlan), + 'vlan_id': self.vlan.vlan_id + } for ip_set in self.ip_set.iter_cidrs() + ] + + @cached_property + def ip6_set_full_info(self): + if self.prefix_v6: + return { + 'network' : str(self.prefix_v6), + 'netmask' : 'ffff:ffff:ffff:ffff::', + 'netmask_cidr' : str(self.prefix_v6_length), + 'vlan': str(self.vlan), + 'vlan_id': self.vlan.vlan_id + } + else: + return None + def ip_objects(self): """ Renvoie tous les objets ipv4 relié à ce type""" return IpList.objects.filter(ip_type=self) diff --git a/machines/templates/machines/aff_iptype.html b/machines/templates/machines/aff_iptype.html index bee4669b..7d4de6c5 100644 --- a/machines/templates/machines/aff_iptype.html +++ b/machines/templates/machines/aff_iptype.html @@ -47,7 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ type.extension }} {{ type.need_infra|tick }} {{ type.domaine_ip_start }}-{{ type.domaine_ip_stop }} - {{ type.prefix_v6 }} + {{ type.prefix_v6 }}/{{ type.prefix_v6_length }} {{ type.dnssec_reverse_v4|tick }}/{{ type.dnssec_reverse_v6|tick }} {{ type.vlan }} {{ type.ouverture_ports }}