mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Optimisation de la creation ipv4 + limitation à /16 pour les ip
This commit is contained in:
parent
39571c75eb
commit
e1e6b8cb9d
2 changed files with 25 additions and 3 deletions
21
machines/migrations/0048_auto_20170823_2315.py
Normal file
21
machines/migrations/0048_auto_20170823_2315.py
Normal file
|
@ -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)]),
|
||||
),
|
||||
]
|
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue