]> git.llucax.com Git - software/pymin.git/blob - pymin/services/vrrp/__init__.py
Merge branch 'master' of git.llucax.com.ar:/var/lib/git/software/pymin into procman
[software/pymin.git] / pymin / services / vrrp / __init__.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 import os
4 from os import path
5 from signal import SIGTERM
6 from subprocess import Popen, PIPE
7
8 from pymin import procman
9 from pymin.seqtools import Sequence
10 from pymin.dispatcher import Handler, handler, HandlerError
11 from pymin.services.util import Restorable, TransactionalHandler, \
12                                 ReloadHandler, RestartHandler, \
13                                 ServiceHandler, ParametersHandler, call
14
15 __ALL__ = ('VrrpHandler',)
16
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):
21
22     handler_help = u"Manage VRRP service"
23
24     _persistent_attrs = ['params']
25
26     _restorable_defaults = dict(
27         params = dict(
28                 ipaddress = '192.168.0.1',
29                 id        = '1',
30                 prio      = '',
31                 dev       = 'eth0',
32                 persist   = True,
33             ),
34         )
35
36     @property
37     def _command(self):
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'])
42         return command
43
44     def _service_start(self):
45         procinfo = procman.get('vrrp')
46         procinfo.command = self._command
47         procinfo.persist = self.params['persist']
48         procman.start('vrrp')
49
50     def _service_stop(self):
51         procman.stop('vrrp')
52
53     def _service_restart(self):
54         procinfo = procman.get('vrrp')
55         procinfo.command = self._command
56         procinfo.persist = self.params['persist']
57         procman.restart('vrrp')
58
59     def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
60         self._persistent_dir = pickle_dir
61         self._pid_dir = pid_dir
62         procman.register('vrrp', None)
63         ServiceHandler.__init__(self)
64
65
66 if __name__ == '__main__':
67     v = VrrpHandler()
68     v.set('prio','10')
69     v.commit()
70