def upgrade(self, req, agent_id, body=None): """call by client, and asyncrequest do not need Idsformater, check it in send_asyncrequest send rpm file to upgrade code of agent """ body = body or {} asyncrequest = self.create_asyncrequest(body) target = targetutils.target_all(fanout=True) async_ctxt = dict(pre_run=body.pop('pre_run', None), after_run=body.pop('after_run', None), post_run=body.pop('post_run', None)) rpc_method = 'upgrade_agent' rpc_ctxt = {} agents = self.agents_id_check(agent_id) if agent_id != 'all': rpc_ctxt.setdefault('agents', agents) global_data = get_global() glock = global_data.lock('agents') def wapper(): with glock(agents): self.send_asyncrequest(asyncrequest, target, rpc_ctxt, rpc_method, None, async_ctxt) threadpool.add_thread(safe_func_wrapper, wapper, LOG) return resultutils.results(result='Upgrade agent async request thread spawning', data=[asyncrequest.to_dict()])
def _expire(): try: BaseContorller._agent_metadata_expire(agent_id, expire + fix) except AgentMetadataMiss: # 元数据丢失, 通知agent重新上报 rpc = get_client() # send to rpc server rpc.cast(targetutils.target_all(fanout=True), ctxt={'agents': [agent_id, ]}, msg={'method': 'flush_metadata', 'args': {'expire': expire}})
def status(self, req, agent_id, body=None): """get status from agent, not from database do not need Idsformater, check it in send_asyncrequest """ body = body or {} body.setdefault('expire', 180) asyncrequest = self.create_asyncrequest(body) target = targetutils.target_all(fanout=True) rpc_ctxt = {} if agent_id != 'all': rpc_ctxt.setdefault('agents', self.agents_id_check(agent_id)) rpc_method = 'status_agent' rpc_args = body def wapper(): self.send_asyncrequest(asyncrequest, target, rpc_ctxt, rpc_method, rpc_args) threadpool.add_thread(safe_func_wrapper, wapper, LOG) return resultutils.results(result='Status agent async request thread spawning', data=[asyncrequest.to_dict()])
def send(self, req, agent_id, md5, body=None): """call by client, and asyncrequest send file to agents """ body = body or {} asyncrequest = self.create_asyncrequest(body) target = targetutils.target_all(fanout=True) async_ctxt = dict(pre_run=body.pop('pre_run', None), after_run=body.pop('after_run', None), post_run=body.pop('post_run', None)) rpc_method = 'getfile' rpc_args = {'md5': md5, 'timeout': asyncrequest.deadline - 1} rpc_ctxt = {} if agent_id != 'all': rpc_ctxt.setdefault('agents', self.agents_id_check(agent_id)) def wapper(): self.send_asyncrequest(asyncrequest, target, rpc_ctxt, rpc_method, rpc_args, async_ctxt) threadpool.add_thread(safe_func_wrapper, wapper, LOG) return resultutils.results(result='Send file to agents thread spawning', data=[asyncrequest.to_dict()])