Commit daada3b6 authored by Morten Knutsen's avatar Morten Knutsen

Merge branch 'dns-ptr-rewrite' into 'master'

Dns ptr rewrite

More generc reverse domain handling

See merge request !5
parents 0da8662c 1d470182
......@@ -27,6 +27,15 @@ def reverse_dns6(ipv6_string):
return r + suffix
def get_reverse_domain(record):
parts = record.split('.')
if len(parts) == 34: # IPv6
parts = parts[17:]
else: # IPv4
parts = parts[1:]
return '.'.join(parts)
def client_from_conf(conf):
pdns_url = conf.get('pdns', 'url')
pdns_username = None
......@@ -169,28 +178,20 @@ class PowerRESTClient(object):
ptr_record['content'] = generate_ptr(ipaddress)
self.update_record(ptr_record)
def get_reverse_domain_id(self, v6):
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:
domain_id = self.get_domain_id("213.38.158.in-addr.arpa")
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")
rec = self.get_ptr_record(address, ipv6)
if not rec: # Create
domain_id = self.get_reverse_domain_id(ipv6)
if ipv6:
reverse_record = reverse_dns6(address)
else:
reverse_record = reverse_dns(address)
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,
'domain_id': domain_id,
......
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