1 # vim: set encoding=utf-8 et sw=4 sts=4 :
3 from pymin.seqtools import Sequence
4 from pymin.service.util import DictSubHandler
6 __all__ = ('ConnectionHandler',)
9 class Connection(Sequence):
11 def __init__(self, name, username, password, type, **kw):
13 self.username = username
14 self.password = password
18 if not 'device' in kw:
19 raise ConnectionError('Bad arguments for type=OE')
20 self.device = kw['device']
21 elif type == 'TUNNEL':
22 if not 'server' in kw:
23 raise ConnectionError('Bad arguments for type=TUNNEL')
24 self.server = kw['server']
25 self.username = self.username.replace('\\','\\\\')
27 if not 'device' in kw:
28 raise ConnectionError('Bad arguments for type=PPP')
29 self.device = kw['device']
31 raise ConnectionError('Bad arguments, unknown or unspecified type')
34 if self.type == 'TUNNEL':
35 return (self.name, self.username, self.password, self.type, self.server)
36 elif self.type == 'PPP' or self.type == 'OE':
37 return (self.name, self.username, self.password, self.type, self.device)
39 def update(self, device=None, username=None, password=None):
40 if device is not None:
42 if username is not None:
43 self.username = username
44 if password is not None:
45 self.password = password
48 class ConnectionHandler(DictSubHandler):
50 handler_help = u"Manages connections for the ppp service"
52 _cont_subhandler_attr = 'conns'
53 _cont_subhandler_class = Connection