def _run_obj(self,path,content): '''''' app=path[0] log("path:%s"%str(path)) log(get_projname()) if app == get_projname(): pass else: ret_data = ReturnData() ret_data.set_header(code=1000, msg="[Process]Get obj path info error") log(ret_data.get_data()) return ret_data.get_data() if isinstance(path,list): try: classname=RPC_DICT[path[1]] class_obj=classname() method = path[2] obj = getattr(class_obj,method) #log(obj) return obj(content) except Exception,e: print str(e) ret_data = ReturnData() ret_data.set_header(code=1000, msg="[Process]Get obj info error") log(ret_data.get_data()) return ret_data.get_data()
class ProcessServerTask(): def __init__(self): self._ret_data =ReturnData() def run(self,data): # #log(str(data)) self.main_process(data) self._ret_data.set_header(0,"OK",) return self._ret_data def main_process(self,data): #step-1: log("[main_process]callback...") log(str(data)) # return def update_local_task_status_result(self): """function:update task status""" try: pass except Exception,e: pass return
class API(object): def __init__(self): self._ret_data = ReturnData() #@staticmethod def run(self,content): try: #log(type(content)) #for i in range(random.randint(0,100)): # log(i) # self._ret_data.add_result(str("key_"+str(i)), i) #TODO:process command execute ret_obj = AgentAPI().run(content) return ret_obj.get_data() except Exception,e: #print str(e) log(str(e)) print_exc_info() self._ret_data.add_result("msg","error") return self._ret_data.get_data()
def __init__(self): self._ret_data = ReturnData()
class ProcessAgentTask(): def __init__(self): self._ret_data =ReturnData() def run(self,data): log(str(data)) return self.main_process(data) #return def inner_process_ret(self,data): """""" (result,header_info,body_info)=self.check_params(data) if isinstance(body_info["data"]["detail"],list): detail = body_info["data"]["detail"][0] elif isinstance(body_info["data"]["detail"],dict): detail = body_info["data"]["detail"] else: log("request content:param[detail] type need be list or dict") return "request content format error" (script_name,store_path)=self.convert_str_2_file(detail) result=exec_cmd("chmod +x "+store_path+script_name) log("\n".join(result)) result = exec_cmd(store_path+script_name) str_result = "\n".join(result) log(str_result) return str_result def main_process(self,data): #step-1: (result,header_info,body_info)=self.check_params(data) if not result: self._ret_data.set_header(1, "params check error,please input correct formate") return self._ret_data w_dir = conf.get("TASK","agent.task.dir","/var/agent/task") try: result = True result =self._make_task_dir(w_dir) if not result: result = False msg = u"[ProcessTaskAPI]Create local store dir/va/agent/task failure" else: r_taskid = gen_taskid() w_content = json.dumps(data) with open(w_dir+"/"+r_taskid+".ready","w") as f: f.write(w_content) msg = "ok" except Exception,e: log(str(e)) result = False msg = str(e) #compose result if not result: self._ret_data.set_header(1,msg) else: self._ret_data.set_header(0, msg) self._ret_data.add_result("taskid",r_taskid) return self._ret_data
try: classname=RPC_DICT[path[1]] class_obj=classname() method = path[2] obj = getattr(class_obj,method) #log(obj) return obj(content) except Exception,e: print str(e) ret_data = ReturnData() ret_data.set_header(code=1000, msg="[Process]Get obj info error") log(ret_data.get_data()) return ret_data.get_data() else: ret_data = ReturnData() ret_data.set_header(code=1000, msg="[Process]Path info error") return ret_data.get_data() class ThreadingHttpServer(ThreadingMixIn,HTTPServer): pass ########################################################## class ThreadingUDPServer(ThreadingMixIn,UDPServer): pass class UDPRequestHandler(BaseRequestHandler): """process udp report info""" def handle(self): """""" try: