]> git.llucax.com Git - software/pymin.git/blob - services/proxy/handler.py
Add GPL v3 license to the project
[software/pymin.git] / services / proxy / handler.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 from os import path
4 import logging ; log = logging.getLogger('pymin.services.proxy')
5
6 from pymin.service.util import Restorable, ConfigWriter, InitdHandler, \
7                                TransactionalHandler, ParametersHandler
8
9 from host import HostHandler
10 from user import UserHandler
11
12 __all__ = ('ProxyHandler',)
13
14
15 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
16                    TransactionalHandler, ParametersHandler):
17
18     handler_help = u"Manage proxy service"
19
20     _initd_name = 'squid'
21
22     _persistent_attrs = ('params', 'hosts', 'users')
23
24     _restorable_defaults = dict(
25             hosts = dict(),
26             params  = dict(
27                 ip   = '192.168.0.1',
28                 port = '8080',
29             ),
30             users = dict(),
31     )
32
33     _config_writer_files = ('squid.conf','users.conf')
34     _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
35
36     def __init__(self, pickle_dir='.', config_dir='.'):
37         r"Initialize DhcpHandler object, see class documentation for details."
38         log.debug(u'ProxyHandler(%r, %r)', pickle_dir, config_dir)
39         self._persistent_dir = pickle_dir
40         self._config_writer_cfg_dir = config_dir
41         self._config_build_templates()
42         InitdHandler.__init__(self)
43         self.host = HostHandler(self)
44         self.user = UserHandler(self)
45
46     def _get_config_vars(self, config_file):
47         if config_file == 'squid.conf':
48             return dict(hosts=self.hosts.values(), **self.params)
49         return dict(users=self.users)
50
51
52 if __name__ == '__main__':
53
54     logging.basicConfig(
55         level   = logging.DEBUG,
56         format  = '%(asctime)s %(levelname)-8s %(message)s',
57         datefmt = '%H:%M:%S',
58     )
59
60     px = ProxyHandler()
61     px.set('ip','192.66.66.66')
62     px.set('port','666')
63     px.host.add('192.168.0.25.25')
64     px.host.add('192.168.0.25.26')
65     px.host.add('192.168.0.25.27')
66     px.host.delete('192.168.0.25.27')
67     px.user.add('lala','soronga')
68     px.user.add('culo','sarasa')
69     px.commit()