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', 'get_service')
13 def get_service(config):
14 return VrrpHandler(config.vrrp.pickle_dir, config.vrrp.config_dir)
17 # FIXME the the command should not use new parameters unless commit where called
18 # i.e. integrate commit with procman to update internal procman parameters.
19 class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
20 ServiceHandler, TransactionalHandler):
22 handler_help = u"Manage VRRP service"
24 _persistent_attrs = ['params']
26 _restorable_defaults = dict(
28 ipaddress = '192.168.0.1',
38 command = ['vrrpd', '-i', self.params['dev'], '-v', self.params['id']]
39 if self.params['prio']:
40 command.extend(('-p', self.params['prio']))
41 command.append(self.params['ipaddress'])
44 def _service_start(self):
45 log.debug(u'VrrpHandler._service_start()')
46 procinfo = procman.get('vrrp')
47 procinfo.command = self._command
48 procinfo.persist = self.params['persist']
51 def _service_stop(self):
52 log.debug(u'VrrpHandler._service_stop()')
55 def _service_restart(self):
56 procinfo = procman.get('vrrp')
57 procinfo.command = self._command
58 procinfo.persist = self.params['persist']
59 procman.restart('vrrp')
61 def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
62 log.debug(u'VrrpHandler(%r, %r, %r)', pickle_dir, config_dir, pid_dir)
63 self._persistent_dir = pickle_dir
64 self._pid_dir = pid_dir
65 procman.register('vrrp', None)
66 ServiceHandler.__init__(self)
69 if __name__ == '__main__':
72 level = logging.DEBUG,
73 format = '%(asctime)s %(levelname)-8s %(message)s',