]> git.llucax.com Git - software/pymin.git/commitdiff
Add validation to vpn service (refs #20)
authorLeandro Lucarella <llucax@gmail.com>
Sat, 28 Jun 2008 19:50:37 +0000 (16:50 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sat, 28 Jun 2008 19:50:37 +0000 (16:50 -0300)
services/vpn/handler.py
services/vpn/host.py

index 89dfac7845f6f71af22422401a49aa7aeb0a59af..6e63ae51483f68f7122b86579c8a82f872a43315 100644 (file)
@@ -6,7 +6,7 @@ import signal
 from os import path
 import logging ; log = logging.getLogger('pymin.services.vpn')
 
-from pymin.seqtools import Sequence
+from pymin.validation import Item, Field, HostName, CIDR, Validator
 from pymin.dispatcher import handler, HandlerError
 from pymin.service.util import Restorable, ConfigWriter, InitdHandler, \
                                TransactionalHandler, DictSubHandler, \
@@ -17,27 +17,18 @@ from host import HostHandler
 __all__ = ('VpnHandler',)
 
 
-class Vpn(Sequence):
-    def __init__(self, name, connect_to, local_addr,
-                 public_key=None, private_key=None):
-        self.name = name
-        self.connect_to = connect_to
-        self.local_addr = local_addr
-        self.public_key = public_key
-        self.private_key = private_key
+class Vpn(Item):
+    name = Field(HostName(not_empty=True))
+    connect_to = Field(HostName(not_empty=True))
+    local_addr = Field(CIDR(not_empty=True))
+    public_key = Field(Validator)
+    private_key = Field(Validator)
+
+    def __init__(self, *args, **kwargs):
+        Item.__init__(self, *args, **kwargs)
         self.hosts = dict()
         self._delete = False
 
-    def as_tuple(self):
-        return (self.name, self.connect_to, self.local_addr,
-                self.public_key, self.private_key)
-
-    def update(self, connect_to=None, local_addr=None):
-        if connect_to is not None:
-            self.connect_to = connect_to
-        if local_addr is not None:
-            self.local_addr = local_addr
-
 
 class VpnHandler(Restorable, ConfigWriter,
                    TransactionalHandler, DictSubHandler):
index 37afc7413c9bf747dcef989041f53e5aef84d724..f7e18320633382ea2a1835f3f695a9bdd6a69517 100644 (file)
@@ -1,21 +1,16 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-from pymin.seqtools import Sequence
+from pymin.validation import Item, Field, Any, HostName, \
+                             FullyQualifiedHostName, IPAddress, CIDR
 from pymin.service.util import DictComposedSubHandler
 
 __all__ = ('HostHandler',)
 
 
-class Host(Sequence):
-    def __init__(self, name, address, subnet, public_key):
-        self.name = name
-        self.address = address
-        self.subnet = subnet
-        self.public_key = public_key
-        self._delete = False
-
-    def as_tuple(self):
-        return(self.name, self.address, self.subnet, self.public_key)
+class Host(Item):
+    name = Field(HostName(not_empty=True))
+    address = Field(Any(HostName, FullyQualifiedHostName, IPAddress))
+    subnet = Field(CIDR)
 
 class HostHandler(DictComposedSubHandler):