本文整理汇总了Python中models.Node.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get_all方法的具体用法?Python Node.get_all怎么用?Python Node.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Node
的用法示例。
在下文中一共展示了Node.get_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: nodes_list
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_all [as 别名]
def nodes_list():
"""
Get nodes
List's all nodes activated on the hub
---
tags:
- nodes
responses:
200:
description: Returns a list of nodes
"""
log = hub.log
listener = hub.node_listeners
internal = request.args.get("internal", "false")
online = request.args.get("online", "false")
data = {"nodes": []}
nodes = data.get("nodes")
for node in Node.get_all():
if internal.lower() != "true" and node.printer_id != None:
continue
if online.lower() == "true" and not listener.is_alive(node.id):
continue
nodes.append(node.to_web())
return json.jsonify(data)
示例2: activate_node
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get_all [as 别名]
def activate_node(payload = None):
"""
Activate Node
Called by node to activate itself on the hub
---
tags:
- nodes
responses:
200:
description: Returns a list of sensors
"""
global nodes
id = int(request.args.get("id"))
ip = str(request.args.get("ip"))
port = int(request.args.get("port", 80))
log = hub.log
listener = hub.node_listeners
node = Node.get_by_id(id)
if node:
node.update(ip=ip)
if not listener.is_alive(id):
t = NodeCollector(id, hub.Webapi, hub.log)
t.start()
listener.add_thread(id, t)
log.log("Node " + str(id) + " is now online.")
return json.jsonify({'message': "Node " + str(id)
+ " is now online."}),201
if listener.is_alive(id):
log.log("Node " + str(id)
+ " is already online but tried"
+ " to activate again, Updated it's data")
return json.jsonify({'message': "Node " + str(id)
+ " was already online"}),201
else:
node = Node(id, ip)
t = NodeCollector(id, hub.Webapi, hub.log)
t.start()
listener.add_thread(id, t)
updates = {"nodes": []}
node_updates = updates.get("nodes")
for node in Node.get_all(fresh=True):
if node.printer_id == None:
node_updates.append(node.id)
t = threading.Thread(target=hub.Webapi.update_nodes,args=updates)
t.start()
return json.jsonify({"message": str(id) + " has been activated."}),201