added wlan config set/get to rest, added node terminal command for rest, added hook query to rest
This commit is contained in:
parent
359af03cfc
commit
d2ebdb0468
1 changed files with 62 additions and 2 deletions
|
@ -21,6 +21,7 @@ from core.enumerations import LinkTypes
|
||||||
from core.enumerations import NodeTypes
|
from core.enumerations import NodeTypes
|
||||||
from core.misc import nodeutils
|
from core.misc import nodeutils
|
||||||
from core.misc.ipaddress import Ipv4Prefix, Ipv6Prefix
|
from core.misc.ipaddress import Ipv4Prefix, Ipv6Prefix
|
||||||
|
from core.mobility import BasicRangeModel
|
||||||
from core.service import ServiceManager
|
from core.service import ServiceManager
|
||||||
|
|
||||||
CORE_LOCK = Lock()
|
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")
|
@socketio.on("connect")
|
||||||
def websocket_connect():
|
def websocket_connect():
|
||||||
emit("info", {"message": "You are connected!"})
|
emit("info", {"message": "You are connected!"})
|
||||||
|
@ -219,6 +231,9 @@ def create_session():
|
||||||
session.location.setrefgeo(47.57917, -122.13232, 2.0)
|
session.location.setrefgeo(47.57917, -122.13232, 2.0)
|
||||||
session.location.refscale = 150.0
|
session.location.refscale = 150.0
|
||||||
|
|
||||||
|
# add handlers
|
||||||
|
session.event_handlers.append(broadcast_event)
|
||||||
|
|
||||||
response_data = jsonify(
|
response_data = jsonify(
|
||||||
id=session.session_id,
|
id=session.session_id,
|
||||||
state=session.state,
|
state=session.state,
|
||||||
|
@ -292,6 +307,51 @@ def add_hook(session_id):
|
||||||
return jsonify()
|
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"])
|
@app.route("/sessions/<int:session_id>/emane/config", methods=["PUT"])
|
||||||
@synchronized
|
@synchronized
|
||||||
def set_emane_config(session_id):
|
def set_emane_config(session_id):
|
||||||
|
@ -533,9 +593,9 @@ def node_terminal(session_id, node_id):
|
||||||
if not node:
|
if not node:
|
||||||
return jsonify(error="node does not exist"), 404
|
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"])
|
@app.route("/sessions/<int:session_id>/nodes/<node_id>", methods=["DELETE"])
|
||||||
|
|
Loading…
Reference in a new issue