+ @handler(u'Start one or all the connections.')
+ def start(self, name=None):
+ log.debug(u'PppHandler.start(%r)', name)
+ 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:
+ log.debug(u'PppHandler.start: starting connection %r', name)
+ call(('pppd', 'call', name))
+ self.conns[name]._running = True
+ self._dump_attr('conns')
+ else:
+ log.debug(u'PppHandler.start: connection not found')
+ raise ConnectionNotFoundError(name)
+
+ @handler(u'Stop one or all the connections.')
+ def stop(self, name=None):
+ log.debug(u'PppHandler.stop(%r)', name)
+ names = [name]
+ names = [name]
+ if name is None:
+ names = self.conns.keys()
+ for name in names:
+ if name in self.conns:
+ if self.conns[name]._running:
+ pid_file = '/var/run/ppp-' + name + '.pid'
+ log.debug(u'PppHandler.stop: getting pid from %r', pid_file)
+ if path.exists(pid_file):
+ pid = file(pid_file).readline()
+ pid = int(pid.strip())
+ try:
+ log.debug(u'PppHandler.stop: killing pid %r', pid)
+ os.kill(pid, SIGTERM)
+ except OSError, e:
+ log.debug(u'PppHandler.stop: error killing: %r', e)
+ else:
+ log.debug(u'PppHandler.stop: pid file not found')
+ self.conns[name]._running = False
+ self._dump_attr('conns')
+ else:
+ log.debug(u'PppHandler.stop: connection not running')
+ else:
+ log.debug(u'PppHandler.stop: connection not found')
+ raise ConnectionNotFoundError(name)
+
+ @handler(u'Restart one or all the connections (even disconnected ones).')
+ def restart(self, name=None):
+ log.debug(u'PppHandler.restart(%r)', name)
+ 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."
+ log.debug(u'PppHandler.reload(%r)', name)
+ 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."
+ log.debug(u'PppHandler.running(%r)', name)
+ if name is None:
+ return [c.name for c in self.conns.values() if c._running]