]> git.llucax.com Git - software/pymin.git/blob - pymin/services/vrrp/__init__.py
Merge branch 'master' into suse
[software/pymin.git] / pymin / services / vrrp / __init__.py
1 # vim: set encoding=utf-8 et sw=4 sts=4 :
2
3 from os import path
4 from subprocess import Popen, PIPE
5
6 from pymin.seqtools import Sequence
7 from pymin.dispatcher import Handler, handler, HandlerError
8 from pymin.services.util import Restorable, TransactionalHandler, ParametersHandler, call
9
10 __ALL__ = ('VrrpHandler',)
11
12 class VrrpHandler(Restorable, ParametersHandler, TransactionalHandler):
13     handler_help = u"Manage VRRP service"
14
15     _persistent_attrs = 'params'
16
17     _restorable_defaults = dict(
18                             params = dict( ipaddress='192.168.0.1',
19                                             id = '1',
20                                             prio = '',
21                                             dev = 'eth0',
22                                     ),
23                             )
24
25     def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
26         self._persistent_dir = pickle_dir
27         self._pid_dir = pid_dir
28         self._restore()
29
30     @handler('Starts the service')
31     def start(self):
32         if self.params['prio'] != '':
33             call(('/usr/local/bin/vrrpd','-i',self.params['dev'],'-v',self.params['id'],'-p',self.params['prio'],self.params['ipaddress']))
34             #print ('vrrpd','-i',self.params['dev'],'-v',self.params['id'],'-p',self.params['prio'],self.params['ipaddress'])
35         else:
36             call(('/usr/local/bin/vrrpd','-i',self.params['dev'],'-v',self.params['id'],self.params['ipaddress']))
37             #print ('vrrpd','-i',self.params['dev'],'-v',self.params['id'],self.params['ipaddress'])
38
39     @handler('Stop the service')
40     def stop(self):
41         try :
42             pid = 'vrrpd' + '_' + self.params['dev'] + '_' + self.params['id'] + '.pid'
43             f = file(path.join(self._pid_dir, pid ), 'r')
44             call(('kill',f.read().strip('\n')))
45             #print('kill','<',f.read())
46         except IOError:
47             pass
48
49     @handler('Reloads the service')
50     def reload(self):
51         self.stop()
52         self.start()
53
54
55 if __name__ == '__main__':
56     v = VrrpHandler()
57     v.set('prio','10')
58     v.commit()