8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Update domains when ip_type or machine_type are updated

This commit is contained in:
chapeau 2020-06-09 11:27:35 +02:00 committed by Gabriel Detraz
parent 02c8321d7d
commit 7a6075b741

View file

@ -353,6 +353,9 @@ class MachineType(RevMixin, AclMixin, models.Model):
"""Get all interfaces of the current machine type (self).""" """Get all interfaces of the current machine type (self)."""
return Interface.objects.filter(machine_type=self) return Interface.objects.filter(machine_type=self)
def save(self, *args, **kwargs):
super(MachineType, self).save(*args, **kwargs)
@staticmethod @staticmethod
def can_use_all(user_request, *_args, **_kwargs): def can_use_all(user_request, *_args, **_kwargs):
"""Check if an user can use all machine types. """Check if an user can use all machine types.
@ -594,6 +597,10 @@ class IpType(RevMixin, AclMixin, models.Model):
else: else:
return None return None
def all_machine_types(self):
"""Get all machine types associated with this ip type (self)."""
return MachineType.objects.filter(ip_type=self)
def clean(self): def clean(self):
""" """
Check if: Check if:
@ -1417,6 +1424,10 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
interface.save() interface.save()
reversion.set_comment("IPv4 assignment") reversion.set_comment("IPv4 assignment")
def all_domains(self):
"""Get all domains associated with this interface (self)."""
return Domain.objects.filter(interface_parent=self)
def update_type(self): def update_type(self):
"""Reassign addresses when the IP type of the machine type changed.""" """Reassign addresses when the IP type of the machine type changed."""
self.clean() self.clean()
@ -2430,7 +2441,8 @@ def machine_post_delete(**kwargs):
@receiver(post_save, sender=Interface) @receiver(post_save, sender=Interface)
def interface_post_save(**kwargs): def interface_post_save(**kwargs):
"""Synchronise LDAP and regen firewall/DHCP after an interface is edited. """Synchronise LDAP, regen firewall/DHCP after an interface is edited
and update associated domains
""" """
interface = kwargs["instance"] interface = kwargs["instance"]
interface.sync_ipv6() interface.sync_ipv6()
@ -2439,6 +2451,10 @@ def interface_post_save(**kwargs):
# Regen services # Regen services
regen("dhcp") regen("dhcp")
regen("mac_ip_list") regen("mac_ip_list")
# Update associated domains
for domain in interface.all_domains():
domain.clean()
domain.save()
@receiver(post_delete, sender=Interface) @receiver(post_delete, sender=Interface)
@ -2456,6 +2472,8 @@ def iptype_post_save(**kwargs):
iptype = kwargs["instance"] iptype = kwargs["instance"]
iptype.gen_ip_range() iptype.gen_ip_range()
iptype.check_replace_prefixv6() iptype.check_replace_prefixv6()
for machinetype in iptype.all_machine_types():
machinetype.save()
@receiver(post_save, sender=MachineType) @receiver(post_save, sender=MachineType)