+ except ExecutionError, e:
+ print e
+
+ def handle_timer(self):
+ self.refresh_devices()
+
+
+ def refresh_devices(self):
+ devices = get_network_devices()
+ #add not registered and active devices
+ go_active = False
+ for k,v in devices.items():
+ if k not in self.devices:
+ self.devices[k] = v
+ elif not self.devices[k].active:
+ self.active = True
+ go_active = True
+ self._write_config_for_device(self.devices[k])
+ if go_active:
+ self._write_hops()
+ self._bring_up_no_dev_routes()
+ self._restart_services()
+
+ #mark inactive devices
+ for k in self.devices.keys():
+ go_down = False
+ if k not in devices:
+ self.devices[k].active = False
+ go_down = True
+ if go_down:
+ self._bring_up_no_dev_routes()
+
+ def _restart_services(self):
+ for s in self.services:
+ if s._service_running:
+ try:
+ s.stop()
+ except ExecutionError:
+ pass
+ try:
+ s.start()
+ except ExecutionError:
+ pass
+
+ #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'):
+ self.services.append(serv)
+
+
+