1 # vim: set encoding=utf-8 et sw=4 sts=4 :
3 import logging ; log = logging.getLogger('pymin.services.vrrp')
5 from pymin import procman
6 from pymin.service.util import Restorable, TransactionalHandler, \
7 ReloadHandler, RestartHandler, \
8 ServiceHandler, ParametersHandler
10 __all__ = ('VrrpHandler')
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):
18 handler_help = u"Manage VRRP service"
20 _persistent_attrs = ['params']
22 _restorable_defaults = dict(
24 ipaddress = '192.168.0.1',
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'])
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']
47 def _service_stop(self):
48 log.debug(u'VrrpHandler._service_stop()')
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')
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)
65 if __name__ == '__main__':
68 level = logging.DEBUG,
69 format = '%(asctime)s %(levelname)-8s %(message)s',