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
affected_records = Record.objects.filter(
host=self, name=self.hostname,
type='A').update(address=self.ipv4) type='A').update(address=self.ipv4)
record_count = self.record_set.filter(host=self, # create new record
name=self.hostname, if affected_records == 0:
address=self.ipv4,
type='A').count()
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:
# update existing records
affected_records = Record.objects.filter(
host=self, name=self.hostname,
type='AAAA').update(address=self.ipv6) type='AAAA').update(address=self.ipv6)
record_count = self.record_set.filter(host=self, # create new record
name=self.hostname, if affected_records == 0:
address=self.ipv6,
type='AAAA').count()
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.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