added wlan config set/get to rest, added node terminal command for rest, added hook query to rest

This commit is contained in:
Blake J. Harnden 2018-08-27 14:57:36 -07:00
parent 359af03cfc
commit d2ebdb0468

View file

@ -21,6 +21,7 @@ from core.enumerations import LinkTypes
from core.enumerations import NodeTypes
from core.misc import nodeutils
from core.misc.ipaddress import Ipv4Prefix, Ipv6Prefix
from core.mobility import BasicRangeModel
from core.service import ServiceManager
CORE_LOCK = Lock()
@ -108,6 +109,17 @@ def convert_link(session, link_data):
}
def broadcast_event(event):
socketio.emit("event", {
"node": event.node,
"event_type": event.event_type,
"name": event.name,
"data": event.data,
"time": event.time,
"session": event.session
})
@socketio.on("connect")
def websocket_connect():
emit("info", {"message": "You are connected!"})
@ -219,6 +231,9 @@ def create_session():
session.location.setrefgeo(47.57917, -122.13232, 2.0)
session.location.refscale = 150.0
# add handlers
session.event_handlers.append(broadcast_event)
response_data = jsonify(
id=session.session_id,
state=session.state,
@ -292,6 +307,51 @@ def add_hook(session_id):
return jsonify()
@app.route("/sessions/<int:session_id>/hooks")
def get_hooks(session_id):
session = coreemu.sessions.get(session_id)
if not session:
return jsonify(error="session does not exist"), 404
hooks = []
for state, state_hooks in session._hooks.iteritems():
for file_name, file_data in state_hooks:
hooks.append({
"state": state,
"file": file_name,
"data": file_data
})
return jsonify(hooks=hooks)
@app.route("/sessions/<int:session_id>/nodes/<node_id>/wlan")
def get_wlan_config(session_id, node_id):
session = coreemu.sessions.get(session_id)
if not session:
return jsonify(error="session does not exist"), 404
if node_id.isdigit():
node_id = int(node_id)
config = session.mobility.get_model_config(node_id, BasicRangeModel.name)
return jsonify(config)
@app.route("/sessions/<int:session_id>/nodes/<node_id>/wlan", methods=["PUT"])
def set_wlan_config(session_id, node_id):
session = coreemu.sessions.get(session_id)
if not session:
return jsonify(error="session does not exist"), 404
if node_id.isdigit():
node_id = int(node_id)
config = request.get_json() or {}
session.mobility.set_model_config(node_id, BasicRangeModel.name, config)
return jsonify()
@app.route("/sessions/<int:session_id>/emane/config", methods=["PUT"])
@synchronized
def set_emane_config(session_id):
@ -533,9 +593,9 @@ def node_terminal(session_id, node_id):
if not node:
return jsonify(error="node does not exist"), 404
node.client.term("bash")
terminal_command = node.termcmdstring("/bin/bash")
return jsonify()
return jsonify(terminal_command)
@app.route("/sessions/<int:session_id>/nodes/<node_id>", methods=["DELETE"])