]> git.llucax.com Git - software/pymin.git/commitdiff
Merge commit 'nico-baryon/master'
authorLeandro Lucarella <llucax@gmail.com>
Mon, 22 Oct 2007 16:11:43 +0000 (13:11 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Mon, 22 Oct 2007 16:11:43 +0000 (13:11 -0300)
Conflicts:

pymin/services/ppp/__init__.py
pymin/services/vrrp/__init__.py

1  2 
pymin/services/ppp/__init__.py
pymin/services/vrrp/__init__.py

index 91070e79cc652441b6909e36cda6a06a31939aab,868b6d59330729a946309128ef91e85f99c9a31a..c251e5025a25f00c12f4106d7d970f52296bfa10
@@@ -1,6 -1,6 +1,8 @@@
  # vim: set encoding=utf-8 et sw=4 sts=4 :
  
++import os
  from os import path
++from signal import SIGTERM
  
  from pymin.seqtools import Sequence
  from pymin.dispatcher import Handler, handler, HandlerError
@@@ -90,67 -89,23 +92,73 @@@ class PppHandler(Restorable, ConfigWrit
          self._config_writer_cfg_dir = config_dir
          self._config_build_templates()
          self._restore()
 +        for conn in self.conns.values():
 +            if conn._running:
 +                conn._running = False
 +                self.start(conn.name)
          self.conn = ConnectionHandler(self)
  
 -    @handler('Starts the service')
 -    def start(self, name):
 -        if name in self.conns:
 -            call(['pppd','call', name],stdout=None, stderr=None)
 -            #print ('pon', name)
 -        else:
 -            raise ConnectionNotFoundError(name)
 -
 -    @handler('Stops the service')
 -    def stop(self, name):
 +    @handler(u'Start one or all the connections.')
 +    def start(self, name=None):
 +        names = [name]
 +        if name is None:
 +            names = self.conns.keys()
 +        for name in names:
 +            if name in self.conns:
 +                if not self.conns[name]._running:
-                     call(('pon', name))
++                    call(('pppd', 'call', name))
 +                    self.conns[name]._running = True
 +                    self._dump_attr('conns')
 +            else:
 +                raise ConnectionNotFoundError(name)
 +
 +    @handler(u'Stop one or all the connections.')
 +    def stop(self, name=None):
 +        names = [name]
 +        if name is None:
 +            names = self.conns.keys()
 +        for name in names:
 +            if name in self.conns:
 +                if self.conns[name]._running:
 +                    call(('poff', name))
++                    if path.exists('/var/run/ppp-' + name + '.pid'):
++                        pid = file('/var/run/ppp-' + name + '.pid').readline()
++                        try:
++                            os.kill(int(pid.strip()), SIGTERM)
++                        except OSError:
++                            pass # XXX report error?
 +                    self.conns[name]._running = False
 +                    self._dump_attr('conns')
 +            else:
 +                raise ConnectionNotFoundError(name)
 +
 +    @handler(u'Restart one or all the connections (even disconnected ones).')
 +    def restart(self, name=None):
 +        names = [name]
 +        if name is None:
 +            names = self.conns.keys()
 +        for name in names:
 +            self.stop(name)
 +            self.start(name)
 +
 +    @handler(u'Restart only one or all the already running connections.')
 +    def reload(self, name=None):
 +        r"reload() -> None :: Reload the configuration of the service."
 +        names = [name]
 +        if name is None:
 +            names = self.conns.keys()
 +        for name in names:
 +            if self.conns[name]._running:
 +                self.stop(name)
 +                self.start(name)
 +
 +    @handler(u'Tell if the service is running.')
 +    def running(self, name=None):
 +        r"reload() -> None :: Reload the configuration of the service."
 +        if name is None:
 +            return [c.name for c in self.conns.values() if c._running]
          if name in self.conns:
 -            if path.exists('/var/run/ppp-' + name + '.pid'):
 -                pid = file('/var/run/ppp-' + name + '.pid').readline().strip()
 -                call(['kill',pid],stdout=None, stderr=None)
 -            #print ('poff', name)
 +            return int(self.conns[name]._running)
          else:
              raise ConnectionNotFoundError(name)
  
@@@ -185,3 -146,3 +193,4 @@@ if __name__ == '__main__'
      p.commit()
      print p.conn.list()
      print p.conn.show()
++
index c8563a699b6923f091ea50be67532ddf94121d26,580d4e69a23ec42540e65b6b1345601c3fa76770..403cd364fdac153229282e8fb6230cc921680eb3
@@@ -13,14 -9,10 +13,12 @@@ from pymin.services.util import Restora
  
  __ALL__ = ('VrrpHandler',)
  
- pid_filename = 'vrrp.pid'
 -class VrrpHandler(Restorable, ParametersHandler, TransactionalHandler):
 +class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
 +                        ServiceHandler, TransactionalHandler):
 +
      handler_help = u"Manage VRRP service"
  
 -    _persistent_attrs = 'params'
 +    _persistent_attrs = ['params']
  
      _restorable_defaults = dict(
                              params = dict( ipaddress='192.168.0.1',
                                      ),
                              )
  
 -    def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
 -        self._persistent_dir = pickle_dir
 -        self._pid_dir = pid_dir
 -        self._restore()
 -
 -    @handler('Starts the service')
 -    def start(self):
 +    def _service_start(self):
          if self.params['prio'] != '':
 -            call(('/usr/local/bin/vrrpd','-i',self.params['dev'],'-v',self.params['id'],'-p',self.params['prio'],self.params['ipaddress']))
 -            #print ('vrrpd','-i',self.params['dev'],'-v',self.params['id'],'-p',self.params['prio'],self.params['ipaddress'])
 +            call(('vrrp', '-i', self.params['dev'], '-v', self.params['id'],
 +                    '-p', self.params['prio'], self.params['ipaddress']))
          else:
 -            call(('/usr/local/bin/vrrpd','-i',self.params['dev'],'-v',self.params['id'],self.params['ipaddress']))
 -            #print ('vrrpd','-i',self.params['dev'],'-v',self.params['id'],self.params['ipaddress'])
 -
 -    @handler('Stop the service')
 -    def stop(self):
 -        try :
 -            pid = 'vrrpd' + '_' + self.params['dev'] + '_' + self.params['id'] + '.pid'
 -            f = file(path.join(self._pid_dir, pid ), 'r')
 -            call(('kill',f.read().strip('\n')))
 -            #print('kill','<',f.read())
 -        except IOError:
 +            call(('vrrp', '-i', self.params['dev'], '-v', self.params['id'], \
 +                    self.params['ipaddress']))
 +
 +    def _service_stop(self):
 +        try:
++            pid_filename = 'vrrpd_%(dev)s_%(id)s.pid' % self.params
 +            pid = file(path.join(self._pid_dir, pid_filename )).read().strip()
 +            os.kill(int(pid), SIGTERM)
 +        except (IOError, OSError):
 +            # TODO log
              pass
  
 -    @handler('Reloads the service')
 -    def reload(self):
 -        self.stop()
 -        self.start()
 +    def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
 +        self._persistent_dir = pickle_dir
 +        self._pid_dir = pid_dir
 +        ServiceHandler.__init__(self)
  
  
  if __name__ == '__main__':
      v = VrrpHandler()
      v.set('prio','10')
-     v.commit()
+     v.commit()
++