1 # vim: set encoding=utf-8 et sw=4 sts=4 :
4 import logging ; log = logging.getLogger('pymin.services.proxy')
6 from pymin.service.util import Restorable, ConfigWriter, InitdHandler, \
7 TransactionalHandler, ParametersHandler
9 from host import HostHandler
10 from user import UserHandler
12 __all__ = ('ProxyHandler',)
15 class ProxyHandler(Restorable, ConfigWriter, InitdHandler,
16 TransactionalHandler, ParametersHandler):
18 handler_help = u"Manage proxy service"
22 _persistent_attrs = ('params', 'hosts', 'users')
24 _restorable_defaults = dict(
33 _config_writer_files = ('squid.conf','users.conf')
34 _config_writer_tpl_dir = path.join(path.dirname(__file__), 'templates')
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)
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)
52 if __name__ == '__main__':
55 level = logging.DEBUG,
56 format = '%(asctime)s %(levelname)-8s %(message)s',
61 px.set('ip','192.66.66.66')
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')