def _backoff(self, msg): wait_time = RETRY_BACKOFF[min(self.retries, len(RETRY_BACKOFF) - 1)] self.retry_time += wait_time self.retries += 1 log.error(msg, next_retry_in_secs=wait_time, total_delay_in_secs=self.retry_time, retries=self.retries) return asleep(wait_time)
def reboot(self): self.log.info('rebooting', device_id=self.device_id) # Update the connect status to UNREACHABLE yield self.core_proxy.device_state_update( self.device_id, connect_status=ConnectStatus.UNREACHABLE) # Sleep 10 secs, simulating a reboot # TODO: send alert and clear alert after the reboot yield asleep(10) # Change the connection status back to REACHABLE. With a # real ONU the connection state must be the actual state yield self.core_proxy.device_state_update( self.device_id, connect_status=ConnectStatus.REACHABLE) self.log.info('rebooted', device_id=self.device_id)
def _register_with_core(self, retries): while 1: try: resp = yield self.core_proxy.register( self.adapter.adapter_descriptor(), self.adapter.device_types()) if resp: self.log.info('registered-with-core', coreId=resp.instance_id) returnValue(resp) except TimeOutError as e: self.log.warn("timeout-when-registering-with-core", e=e) if retries == 0: self.log.exception("no-more-retries", e=e) raise else: retries = retries if retries < 0 else retries - 1 yield asleep(defs['retry_interval']) except Exception as e: self.log.exception("failed-registration", e=e) raise