def Ping(self, n, retries, force, reason): if IsMultichannelNode(n): XMIT_OPTIONS = (z.TRANSMIT_OPTION_ACK | z.TRANSMIT_OPTION_AUTO_ROUTE | z.TRANSMIT_OPTION_EXPLORE) n, endpoint = SplitMultiChannelNode(n) logging.info("ping %d.%d", n, endpoint) self.SendCommand(n, z.MultiChannel_CapabilityGet, {"endpoint": endpoint}, zmessage.ControllerPriority(), XMIT_OPTIONS) return logging.info("[%s] Ping (%s) retries %d, force: %s", _NodeName(n), reason, retries, force) self.GetNodeProtocolInfo(n) if force: self._UpdateIsFailedNode(n, None) self._RequestNodeInfo(n, retries) else: def handler(failed): if not failed: self._RequestNodeInfo(n, retries) self._UpdateIsFailedNode(n, handler)
def cmd_get_basic(args): driver, controller = InitController(args, True) translator = command_translator.CommandTranslator(driver) translator.AddListener(NodeUpdateListener()) for n in args.node: translator.SendCommand(n, z.Basic_Get, {}, zmessage.ControllerPriority(), XMIT_OPTIONS) time.sleep(2) driver.Terminate()
def cmd_set_basic_multi(args): driver, controller = InitController(args, True) translator = command_translator.CommandTranslator(driver) logging.info("sending command to %s", args.node) translator.SendMultiCommand(args.node, z.Basic_Set, {"level": args.level}, zmessage.ControllerPriority(), XMIT_OPTIONS ) driver.Terminate()
def GetNodeProtocolInfo(self, n): def handler(message): if not message: logging.error("ProtocolInfo failed") return payload = message[4:-1] if len(payload) < 5: logging.error("bad ProtocolInfo payload: %s", message) return self._ProcessProtocolInfo(n, payload) logging.warning("[%d] GetNodeProtocolInfo", n) m = zmessage.MakeRawMessage(z.API_ZW_GET_NODE_PROTOCOL_INFO, [n]) self._SendMessage(n, m, zmessage.ControllerPriority(), handler)
def _UpdateIsFailedNode(self, n, cb): def handler(mesg): if mesg is None: return logging.info("[%s] is failed check: %d, %s", _NodeName(n), mesg[4], zmessage.PrettifyRawMessage(mesg)) failed = mesg[4] != 0 self._PushToListeners(n, time.time(), command.CUSTOM_COMMAND_FAILED_NODE, {"failed": failed}) if cb: cb(failed) m = zmessage.MakeRawMessage(z.API_ZW_IS_FAILED_NODE_ID, [n]) self._SendMessage(n, m, zmessage.ControllerPriority(), handler)
def _RequestNodeInfo(self, n, retries): """This usually triggers send "API_ZW_APPLICATION_UPDATE:""" def handler(_): # if we timeout m will be None if m is not None and m[4] != 0: return # success logging.warning("[%d] RequestNodeInfo failed: %s", n, zmessage.PrettifyRawMessage(m)) self._RequestNodeInfo(n, retries - 1) if retries > 0: logging.warning("[%d] RequestNodeInfo try:%d", n, retries) m = zmessage.MakeRawMessage(z.API_ZW_REQUEST_NODE_INFO, [n]) self._SendMessage(n, m, zmessage.ControllerPriority(), handler) else: logging.error("[%d] RequestNodeInfo failed permanently", n)
def Priority(cls): return zmessage.ControllerPriority()