]> git.llucax.com Git - software/pymin.git/blob - services/vrrp/handler.py
Move logging module setup to pymind.
[software/pymin.git] / services / vrrp / handler.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 import logging ; log = logging.getLogger('pymin.services.vrrp')
4
5 from pymin import procman
6 from pymin.service.util import Restorable, TransactionalHandler, \
7                                ReloadHandler, RestartHandler, \
8                                ServiceHandler, ParametersHandler
9
10 __all__ = ('VrrpHandler')
11
12
13 # FIXME the the command should not use new parameters unless commit where called
14 #       i.e. integrate commit with procman to update internal procman parameters.
15 class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
16                         ServiceHandler, TransactionalHandler):
17
18     handler_help = u"Manage VRRP service"
19
20     _persistent_attrs = ['params']
21
22     _restorable_defaults = dict(
23         params = dict(
24                 ipaddress = '192.168.0.1',
25                 id        = '1',
26                 prio      = '',
27                 dev       = 'eth0',
28                 persist   = True,
29             ),
30         )
31
32     @property
33     def _command(self):
34         command = ['vrrpd', '-i', self.params['dev'], '-v', self.params['id']]
35         if self.params['prio']:
36             command.extend(('-p', self.params['prio']))
37         command.append(self.params['ipaddress'])
38         return command
39
40     def _service_start(self):
41         log.debug(u'VrrpHandler._service_start()')
42         procinfo = procman.get('vrrp')
43         procinfo.command = self._command
44         procinfo.persist = self.params['persist']
45         procman.start('vrrp')
46
47     def _service_stop(self):
48         log.debug(u'VrrpHandler._service_stop()')
49         procman.stop('vrrp')
50
51     def _service_restart(self):
52         procinfo = procman.get('vrrp')
53         procinfo.command = self._command
54         procinfo.persist = self.params['persist']
55         procman.restart('vrrp')
56
57     def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
58         log.debug(u'VrrpHandler(%r, %r, %r)', pickle_dir, config_dir, pid_dir)
59         self._persistent_dir = pickle_dir
60         self._pid_dir = pid_dir
61         procman.register('vrrp', None)
62         ServiceHandler.__init__(self)
63
64
65 if __name__ == '__main__':
66
67     logging.basicConfig(
68         level   = logging.DEBUG,
69         format  = '%(asctime)s %(levelname)-8s %(message)s',
70         datefmt = '%H:%M:%S',
71     )
72
73     v = VrrpHandler()
74     v.set('prio', '10')
75     v.commit()
76