当前位置: 首页>>代码示例>>Python>>正文


Python Agent.find方法代码示例

本文整理汇总了Python中agent.Agent.find方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.find方法的具体用法?Python Agent.find怎么用?Python Agent.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在agent.Agent的用法示例。


在下文中一共展示了Agent.find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Controller

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import find [as 别名]
class Controller(Parent):

    def models(self):
        self.agents = Agent(self.config)
        self.sender = RPCSender(self.config)

    # BELOW THIS LINE ARE ALL CONTROLLER ACTIONS

    def setFiles(self, body, resp):
        response = []
        data = body['data']
        # Create body for sending to agent
        sbody = {"files": data['files']}
        for agent in data['agents']:
            ag = self.agents.find(agent)
            if ag is not None:
                self.logger.info("Sending %s to %s" % (sbody, agent))
                r = {agent: self.sender.send_request(
                    'SETFILES',
                    agent,
                    sbody,
                    '000000000000',
                    'agentmanager',
                    key=ag.QUEUE)}
                self.logger.info("Sent!")
            else:
                r = {agent: 'Agent Doesnt Exist!'}
            response.append(r)
        resp.respond(response)
开发者ID:bradleyjones,项目名称:apiary,代码行数:31,代码来源:configcontroller.py

示例2: Controller

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import find [as 别名]
class Controller(Parent):

    def models(self):
        self.agents = Agent(self.config)

    def send_agent_event(self, agent, key):
        event = {"agents": {}}
        event['agents'][agent.UUID] = agent.to_hash()
        self.event(event, 'agent.%s' % key)

    # BELOW THIS LINE ARE ALL CONTROLLER ACTIONS

    def handshake(self, data, resp):
        id = str(uuid.uuid4())
        agent = self.agents.new()
        agent.UUID = id
        agent.HEARTBEAT = time.time()
        agent.DEAD = False
        agent.AUTHENTICATED = False
        agent.QUEUE = data['reply_to']
        agent.MACHINEID = data['machineid']
        agent.BOUND = False
        agent.METADATA = {}
        agent = self.agents.save(agent)
        self.send_agent_event(agent, "new")
        resp.respond(id)

    def update(self, body, resp):
        agent = self.agents.find(body['data']['UUID'])
        for column in self.agents.columns:
            if column in body['data']:
                setattr(agent, column, body['data'][column])
        self.agents.save(agent)
        self.send_agent_event(agent, "update")
        resp.respond(agent.to_hash())

    def goodbye(self, data, resp):
        agent = self.agents.find(data["from"])
        self.agents.delete(agent)
        resp.respond("GOODBYE!")

    def get_agents(self, data, resp):
        agents = self.agents.findAll()
        response = {}
        for agent in agents:
            response[agent.UUID] = agent.to_hash()
        resp.respond(response)

    def get_agents_count(self, data, resp):
        agents = self.agents.findAll()
        count = len(agents)
        resp.respond(count)

    def get_single_agent(self, data, resp):
        agent = self.agents.find(data["data"]["id"])
        response = None
        if agent is not None:
            response = {}
            response[agent.UUID] = agent.to_hash()
        resp.respond(response)

    def heartbeat(self, data, resp):
        self.logger.debug("Received HeartBeat from: %s", data["from"])
        agent = self.agents.find(data["from"])
        agent.HEARTBEAT = time.time()
        agent.DEAD = False
        self.agents.save(agent)
开发者ID:bradleyjones,项目名称:apiary,代码行数:69,代码来源:agentscontroller.py


注:本文中的agent.Agent.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。