Commit 742b9423 by Bach Dániel

firewall: fix Host.save()

parent f5d3ce91
...@@ -540,36 +540,36 @@ class Host(models.Model): ...@@ -540,36 +540,36 @@ class Host(models.Model):
super(Host, self).save(*args, **kwargs) super(Host, self).save(*args, **kwargs)
# IPv4
if self.ipv4 is not None: if self.ipv4 is not None:
Record.objects.filter(host=self, name=self.hostname, # update existing records
type='A').update(address=self.ipv4) affected_records = Record.objects.filter(
record_count = self.record_set.filter(host=self, host=self, name=self.hostname,
name=self.hostname, type='A').update(address=self.ipv4)
address=self.ipv4, # create new record
type='A').count() if affected_records == 0:
if record_count == 0:
Record(host=self, Record(host=self,
name=self.hostname, name=self.hostname,
domain=self.vlan.domain, domain=self.vlan.domain,
address=self.ipv4, address=self.ipv4,
owner=self.owner, owner=self.owner,
description='host.save()', description='created by host.save()',
type='A').save() type='A').save()
if self.ipv6: # IPv6
Record.objects.filter(host=self, name=self.hostname, if self.ipv6 is not None:
type='AAAA').update(address=self.ipv6) # update existing records
record_count = self.record_set.filter(host=self, affected_records = Record.objects.filter(
name=self.hostname, host=self, name=self.hostname,
address=self.ipv6, type='AAAA').update(address=self.ipv6)
type='AAAA').count() # create new record
if record_count == 0: if affected_records == 0:
Record(host=self, Record(host=self,
name=self.hostname, name=self.hostname,
domain=self.vlan.domain, domain=self.vlan.domain,
address=self.ipv6, address=self.ipv6,
owner=self.owner, owner=self.owner,
description='host.save()', description='created by host.save()',
type='AAAA').save() type='AAAA').save()
def enable_net(self): def enable_net(self):
......
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 sign in to comment