From fc612f47dcfa440bf3c86362520209dfe5b76392 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 ++++--- .../0095_iptype_prefix_v6_length.py | 21 +++++++++++++++++++ machines/models.py | 11 ++++++++-- machines/templates/machines/aff_iptype.html | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 machines/migrations/0095_iptype_prefix_v6_length.py diff --git a/machines/forms.py b/machines/forms.py index 6be9b2a2..5706d798 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/0095_iptype_prefix_v6_length.py b/machines/migrations/0095_iptype_prefix_v6_length.py new file mode 100644 index 00000000..4d0cfc71 --- /dev/null +++ b/machines/migrations/0095_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', '0094_role_specific_role'), + ] + + 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 90e65a5f..7d9d983c 100644 --- a/machines/models.py +++ b/machines/models.py @@ -39,7 +39,7 @@ 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.core.validators import MaxValueValidator, MinValueValidator from macaddress.fields import MACAddressField @@ -343,6 +343,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", @@ -405,7 +412,7 @@ class IpType(RevMixin, AclMixin, models.Model): return { 'network' : str(self.prefix_v6), 'netmask' : 'ffff:ffff:ffff:ffff::', - 'netmask_cidr' : '64', + 'netmask_cidr' : str(self.prefix_v6_length), 'vlan': str(self.vlan), 'vlan_id': self.vlan.vlan_id } diff --git a/machines/templates/machines/aff_iptype.html b/machines/templates/machines/aff_iptype.html index 576c404d..d3e586d0 100644 --- a/machines/templates/machines/aff_iptype.html +++ b/machines/templates/machines/aff_iptype.html @@ -45,7 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ type.extension }} {{ type.need_infra }} {{ type.domaine_ip_start }}-{{ type.domaine_ip_stop }} - {{ type.prefix_v6 }} + {{ type.prefix_v6 }}/{{ type.prefix_v6_length }} {{ type.dnssec_reverse_v4 }}/{{ type.dnssec_reverse_v6 }} {{ type.vlan }} {{ type.ouverture_ports }}