mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Update domains when ip_type or machine_type are updated
This commit is contained in:
parent
02c8321d7d
commit
7a6075b741
1 changed files with 19 additions and 1 deletions
|
@ -353,6 +353,9 @@ class MachineType(RevMixin, AclMixin, models.Model):
|
|||
"""Get all interfaces of the current machine type (self)."""
|
||||
return Interface.objects.filter(machine_type=self)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(MachineType, self).save(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def can_use_all(user_request, *_args, **_kwargs):
|
||||
"""Check if an user can use all machine types.
|
||||
|
@ -594,6 +597,10 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
else:
|
||||
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):
|
||||
"""
|
||||
Check if:
|
||||
|
@ -1417,6 +1424,10 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
interface.save()
|
||||
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):
|
||||
"""Reassign addresses when the IP type of the machine type changed."""
|
||||
self.clean()
|
||||
|
@ -2430,7 +2441,8 @@ def machine_post_delete(**kwargs):
|
|||
|
||||
@receiver(post_save, sender=Interface)
|
||||
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.sync_ipv6()
|
||||
|
@ -2439,6 +2451,10 @@ def interface_post_save(**kwargs):
|
|||
# Regen services
|
||||
regen("dhcp")
|
||||
regen("mac_ip_list")
|
||||
# Update associated domains
|
||||
for domain in interface.all_domains():
|
||||
domain.clean()
|
||||
domain.save()
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Interface)
|
||||
|
@ -2456,6 +2472,8 @@ def iptype_post_save(**kwargs):
|
|||
iptype = kwargs["instance"]
|
||||
iptype.gen_ip_range()
|
||||
iptype.check_replace_prefixv6()
|
||||
for machinetype in iptype.all_machine_types():
|
||||
machinetype.save()
|
||||
|
||||
|
||||
@receiver(post_save, sender=MachineType)
|
||||
|
|
Loading…
Reference in a new issue