]> git.llucax.com Git - software/pymin.git/commitdiff
Split dns handler in submodules (refs #2).
authorLeandro Lucarella <llucax@gmail.com>
Fri, 20 Jun 2008 04:03:01 +0000 (01:03 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Fri, 20 Jun 2008 04:12:26 +0000 (01:12 -0300)
services/dns/handler.py
services/dns/host.py [new file with mode: 0644]
services/dns/mx.py [new file with mode: 0644]
services/dns/ns.py [new file with mode: 0644]
services/dns/zone.py [new file with mode: 0644]

index fb6692373a4fb05affc1400901cff270d270a072..6b0522518d7d8aa84fc90c240786f810153d9f3f 100644 (file)
@@ -1,77 +1,22 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-# TODO COMMENT
+# TODO documentation, validation
+
 from os import path
 from os import unlink
 import logging ; log = logging.getLogger('pymin.services.dns')
 
-from pymin.seqtools import Sequence
-from pymin.dispatcher import handler, HandlerError, Handler
-from pymin.service.util import Restorable, ConfigWriter, InitdHandler, \
+from pymin.service.util import Restorable, ConfigWriter, \
                                TransactionalHandler, ParametersHandler, \
-                               DictComposedSubHandler, DictSubHandler, call
-
-__all__ = ('DnsHandler')
-
-
-class Host(Sequence):
-    def __init__(self, name, ip):
-        self.name = name
-        self.ip = ip
-    def update(self, ip=None):
-        if ip is not None: self.ip = ip
-    def as_tuple(self):
-        return (self.name, self.ip)
-
-class HostHandler(DictComposedSubHandler):
-    handler_help = u"Manage DNS hosts"
-    _comp_subhandler_cont = 'zones'
-    _comp_subhandler_attr = 'hosts'
-    _comp_subhandler_class = Host
-
-class MailExchange(Sequence):
-    def __init__(self, mx, prio):
-        self.mx = mx
-        self.prio = prio
-    def update(self, prio=None):
-        if prio is not None: self.prio = prio
-    def as_tuple(self):
-        return (self.mx, self.prio)
-
-class MailExchangeHandler(DictComposedSubHandler):
-    handler_help = u"Manage DNS mail exchangers (MX)"
-    _comp_subhandler_cont = 'zones'
-    _comp_subhandler_attr = 'mxs'
-    _comp_subhandler_class = MailExchange
-
-class NameServer(Sequence):
-    def __init__(self, name):
-        self.name = name
-    def as_tuple(self):
-        return (self.name,)
-
-class NameServerHandler(DictComposedSubHandler):
-    handler_help = u"Manage DNS name servers (NS)"
-    _comp_subhandler_cont = 'zones'
-    _comp_subhandler_attr = 'nss'
-    _comp_subhandler_class = NameServer
-
-class Zone(Sequence):
-    def __init__(self, name):
-        self.name = name
-        self.hosts = dict()
-        self.mxs = dict()
-        self.nss = dict()
-        self._add = False
-        self._update = False
-        self._delete = False
-    def as_tuple(self):
-        return (self.name, self.hosts, self.mxs, self.nss)
+                               InitdHandler, call
+
+from host import HostHandler
+from mx import MailExchangeHandler
+from ns import NameServerHandler
+from zone import ZoneHandler
+
+__all__ = ('DnsHandler',)
 
-class ZoneHandler(DictSubHandler):
-    handler_help = u"Manage DNS zones"
-    _cont_subhandler_attr = 'zones'
-    _cont_subhandler_class = Zone
 
 class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler,
                  ParametersHandler):
@@ -239,12 +184,6 @@ if __name__ == '__main__':
     for z in dns.zones:
         print 'HOSTS from', z, ':', dns.host.show(z)
 
-    #test zone errors
-    #try:
-    #    dns.zone.update('zone-sarasa','lalal')
-    #except ZoneNotFoundError, inst:
-    #    print 'Error: ', inst
-
     from pymin.services.util import ItemNotFoundError, ItemAlreadyExistsError, \
                                     ContainerNotFoundError
 
@@ -253,11 +192,6 @@ if __name__ == '__main__':
     except ItemNotFoundError, inst:
         print 'Error: ', inst
 
-    #try:
-    #    dns.zone.add('zona_loca.com','ns1.dom.com','ns2.dom.com')
-    #except ZoneAlreadyExistsError, inst:
-    #    print 'Error: ', inst
-
 
     #test hosts errors
     try:
diff --git a/services/dns/host.py b/services/dns/host.py
new file mode 100644 (file)
index 0000000..20ce0d5
--- /dev/null
@@ -0,0 +1,24 @@
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+# TODO documentation, validation
+
+from pymin.seqtools import Sequence
+from pymin.service.util import DictComposedSubHandler
+
+__all__ = ('HostHandler',)
+
+class Host(Sequence):
+    def __init__(self, name, ip):
+        self.name = name
+        self.ip = ip
+    def update(self, ip=None):
+        if ip is not None: self.ip = ip
+    def as_tuple(self):
+        return (self.name, self.ip)
+
+class HostHandler(DictComposedSubHandler):
+    handler_help = u"Manage DNS hosts"
+    _comp_subhandler_cont = 'zones'
+    _comp_subhandler_attr = 'hosts'
+    _comp_subhandler_class = Host
+
diff --git a/services/dns/mx.py b/services/dns/mx.py
new file mode 100644 (file)
index 0000000..ec7fc82
--- /dev/null
@@ -0,0 +1,25 @@
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+# TODO documentation, validation
+
+from pymin.seqtools import Sequence
+from pymin.service.util import DictComposedSubHandler
+
+__all__ = ('MailExchangeHandler',)
+
+
+class MailExchange(Sequence):
+    def __init__(self, mx, prio):
+        self.mx = mx
+        self.prio = prio
+    def update(self, prio=None):
+        if prio is not None: self.prio = prio
+    def as_tuple(self):
+        return (self.mx, self.prio)
+
+class MailExchangeHandler(DictComposedSubHandler):
+    handler_help = u"Manage DNS mail exchangers (MX)"
+    _comp_subhandler_cont = 'zones'
+    _comp_subhandler_attr = 'mxs'
+    _comp_subhandler_class = MailExchange
+
diff --git a/services/dns/ns.py b/services/dns/ns.py
new file mode 100644 (file)
index 0000000..f5b63ac
--- /dev/null
@@ -0,0 +1,22 @@
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+# TODO documentation, validation
+
+from pymin.seqtools import Sequence
+from pymin.service.util import DictComposedSubHandler
+
+__all__ = ('NameServerHandler',)
+
+
+class NameServer(Sequence):
+    def __init__(self, name):
+        self.name = name
+    def as_tuple(self):
+        return (self.name,)
+
+class NameServerHandler(DictComposedSubHandler):
+    handler_help = u"Manage DNS name servers (NS)"
+    _comp_subhandler_cont = 'zones'
+    _comp_subhandler_attr = 'nss'
+    _comp_subhandler_class = NameServer
+
diff --git a/services/dns/zone.py b/services/dns/zone.py
new file mode 100644 (file)
index 0000000..f91fcc7
--- /dev/null
@@ -0,0 +1,27 @@
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+# TODO documentation, validation
+
+from pymin.seqtools import Sequence
+from pymin.service.util import DictSubHandler
+
+__all__ = ('DnsHandler',)
+
+
+class Zone(Sequence):
+    def __init__(self, name):
+        self.name = name
+        self.hosts = dict()
+        self.mxs = dict()
+        self.nss = dict()
+        self._add = False
+        self._update = False
+        self._delete = False
+    def as_tuple(self):
+        return (self.name, self.hosts, self.mxs, self.nss)
+
+class ZoneHandler(DictSubHandler):
+    handler_help = u"Manage DNS zones"
+    _cont_subhandler_attr = 'zones'
+    _cont_subhandler_class = Zone
+