Commit a09c552d authored by Sigmund Augdal's avatar Sigmund Augdal

Even more generic reverse domain handling

parent 3ddba1e9
......@@ -27,6 +27,15 @@ def reverse_dns6(ipv6_string):
return r + suffix
def get_reverse_domain(record):
parts = record.split('.')
if len(parts) == 34:
parts = parts[17:]
else:
parts = parts[1:]
return '.'.join(parts)
def client_from_conf(conf):
pdns_url = conf.get('pdns', 'url')
pdns_username = None
......@@ -169,19 +178,6 @@ class PowerRESTClient(object):
ptr_record['content'] = generate_ptr(ipaddress)
self.update_record(ptr_record)
def get_reverse_domain_id(self, v6, record):
if v6:
domain_id = self.get_domain_id("4.5.4.0.0.0.0.0.0.7.0.1.0.0.2.ip6.arpa")
if domain_id:
return domain_id
else:
zone = '.'.join(record.split('.')[1:])
domain_id = self.get_domain_id("{}".format(zone))
if domain_id:
return domain_id
raise ValueError("Failed to find domain id")
def create_or_update_ptr(self, ptr, address, ipv6=False):
if not address:
raise RuntimeError("Missing address when trying to create reverse")
......@@ -192,7 +188,9 @@ class PowerRESTClient(object):
else:
reverse_record = reverse_dns(address)
domain_id = self.get_reverse_domain_id(ipv6, reverse_record)
domain_id = self.get_domain_id(get_reverse_domain(reverse_record))
if domain_id is False:
raise ValueError("Failed to find domain id")
data = {'content': ptr,
'name': reverse_record,
......
from __future__ import absolute_import, division, print_function, unicode_literals
from nova_router import dns_rr
from py.test import raises
import mock
class TestFuncs(object):
def test_generate_ptr(self):
assert dns_rr.generate_ptr('158.38.213.10') == 'vm-bs-158-38-213-10.cl.uninett.no'
def test_reverse_dns(self):
assert dns_rr.reverse_dns('158.38.213.10') == '10.213.38.158.in-addr.arpa'
def test_reverse_dns6(self):
assert dns_rr.reverse_dns6('2001:700:0:4540:21d:d8ff:feb7:6355') == \
'5.5.3.6.7.b.e.f.f.f.8.d.d.1.2.0.0.4.5.4.0.0.0.0.0.0.7.0.1.0.0.2.ip6.arpa'
assert dns_rr.reverse_dns6('2001:700:0:4540::10') == \
'0.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.5.4.0.0.0.0.0.0.7.0.1.0.0.2.ip6.arpa'
def test_reverse_domain(self):
assert dns_rr.get_reverse_domain(dns_rr.reverse_dns('158.38.213.10')) == '213.38.158.in-addr.arpa'
assert dns_rr.get_reverse_domain(dns_rr.reverse_dns6('2001:700:0:4540:21d:d8ff:feb7:6355')) == \
"4.5.4.0.0.0.0.0.0.7.0.1.0.0.2.ip6.arpa"
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 to comment