Commit e1e6b8cb authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Optimisation de la creation ipv4 + limitation à /16 pour les ip

parent 39571c75
# -*- 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)]),
),
]
......@@ -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"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment