core rest - added node command api, changed default rest address to the local machine to avoid external connections
This commit is contained in:
parent
56f9e6ec8a
commit
9b56b489fa
2 changed files with 16 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
|
@ -84,4 +85,7 @@ def handle_error(e):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
websocket_routes.socketio.run(app, host="0.0.0.0", debug=True)
|
host = "127.0.0.1"
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
host = sys.argv[1]
|
||||||
|
websocket_routes.socketio.run(app, host=host, debug=True)
|
||||||
|
|
|
@ -149,3 +149,14 @@ def get_node_links(session_id, node_id):
|
||||||
links.append(link)
|
links.append(link)
|
||||||
|
|
||||||
return jsonify(links=links)
|
return jsonify(links=links)
|
||||||
|
|
||||||
|
|
||||||
|
@api.route("/sessions/<int:session_id>/nodes/<node_id>/command", methods=["PUT"])
|
||||||
|
def node_command(session_id, node_id):
|
||||||
|
command = request.get_json() or {}
|
||||||
|
session = core_utils.get_session(coreemu, session_id)
|
||||||
|
node = core_utils.get_node(session, node_id)
|
||||||
|
logger.info("command: %s", command)
|
||||||
|
_, output = node.cmd_output(command)
|
||||||
|
logger.info("output: %s", output)
|
||||||
|
return jsonify(output)
|
||||||
|
|
Loading…
Add table
Reference in a new issue