+ try:
+ log.debug(u'IpHandler._write_config: adding %r', route)
+ call(self._render_config('route_add', dict(
+ dev = device.name,
+ net_addr = route.net_addr,
+ prefix = route.prefix,
+ gateway = route.gateway,
+ )), shell=True)
+ except ExecutionError, e:
+ log.debug(u'IpHandler._write_config: error adding -> %r', e)
+ if self.hops:
+ log.debug(u'IpHandler._write_config: we have hops: %r', self.hops)
+ try:
+ log.debug(u'IpHandler._write_config: flushing default route')
+ call('ip route del default', shell=True)
+ except ExecutionError, e:
+ log.debug(u'IpHandler._write_config: error adding -> %r', e)
+ try:
+ log.debug(u'IpHandler._write_config: configuring hops')
+ call(self._render_config('hop', dict(
+ hops = self.hops,
+ )
+ ), shell=True)
+ except ExecutionError, e:
+ log.debug(u'IpHandler._write_config: error adding -> %r', e)
+
+ def handle_timer(self):
+ log.debug(u'IpHandler.handle_timer()')
+ self.refresh_devices()
+
+ def refresh_devices(self):
+ log.debug(u'IpHandler.update_devices()')
+ devices = get_network_devices()
+ #add not registered devices
+ for k,v in devices.items():
+ if k not in self.devices:
+ log.debug(u'IpHandler.update_devices: adding %r', v)
+ self.devices[k] = v
+ #delete dead devices
+ for k in self.devices.keys():
+ if k not in devices:
+ log.debug(u'IpHandler.update_devices: removing %s', k)
+ del self.devices[k]
+