mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Si il y a deja des ip, on change leur destination ip_type
This commit is contained in:
parent
b06c7ed6ff
commit
789a8dcb5d
1 changed files with 8 additions and 3 deletions
|
@ -93,7 +93,13 @@ class IpType(models.Model):
|
||||||
for net in self.ip_range.cidrs():
|
for net in self.ip_range.cidrs():
|
||||||
networks += net.iter_hosts()
|
networks += net.iter_hosts()
|
||||||
ip_obj = [IpList(ip_type=self, ipv4=str(ip)) for ip in networks]
|
ip_obj = [IpList(ip_type=self, ipv4=str(ip)) for ip in networks]
|
||||||
IpList.objects.bulk_create(ip_obj)
|
listes_ip = IpList.objects.filter(ipv4__in=[str(ip) for ip in networks])
|
||||||
|
# Si il n'y a pas d'ip, on les crée
|
||||||
|
if not listes_ip:
|
||||||
|
IpList.objects.bulk_create(ip_obj)
|
||||||
|
# Sinon on update l'ip_type
|
||||||
|
else:
|
||||||
|
listes_ip.update(ip_type=self)
|
||||||
return
|
return
|
||||||
|
|
||||||
def del_ip_range(self):
|
def del_ip_range(self):
|
||||||
|
@ -373,8 +379,7 @@ def interface_post_delete(sender, **kwargs):
|
||||||
@receiver(post_save, sender=IpType)
|
@receiver(post_save, sender=IpType)
|
||||||
def iptype_post_save(sender, **kwargs):
|
def iptype_post_save(sender, **kwargs):
|
||||||
iptype = kwargs['instance']
|
iptype = kwargs['instance']
|
||||||
if not iptype.ip_objects():
|
iptype.gen_ip_range()
|
||||||
iptype.gen_ip_range()
|
|
||||||
|
|
||||||
@receiver(post_save, sender=MachineType)
|
@receiver(post_save, sender=MachineType)
|
||||||
def machine_post_save(sender, **kwargs):
|
def machine_post_save(sender, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue