added logic for last_api_update. field updated with Hosts.poke() method
This commit is contained in:
parent
053f2f9a65
commit
beafe06852
@ -198,6 +198,14 @@ def AuthorizedNicUpdateView(request):
|
||||
|
||||
def _update(hostname, ipaddr):
|
||||
ipaddr = str(ipaddr) # XXX bug in dnspython: crashes if ipaddr is unicode, wants a str!
|
||||
hosts = Host.filter_by_fqdn(hostname)
|
||||
num_hosts = len(hosts)
|
||||
if num_hosts == 0:
|
||||
return False
|
||||
if num_hosts > 1:
|
||||
logging.error("fqdn %s has multiple entries" % hostname)
|
||||
return False
|
||||
hosts[0].poke()
|
||||
try:
|
||||
update(hostname, ipaddr)
|
||||
logger.info('%s - received good update -> ip: %s' % (hostname, ipaddr, ))
|
||||
|
@ -7,6 +7,7 @@ from django.db.models.signals import post_delete
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from main import dnstools
|
||||
import dns.resolver
|
||||
from datetime import datetime
|
||||
|
||||
import re
|
||||
|
||||
@ -83,14 +84,18 @@ class Host(models.Model):
|
||||
def getIPv4(self):
|
||||
try:
|
||||
return dnstools.query_ns(self.get_fqdn(), 'A')
|
||||
except dns.resolver.NXDOMAIN:
|
||||
return ''
|
||||
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||
return '-'
|
||||
|
||||
def getIPv6(self):
|
||||
try:
|
||||
return dnstools.query_ns(self.get_fqdn(), 'AAAA')
|
||||
except dns.resolver.NXDOMAIN:
|
||||
return ''
|
||||
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||
return '-'
|
||||
|
||||
def poke(self):
|
||||
self.last_api_update = datetime.now()
|
||||
self.save()
|
||||
|
||||
def generate_secret(self):
|
||||
# note: we use a quick hasher for the update_secret as expensive
|
||||
|
Loading…
x
Reference in New Issue
Block a user