]> git.llucax.com Git - software/pymin.git/blob - pymin/services/vrrp/__init__.py
8f5a0037ab065a09e6028edf7217ffb58017ddd7
[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 pid_filename = 'vrrp.pid'
13
14 class VrrpHandler(Restorable, ParametersHandler, TransactionalHandler):
15     handler_help = u"Manage VRRP service"
16
17     _persistent_attrs = 'params'
18
19     _restorable_defaults = dict(
20                             params = dict( ipaddress='192.168.0.1',
21                                             id = '1',
22                                             prio = '',
23                                             dev = 'eth0',
24                                     ),
25                             )
26
27     def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
28         self._persistent_dir = pickle_dir
29         self._pid_dir = pid_dir
30         self._restore()
31
32     @handler('Starts the service')
33     def start(self):
34         if self.params['prio'] != '':
35             #call(('vrrp','-i',self.params[dev],'-v',self.params[id],'-p',self.params[prio],self.params[ipaddress]))
36             print ('vrrp','-i',self.params['dev'],'-v',self.params['id'],'-p',self.params['prio'],self.params['ipaddress'])
37         else:
38             #call(('vrrp','-i',self.params[dev],'-v',self.params[id],self.params[ipaddress]))
39             print ('vrrp','-i',self.params['dev'],'-v',self.params['id'],self.params['ipaddress'])
40
41     @handler('Stop the service')
42     def stop(self):
43         try :
44             f = file(path.join(self._pid_dir, pid_filename ), 'r')
45             #call(('kill','<',f.read()))
46             print(('kill','<',f.read()))
47         except IOError:
48             pass
49
50     @handler('Reloads the service')
51     def reload(self):
52         self.stop()
53         self.start()
54
55
56 if __name__ == '__main__':
57     v = VrrpHandler()
58     v.set('prio','10')
59     v.commit()