From f79fe24d7dae27f6cb31745f24256b01755aad8d Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 20 Jun 2008 01:03:01 -0300 Subject: [PATCH] Split dns handler in submodules (refs #2). --- services/dns/handler.py | 88 ++++++----------------------------------- services/dns/host.py | 24 +++++++++++ services/dns/mx.py | 25 ++++++++++++ services/dns/ns.py | 22 +++++++++++ services/dns/zone.py | 27 +++++++++++++ 5 files changed, 109 insertions(+), 77 deletions(-) create mode 100644 services/dns/host.py create mode 100644 services/dns/mx.py create mode 100644 services/dns/ns.py create mode 100644 services/dns/zone.py diff --git a/services/dns/handler.py b/services/dns/handler.py index fb66923..6b05225 100644 --- a/services/dns/handler.py +++ b/services/dns/handler.py @@ -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 index 0000000..20ce0d5 --- /dev/null +++ b/services/dns/host.py @@ -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 index 0000000..ec7fc82 --- /dev/null +++ b/services/dns/mx.py @@ -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 index 0000000..f5b63ac --- /dev/null +++ b/services/dns/ns.py @@ -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 index 0000000..f91fcc7 --- /dev/null +++ b/services/dns/zone.py @@ -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 + -- 2.43.0