1 # vim: set encoding=utf-8 et sw=4 sts=4 :
3 from pymin import procman
4 from pymin.service.util import Restorable, TransactionalHandler, \
5 ReloadHandler, RestartHandler, \
6 ServiceHandler, ParametersHandler
9 import logging ; log = logging.getLogger('pymin.services.vrrp')
11 __all__ = ('VrrpHandler', 'get_service')
14 def get_service(config):
15 return VrrpHandler(config.vrrp.pickle_dir, config.vrrp.config_dir)
18 # FIXME the the command should not use new parameters unless commit where called
19 # i.e. integrate commit with procman to update internal procman parameters.
20 class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
21 ServiceHandler, TransactionalHandler):
23 handler_help = u"Manage VRRP service"
25 _persistent_attrs = ['params']
27 _restorable_defaults = dict(
29 ipaddress = '192.168.0.1',
39 command = ['vrrpd', '-i', self.params['dev'], '-v', self.params['id']]
40 if self.params['prio']:
41 command.extend(('-p', self.params['prio']))
42 command.append(self.params['ipaddress'])
45 def _service_start(self):
46 log.debug(u'VrrpHandler._service_start()')
47 procinfo = procman.get('vrrp')
48 procinfo.command = self._command
49 procinfo.persist = self.params['persist']
52 def _service_stop(self):
53 log.debug(u'VrrpHandler._service_stop()')
56 def _service_restart(self):
57 procinfo = procman.get('vrrp')
58 procinfo.command = self._command
59 procinfo.persist = self.params['persist']
60 procman.restart('vrrp')
62 def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
63 log.debug(u'VrrpHandler(%r, %r, %r)', pickle_dir, config_dir, pid_dir)
64 self._persistent_dir = pickle_dir
65 self._pid_dir = pid_dir
66 procman.register('vrrp', None)
67 ServiceHandler.__init__(self)
70 if __name__ == '__main__':
73 level = logging.DEBUG,
74 format = '%(asctime)s %(levelname)-8s %(message)s',