]> git.llucax.com Git - software/pymin.git/blobdiff - services/vpn/handler.py
Add validation to vpn service (refs #20)
[software/pymin.git] / services / vpn / handler.py
index a628f79811146f22132068b7ec46538aad65a07e..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,30 +17,18 @@ from host import HostHandler
 __all__ = ('VpnHandler',)
 
 
-class Vpn(Sequence):
-    def __init__(self, name, connect_to, local_ip, mask,
-                 public_key=None, private_key=None):
-        self.name = name
-        self.connect_to = connect_to
-        self.local_ip = local_ip
-        self.mask = mask
-        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_ip, self.mask,
-                self.public_key, self.private_key)
-
-    def update(self, connect_to=None, local_ip=None, mask=None):
-        if connect_to is not None:
-            self.connect_to = connect_to
-        if local_ip is not None:
-            self.local_ip = local_ip
-        if mask is not None:
-            self.mask = mask
-
 
 class VpnHandler(Restorable, ConfigWriter,
                    TransactionalHandler, DictSubHandler):