def delete(peer_id): """ Delete peer """ peer = PeerController.get(peer_id) if not peer: return jsonify(error='Peer not found'), 500 PeerController.delete(peer) return jsonify()
def get(peer_id): """ Get peer """ peer = PeerController.get(peer_id) if not peer: return jsonify(error='Peer not found'), 500 return jsonify(peer=serialize_sqla(peer))
def create(): """ Create new peer """ if request.json['secret'] != app.config['CLIENT_HANDSHAKE']: return jsonify(), 401 peer = PeerController.create(request.remote_addr) return jsonify(id=peer.id)
def get_all(): """ Get all peers unfiltered """ peers = PeerController.get_all() if not peers: return jsonify(error='No peers were found'), 500 ser_peers = [] for peer in peers: ser_peer = row2dict(peer) ser_peer['job'] = None if (peer.task): ser_peer['job'] = row2dict(peer.task.job) ser_peers.append(ser_peer) return jsonify(peers=ser_peers)
def get_all(): """ Get all peers unfiltered """ peers = PeerController.get_all() if not peers: return jsonify(error='No peers were found'), 500 ser_peers = [] for peer in peers: ser_peer = row2dict(peer) ser_peer['job'] = None if(peer.task): ser_peer['job'] = row2dict(peer.task.job) ser_peers.append(ser_peer) return jsonify(peers=ser_peers)
def ping(peer_id): """ Get ping from peer""" load = int(request.json['load']) if load > 0 and load <= 100 and peer_id: PeerController.ping(peer_id, load) return jsonify()
def status(): return render_template('status.htm', data={'peers': PeerController.get_all()})