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)
def get_reverse_domain_id(self, v6):
if v6:
domain_id = self.get_domain_id("")
if domain_id:
return domain_id
domain_id = self.get_domain_id("")
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)
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('') == ''
def test_reverse_dns(self):
assert dns_rr.reverse_dns('') == ''
def test_reverse_dns6(self):
assert dns_rr.reverse_dns6('2001:700:0:4540:21d:d8ff:feb7:6355') == \
assert dns_rr.reverse_dns6('2001:700:0:4540::10') == \
def test_reverse_domain(self):
assert dns_rr.get_reverse_domain(dns_rr.reverse_dns('')) == ''
assert dns_rr.get_reverse_domain(dns_rr.reverse_dns6('2001:700:0:4540:21d:d8ff:feb7:6355')) == \
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment