From dd0f8fb145c838049cfc8a551de5e68bd964cb4f Mon Sep 17 00:00:00 2001 From: Nicolas Emiliani Date: Mon, 26 Nov 2007 09:52:34 -0300 Subject: [PATCH] Added support to hook services to IPHandler. A service that has to be restarted after detection of a device bring up, can be hooked to do so by calling the method device_up_hook. The service while be added to the hook list only in case it has the attributes start and stop. --- pymin/services/ip/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pymin/services/ip/__init__.py b/pymin/services/ip/__init__.py index 965e812..1c0b646 100644 --- a/pymin/services/ip/__init__.py +++ b/pymin/services/ip/__init__.py @@ -173,6 +173,7 @@ class IpHandler(Restorable, ConfigWriter, TransactionalHandler): self.route = RouteHandler(self) self.dev = DeviceHandler(self) self.hop = HopHandler(self) + self.services = list() def _write_config(self): r"_write_config() -> None :: Execute all commands." @@ -256,11 +257,31 @@ class IpHandler(Restorable, ConfigWriter, TransactionalHandler): self._write_config_for_device(self.devices[k]) if go_active: self._write_hops() + for s in services: + if s._running: + try: + s.stop() + except ExecutionError: + pass + try: + s.start() + except ExecutionError: + pass + #mark inactive devices for k in self.devices.keys(): if k not in devices: self.devices[k].active = False + #hooks a service to the ip handler, so when + #a device is brought up one can restart the service + #that need to refresh their device list + def device_up_hook(self, serv): + if hasattr(serv, 'stop') and hasattr(serv, 'start') + services.append(serv) + + + if __name__ == '__main__': -- 2.43.0