From: Leandro Lucarella Date: Thu, 26 Jun 2008 00:37:17 +0000 (-0300) Subject: Add validation to DnsHandler (refs #20) X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/1917762a115dee700b1abea8ea3072042fab8232 Add validation to DnsHandler (refs #20) --- diff --git a/services/dns/host.py b/services/dns/host.py index 20ce0d5..fecd7c6 100644 --- a/services/dns/host.py +++ b/services/dns/host.py @@ -1,20 +1,16 @@ # vim: set encoding=utf-8 et sw=4 sts=4 : -# TODO documentation, validation +# TODO documentation -from pymin.seqtools import Sequence +from pymin.validation import Item, Field, HostName, IPAddress 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 Host(Item): + name = Field(HostName(not_empty=True)) + ip = Field(IPAddress(not_empty=True)) class HostHandler(DictComposedSubHandler): handler_help = u"Manage DNS hosts" diff --git a/services/dns/mx.py b/services/dns/mx.py index ec7fc82..fa2c0cf 100644 --- a/services/dns/mx.py +++ b/services/dns/mx.py @@ -1,21 +1,16 @@ # vim: set encoding=utf-8 et sw=4 sts=4 : -# TODO documentation, validation +# TODO documentation -from pymin.seqtools import Sequence +from pymin.validation import Item, Field, FullyQualifiedHostName, UInt16 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 MailExchange(Item): + mx = Field(FullyQualifiedHostName(not_empty=True)) + prio = Field(UInt16(not_empty=True)) class MailExchangeHandler(DictComposedSubHandler): handler_help = u"Manage DNS mail exchangers (MX)" diff --git a/services/dns/ns.py b/services/dns/ns.py index f5b63ac..510ec31 100644 --- a/services/dns/ns.py +++ b/services/dns/ns.py @@ -1,18 +1,15 @@ # vim: set encoding=utf-8 et sw=4 sts=4 : -# TODO documentation, validation +# TODO documentation -from pymin.seqtools import Sequence +from pymin.validation import Item, Field, FullyQualifiedHostName 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 NameServer(Item): + name = Field(FullyQualifiedHostName(not_empty=True)) class NameServerHandler(DictComposedSubHandler): handler_help = u"Manage DNS name servers (NS)" diff --git a/services/dns/zone.py b/services/dns/zone.py index f91fcc7..2e33382 100644 --- a/services/dns/zone.py +++ b/services/dns/zone.py @@ -1,24 +1,23 @@ # vim: set encoding=utf-8 et sw=4 sts=4 : -# TODO documentation, validation +# TODO documentation -from pymin.seqtools import Sequence +from pymin.validation import Item, Field, FullyQualifiedHostName from pymin.service.util import DictSubHandler __all__ = ('DnsHandler',) -class Zone(Sequence): - def __init__(self, name): - self.name = name +class Zone(Item): + name = Field(FullyQualifiedHostName(not_empty=True)) + def __init__(self, *args, **kwargs): + Item.__init__(self, *args, **kwargs) 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"