Permalink
Browse files

support origin (@)

  • Loading branch information...
1 parent 1224d0f commit 964dfc8a7d604d830addd20f64704742b9178dfd @tantra35 committed Feb 21, 2012
Showing with 116 additions and 65 deletions.
  1. +25 −23 loader.cfg
  2. +9 −5 py-nsupdate/fiilbackets.sh
  3. +63 −29 pymodules/loader.py
  4. +19 −8 pymodules/playrix/powerDNS/g300_net.py
View
@@ -1,23 +1,25 @@
-[global]
-logfile=/var/log/powerdns/python.loader.log
-loglevel=info
-
-[g300.net]
-class=playrix.powerDNS.g300_net.backend
-zone_id=10
-
-SOA=ns1.g300.net support@playrix.com 3600
- 610 #sn = serial number
- 3600 #ref = refresh = 2d
- 7200 #ret = update retry = 2*ref
- 25200 #ex = expiry = 7*ref
- 600 #min = minimum = 1h
-
-NS=ns1.g300.net 120
- ns2.g300.net 120
-
-A=ns1 176.9.15.229 60
- ns2 173.255.195.37 60
- g21 class:playrix.powerDNS.loadbalancewithfailover.backend
- g22 class:playrix.powerDNS.loadbalancewithfailover.backend
- g23 class:playrix.powerDNS.geowithloadbalancewithfailover.backend /usr/share/GeoIP/GeoLiteCity.dat
+[global]
+logfile=/var/log/powerdns/python.loader.log
+loglevel=info
+
+[g300.net]
+class=playrix.powerDNS.g300_net.backend
+zone_id=10
+
+SOA=ns1.g300.net support@playrix.com 3600
+ 610 #sn = serial number
+ 3600 #ref = refresh = 2d
+ 7200 #ret = update retry = 2*ref
+ 25200 #ex = expiry = 7*ref
+ 60 #min = minimum = 1h
+
+NS=@ ns1.g300.net 120
+ @ ns2.g300.net 120
+
+A=ns1 176.9.15.229 60
+ ns2 173.255.195.37 60
+ g21 class:playrix.powerDNS.loadbalancewithfailover.backend
+ g22 class:playrix.powerDNS.loadbalancewithfailover.backend
+ g23 class:playrix.powerDNS.geowithloadbalancewithfailover.backend /usr/share/GeoIP/GeoLiteCity.dat
+ g24 class:playrix.powerDNS.geowithloadbalancewithfailover.backend /usr/share/GeoIP/GeoLiteCity.dat
+ g25 class:playrix.powerDNS.geowithloadbalancewithfailover.backend /usr/share/GeoIP/GeoLiteCity.dat
View
@@ -1,5 +1,9 @@
-./py-nsupdate -t localhost:9160 -f add_domain g21.g300.net 120
-./py-nsupdate -t localhost:9160 -f add_domain_backet g21.g300.net EUR 10.68 40 True
-./py-nsupdate -t localhost:9160 -f add_domain_backet g21.g300.net USA -73.68 40 120 False
-./py-nsupdate -t localhost:9160 -f add_domain_backet_ip g21.g300.net USA 174.36.214.36
-./py-nsupdate -t localhost:9160 -f rmv_domain_backet_ip g21.g300.net USA 174.36.214.36
+#!/bin/sh
+
+./py-nsupdate -t localhost:9160 -f add_domain g23.g300.net 120
+./py-nsupdate -t localhost:9160 -f add_domain_backet g23.g300.net EUR 10.68 40 True
+./py-nsupdate -t localhost:9160 -f add_domain_backet g23.g300.net USA -73.68 40 False
+./py-nsupdate -t localhost:9160 -f add_domain_backet_ip g23.g300.net USA 174.36.214.36
+./py-nsupdate -t localhost:9160 -f add_domain_backet_ip g23.g300.net EUR 85.17.31.103
+./py-nsupdate -t localhost:9160 -f add_domain_backet_ip g23.g300.net EUR 82.192.95.147
+#./py-nsupdate -t localhost:9160 -f rmv_domain_backet_ip g23.g300.net USA 174.36.214.36
View
@@ -1,6 +1,8 @@
import ConfigParser;
import logging;
import logging.handlers;
+import traceback;
+import re;
#------------------------------------------------------------------------------
#
@@ -10,46 +12,72 @@
def removeComments(string):
return re.sub(re.compile("(#|;).*$", re.MULTILINE) ,"" ,string) # remove all occurance singleline comments (//COMMENT\n ) from string
+def cmpdomains(d1, d2):
+ l_d1 = d1.split('.')
+ l_d2 = d2.split('.')
+
+ if(len(l_d1) > len(l_d2)):
+ return 1
+
+ elif(len(l_d1) < len(l_d2)):
+ return -1
+
+ else:
+ return cmp(d1, d2)
+
+#------------------------------------------------------------------------------
+#
+#
+#
+#------------------------------------------------------------------------------
class loader(object):
def __init__(self):
self.__m_domain_to_class = {};
self.__m_handler = None;
self.__m_loger = logging.getLogger("loader");
- l_config = g_config;
+ try:
+ l_config = g_config;
+
+ for l_domainname in l_config.sections():
+ l_module_name, l_class_name = l_config.get(l_domainname, 'class').rsplit('.', 1);
+ l_zone_id = int(l_config.get(l_domainname, 'zone_id'));
+ l_options = [];
+
+ l_module =__import__(l_module_name, globals(), locals(), ['']);
+ l_class = getattr(l_module, l_class_name);
- for l_domainname in l_config.sections():
- l_module_name, l_class_name = l_config.get(l_domainname, 'class').rsplit('.', 1);
- l_zone_id = int(l_config.get(l_domainname, 'zone_id'));
- l_options = [];
+ for l_option in l_config.items(l_domainname):
+ l_name, l_value = l_option;
+ l_value = removeComments(l_value)
+ l_rrnames = ('a', 'ns', 'cname', 'soa', 'txt')
- l_module =__import__(l_module_name, globals(), locals(), ['']);
- l_class = getattr(l_module, l_class_name);
+ if l_name in l_rrnames:
+ if l_name == 'soa':
+ lll_option = [];
- for l_option in l_config.items(l_domainname):
- l_name, l_value = l_option;
- l_value = removeComments(l_value)
- l_rrnames = ('a', 'ns', 'cname', 'soa', 'txt')
+ for l_line in str.splitlines(l_value):
+ if l_line != '':
+ lll_option.append(l_line);
- if l_name in l_rrnames:
- if l_name == 'soa':
- lll_option = [];
+ ll_option = (l_name, ' '.join(lll_option))
+ l_options.append(ll_option);
- for l_line in str.splitlines(l_value):
- if l_line != '':
- lll_option.append(l_line);
+ else:
+ for l_line in str.splitlines(l_value):
+ if l_line != '':
+ ll_option = (l_name, l_line);
+ l_options.append(ll_option);
- ll_option = (l_name, ' '.join(lll_option))
- l_options.append(ll_option);
+ l_ldomainname = l_domainname.lower();
+ self.__m_domain_to_class[l_ldomainname] = l_class(l_ldomainname, l_zone_id, l_options);
- else:
- for l_line in str.splitlines(l_value):
- if l_line != '':
- ll_option = (l_name, l_line);
- l_options.append(ll_option);
+ self.__m_domains = self.__m_domain_to_class.keys();
+ self.__m_domains.sort(cmp=cmpdomains, reverse=True);
- l_ldomainname = l_domainname.lower();
- self.__m_domain_to_class[l_ldomainname] = l_class(l_ldomainname, l_zone_id, l_options);
+ except Exception as e:
+ self.__m_loger.error(traceback.format_exc());
+ raise e
def lookup(self, qtype, qdomain, dnspkt, domain_id):
self.__m_loger.debug("call with qtype: " + str(qtype));
@@ -60,10 +88,12 @@ def lookup(self, qtype, qdomain, dnspkt, domain_id):
self.__m_handler = None;
l_lqdomain = qdomain.lower();
- for l_qdomain, l_handler in self.__m_domain_to_class.iteritems():
+ for l_qdomain in self.__m_domains:
ll_qdomain = '.' + l_qdomain;
if (l_lqdomain == l_qdomain) or (l_lqdomain.find(ll_qdomain, -len(ll_qdomain)) > 0):
+ l_handler = self.__m_domain_to_class[l_qdomain]
+
self.__m_loger.debug("call with handler: " + str(l_handler));
self.__m_handler = l_handler;
l_handler.lookup(qtype, l_lqdomain, dnspkt, domain_id);
@@ -78,10 +108,12 @@ def list(self, qdomain, domain_id):
retval = False;
l_lqdomain = qdomain.lower();
- for l_qdomain, l_handler in self.__m_domain_to_class.iteritems():
+ for l_qdomain in self.__m_domains:
ll_qdomain = '.' + l_qdomain;
if (l_lqdomain == l_qdomain) or (l_lqdomain.find(ll_qdomain, -len(ll_qdomain)) > 0):
+ l_handler = self.__m_domain_to_class[l_qdomain]
+
self.__m_loger.debug("call with handler: " + str(l_handler));
self.__m_handler = l_handler;
retval = l_handler.list(l_lqdomain, domain_id);
@@ -105,10 +137,12 @@ def getSOA(self, qdomain, soadata, dnspkt):
retval = False;
l_lqdomain = qdomain.lower();
- for l_qdomain, l_handler in self.__m_domain_to_class.iteritems():
+ for l_qdomain in self.__m_domains:
ll_qdomain = '.' + l_qdomain;
if (l_lqdomain == l_qdomain) or (l_lqdomain.find(ll_qdomain, -len(ll_qdomain)) > 0):
+ l_handler = self.__m_domain_to_class[l_qdomain]
+
self.__m_loger.debug("call with handler: " + str(l_handler));
self.__m_handler = l_handler;
retval = l_handler.getSOA(l_lqdomain, soadata, dnspkt);
@@ -19,8 +19,13 @@ def __init__(self, qname, zone_id, options):
l_name, l_value = l_option;
if l_name == 'a':
- l_parts = l_value.split(" ");
- l_lqdomain = (l_parts[0] if '.' in l_parts[0] else l_parts[0] + '.' + qname).lower();
+ l_parts = l_value.split();
+
+ if l_parts[0] == '@':
+ l_lqdomain = qname
+
+ else:
+ l_lqdomain = (l_parts[0] if '.' in l_parts[0] else l_parts[0] + '.' + qname).lower();
if not l_lqdomain in self.__m_qdomains:
self.__m_qdomains[l_lqdomain] = {};
@@ -40,38 +45,44 @@ def __init__(self, qname, zone_id, options):
self.__m_qdomains[l_lqdomain]['A'].append({'handler': l_class(qname, l_parts[2:])});
elif l_name == 'ns':
- l_parts = l_value.split(" ");
- l_lqdomain = qname;
+ l_parts = l_value.split();
+
+ if l_parts[0] == '@':
+ l_lqdomain = qname
+
+ else:
+ l_lqdomain = (l_parts[0] if '.' in l_parts[0] else l_parts[0] + '.' + qname).lower();
if not l_lqdomain in self.__m_qdomains:
self.__m_qdomains[l_lqdomain] = {};
if not 'NS' in self.__m_qdomains[l_lqdomain]:
self.__m_qdomains[l_lqdomain]['NS'] = [];
- l_rr = {'type': QType.NS, 'content': l_parts[0], 'qname': l_lqdomain, 'ttl': int(l_parts[1])}
+ l_rr = {'type': QType.NS, 'content': l_parts[1], 'qname': l_lqdomain, 'ttl': int(l_parts[2])}
self.__m_qdomains[l_lqdomain]['NS'].append(l_rr);
elif l_name == 'cname':
pass;
elif l_name == "soa":
- l_parts = l_value.split(" ");
+ l_parts = l_value.split();
l_lqdomain = qname;
if not l_lqdomain in self.__m_qdomains:
self.__m_qdomains[l_lqdomain] = {};
l_rr = {
- 'nameserver': l_parts[0],
+ 'nameserver': l_parts[0],
'hostmaster': l_parts[1].replace('@', '.'),
'ttl': int(l_parts[2]),
'serial': int(l_parts[3]),
- 'refresh': int(l_parts[4]),
+ 'refresh': int(l_parts[4]),
'retry': int(l_parts[5]),
'expire': int(l_parts[6]),
'default_ttl': int(l_parts[7])
}
+
self.__m_qdomains[l_lqdomain]['SOA'] = l_rr;
def lookup(self, qtype, qdomain, dnspkt, domain_id):

0 comments on commit 964dfc8

Please sign in to comment.