]> git.llucax.com Git - software/pymin.git/blob - pymin/services/vrrp/__init__.py
Fix a typo in a log message format in VrrpHandler (closes #26).
[software/pymin.git] / pymin / services / vrrp / __init__.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 from pymin import procman
4 from pymin.services.util import Restorable, TransactionalHandler, \
5                                 ReloadHandler, RestartHandler, \
6                                 ServiceHandler, ParametersHandler
7
8 # Logger
9 import logging ; log = logging.getLogger('pymin.services.vrrp')
10
11 __all__ = ('VrrpHandler',)
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