本文整理汇总了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)
示例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)