def doTaskMain(tinfo): ''' @tinfo 批量操作指令类型 @执行计划任务 ''' cmdstr, ip = ayCmdToConsole(tinfo) try: type = 'task' chooseBatchDef(cmdstr,tinfo,type) except Exception as e: save_log('ERROR','TASK batch chooseBatchDef error:'+str(e))
def socketDo(connection, addr): ''' server指令处理模块 @connection: 指令连接对象 ''' try: rev = socketRev(connection, addr) if isConseResult(rev): connection.send(encode('result_send_ok')) #处理从unctrlpy 传过来的结果信息 try: chooseResultDef(rev) except Exception as e: save_log('ERROR', 'chooseResultDef error:' + str(e)) cmdstr, ip = ayCmdToConsole(rev) if not ip: save_log('ERROR', 'IP IS NULL') connection.send('Ip is null.') connection.close() sys.exit() save_log('INFO', str(cmdstr.split('!'))) # if cmd for myself cname = isMySelfCmd(cmdstr) #if batch cmd batch = isBatchCmd(cmdstr) toPhpData = "" if cname: try: toPhpData = OsaChooseDef(defname=isMySelfCmd(cmdstr), ip=ip, fromPhpCmd=cmdstr) except Exception as e: save_log('ERROR', e) elif batch: toPhpData = 'BATCH_CMD_OK' else: toPhpData = hostSocket.proSocket(ip, SOCKET['REMOTE_PORT'], cmdstr) save_log('DEBUG', 'cmd info:' + str(encode(cmdstr))) save_log('DEBUG', 'cmd info:' + str(cmdstr)) if toPhpData == False: toPhpData = 'Data_receive_Failed!' connection.send('%s!%s' % (toPhpData, ip)) connection.close() if toPhpData == 'BATCH_CMD_OK': try: chooseBatchDef(cmdstr, rev) except Exception as e: save_log('ERROR', 'BATCH chooseBatchDef error:' + str(e)) sys.exit() except queueEmptyException, value: save_log('ERROR', 'server socketDo:' + str(value)) connection.close() sys.exit()
def socketDo(connection, addr): """ server指令处理模块 @connection: 指令连接对象 """ try: rev = socketRev(connection, addr) if isConseResult(rev): connection.send(encode("result_send_ok")) # 处理从unctrlpy 传过来的结果信息 try: chooseResultDef(rev) except Exception as e: save_log("ERROR", "chooseResultDef error:" + str(e)) cmdstr, ip = ayCmdToConsole(rev) if not ip: save_log("ERROR", "IP IS NULL") connection.send("Ip is null.") connection.close() sys.exit() save_log("INFO", str(cmdstr.split("!"))) # if cmd for myself cname = isMySelfCmd(cmdstr) # if batch cmd batch = isBatchCmd(cmdstr) toPhpData = "" if cname: try: toPhpData = OsaChooseDef(defname=isMySelfCmd(cmdstr), ip=ip, fromPhpCmd=cmdstr) except Exception as e: save_log("ERROR", e) elif batch: toPhpData = "BATCH_CMD_OK" else: toPhpData = hostSocket.proSocket(ip, SOCKET["REMOTE_PORT"], cmdstr) save_log("DEBUG", "cmd info:" + str(encode(cmdstr))) save_log("DEBUG", "cmd info:" + str(cmdstr)) if toPhpData == False: toPhpData = "Data_receive_Failed!" connection.send("%s!%s" % (toPhpData, ip)) connection.close() if toPhpData == "BATCH_CMD_OK": try: chooseBatchDef(cmdstr, rev) except Exception as e: save_log("ERROR", "BATCH chooseBatchDef error:" + str(e)) sys.exit() except queueEmptyException, value: save_log("ERROR", "server socketDo:" + str(value)) connection.close() sys.exit()