updated set mobility to upload file to a upload directory and mark files used by set mobility config to look for the file within this directory
This commit is contained in:
parent
2815554487
commit
3dc9586817
8 changed files with 63 additions and 30 deletions
|
@ -1,8 +1,11 @@
|
|||
import os
|
||||
|
||||
from bottle import HTTPError
|
||||
from flask import Flask
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
|
||||
import core_utils
|
||||
import emane_routes
|
||||
import hook_routes
|
||||
import link_routes
|
||||
|
@ -65,6 +68,16 @@ def get_ips():
|
|||
)
|
||||
|
||||
|
||||
@app.route("/upload", methods=["POST"])
|
||||
def upload():
|
||||
if not os.path.exists(core_utils.save_dir):
|
||||
os.mkdir(core_utils.save_dir, 755)
|
||||
upload_file = request.files["file"]
|
||||
save_path = os.path.join(core_utils.save_dir, upload_file.filename)
|
||||
upload_file.save(save_path)
|
||||
return jsonify()
|
||||
|
||||
|
||||
@app.errorhandler(HTTPError)
|
||||
def handle_error(e):
|
||||
return jsonify(message=e.body, status=e.status_code), e.status_code
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import os
|
||||
from functools import wraps
|
||||
from threading import Lock
|
||||
|
||||
from bottle import abort
|
||||
|
||||
save_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "uploads")
|
||||
CORE_LOCK = Lock()
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import os
|
||||
|
||||
from flask import Blueprint
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
|
||||
import core_utils
|
||||
from core.mobility import Ns2ScriptedMobility
|
||||
|
||||
api = Blueprint("mobility_api", __name__)
|
||||
|
@ -11,45 +14,26 @@ coreemu = None
|
|||
|
||||
@api.route("/sessions/<int:session_id>/nodes/<node_id>/mobility", methods=["POST"])
|
||||
def set_mobility_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)
|
||||
|
||||
session = core_utils.get_session(coreemu, session_id)
|
||||
node_id = core_utils.get_node_id(node_id)
|
||||
data = request.get_json() or {}
|
||||
|
||||
data["file"] = os.path.join(core_utils.save_dir, data["file"])
|
||||
session.mobility.set_model_config(node_id, Ns2ScriptedMobility.name, data)
|
||||
|
||||
return jsonify()
|
||||
|
||||
|
||||
@api.route("/sessions/<int:session_id>/nodes/<node_id>/mobility")
|
||||
def get_mobility_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)
|
||||
|
||||
session = core_utils.get_session(coreemu, session_id)
|
||||
node_id = core_utils.get_node_id(node_id)
|
||||
config = session.mobility.get_model_config(node_id, Ns2ScriptedMobility.name)
|
||||
|
||||
return jsonify(config)
|
||||
|
||||
|
||||
@api.route("/sessions/<int:session_id>/nodes/<node_id>/mobility/<action>", methods=["PUT"])
|
||||
def mobility_action(session_id, node_id, action):
|
||||
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)
|
||||
node = session.objects.get(node_id)
|
||||
if not node:
|
||||
return jsonify(error="node does not exist"), 404
|
||||
session = core_utils.get_session(coreemu, session_id)
|
||||
node = core_utils.get_node(session, node_id)
|
||||
|
||||
if action == "start":
|
||||
node.mobility.start()
|
||||
|
|
|
@ -35,7 +35,7 @@ def open_xml():
|
|||
|
||||
logger.info("open xml: %s", request.files)
|
||||
_, temp_path = tempfile.mkstemp()
|
||||
session_file = request.files['session']
|
||||
session_file = request.files["file"]
|
||||
session_file.save(temp_path)
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue