]> git.llucax.com Git - software/pymin.git/blob - services/ppp/conn.py
Split ppp handler in submodules (refs #2).
[software/pymin.git] / services / ppp / conn.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 from pymin.seqtools import Sequence
4 from pymin.service.util import DictSubHandler
5
6 __all__ = ('ConnectionHandler',)
7
8
9 class Connection(Sequence):
10
11     def __init__(self, name, username, password, type, **kw):
12         self.name = name
13         self.username = username
14         self.password = password
15         self.type = type
16         self._running = False
17         if type == 'OE':
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('\\','\\\\')
26         elif type == 'PPP':
27             if not 'device' in kw:
28                 raise ConnectionError('Bad arguments for type=PPP')
29             self.device = kw['device']
30         else:
31             raise ConnectionError('Bad arguments, unknown or unspecified type')
32
33     def as_tuple(self):
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)
38
39     def update(self, device=None, username=None, password=None):
40         if device is not None:
41             self.device = device
42         if username is not None:
43             self.username = username
44         if password is not None:
45             self.password = password
46
47
48 class ConnectionHandler(DictSubHandler):
49
50     handler_help = u"Manages connections for the ppp service"
51
52     _cont_subhandler_attr = 'conns'
53     _cont_subhandler_class = Connection
54