From e1e6b8cb9d24ca81880bf53844ee8f45e4078509 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 23 Aug 2017 23:26:49 +0200 Subject: [PATCH] =?UTF-8?q?Optimisation=20de=20la=20creation=20ipv4=20+=20?= =?UTF-8?q?limitation=20=C3=A0=20/16=20pour=20les=20ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0048_auto_20170823_2315.py | 21 +++++++++++++++++++ machines/models.py | 7 ++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 machines/migrations/0048_auto_20170823_2315.py diff --git a/machines/migrations/0048_auto_20170823_2315.py b/machines/migrations/0048_auto_20170823_2315.py new file mode 100644 index 00000000..0c0a48f3 --- /dev/null +++ b/machines/migrations/0048_auto_20170823_2315.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-08-23 21:15 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0047_auto_20170809_0606'), + ] + + operations = [ + migrations.AlterField( + model_name='iptype', + name='domaine_range', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(16), django.core.validators.MaxValueValidator(32)]), + ), + ] diff --git a/machines/models.py b/machines/models.py index 2207d1b6..bd4426c3 100644 --- a/machines/models.py +++ b/machines/models.py @@ -68,7 +68,7 @@ class IpType(models.Model): extension = models.ForeignKey('Extension', on_delete=models.PROTECT) need_infra = models.BooleanField(default=False) domaine_ip = models.GenericIPAddressField(protocol='IPv4') - domaine_range = models.IntegerField(validators=[MinValueValidator(8), MaxValueValidator(32)]) + domaine_range = models.IntegerField(validators=[MinValueValidator(16), MaxValueValidator(32)]) @cached_property def network(self): @@ -94,8 +94,9 @@ class IpType(models.Model): def gen_ip_range(self): # Creation du range d'ip dans les objets iplist - for ip in self.ip_network.iter_hosts(): - obj, created = IpList.objects.get_or_create(ip_type=self, ipv4=str(ip)) + ip_obj = [IpList(ip_type=self, ipv4=str(ip)) for ip in self.ip_network.iter_hosts()] + IpList.objects.bulk_create(ip_obj) + return def del_ip_range(self): """ Methode dépréciée, IpList est en mode cascade et supprimé automatiquement"""