show related hosts' ipv4/v6 addr from nameserver

This commit is contained in:
Thomas Waldmann 2014-09-26 00:16:52 +02:00
parent 3b4669771a
commit 8c25bdf14d
2 changed files with 35 additions and 4 deletions

View File

@ -333,6 +333,21 @@ class RelatedHost(models.Model):
# so the resulting hostname has a dot inside:
return dnstools.FQDN('%s.%s' % (self.name, main.host), main.domain)
def get_ip(self, kind):
record = 'A' if kind == 'ipv4' else 'AAAA'
try:
return dnstools.query_ns(self.get_fqdn(), record)
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
return 'none'
except (dns.resolver.NoNameservers, dns.resolver.Timeout, dnstools.NameServerNotAvailable):
return 'error'
def get_ipv4(self):
return self.get_ip('ipv4')
def get_ipv6(self):
return self.get_ip('ipv6')
pre_delete.connect(pre_delete_host, sender=RelatedHost)

View File

@ -19,8 +19,16 @@
{% trans "Comment" %}
</th>
<th>{% trans "Available" %}</th>
<th>{% blocktrans with type=_("IPv4") %}{{ type }} interface ID{% endblocktrans %}</th>
<th>{% blocktrans with type=_("IPv6") %}{{ type }} interface ID{% endblocktrans %}</th>
<th>
{% blocktrans with type=_("IPv4") %}{{ type }} Address{% endblocktrans %}
<br>
{% blocktrans with type=_("IPv4") %}{{ type }} interface ID{% endblocktrans %}
</th>
<th>
{% blocktrans with type=_("IPv6") %}{{ type }} Address{% endblocktrans %}
<br>
{% blocktrans with type=_("IPv6") %}{{ type }} interface ID{% endblocktrans %}
</th>
</tr>
</thead>
{% for rh in related_hosts %}
@ -31,8 +39,16 @@
{{ rh.comment }}
</td>
<td>{{ rh.available|yesno }}</td>
<td>{{ rh.interface_id_ipv4 }}</td>
<td>{{ rh.interface_id_ipv6 }}</td>
<td>
{{ rh.get_ipv4 }}
<br>
{{ rh.interface_id_ipv4 }}
</td>
<td>
{{ rh.get_ipv6 }}
<br>
{{ rh.interface_id_ipv6 }}
</td>
</tr>
{% empty %}
<tr><td colspan="5">{% trans "No related hosts yet." %}</td></tr>