From 04c2a30fbdea2d6fe345f86bd12e536ebbf5deca Mon Sep 17 00:00:00 2001 From: bharnden Date: Sat, 24 Nov 2018 07:01:23 -0800 Subject: [PATCH] core rest - added start/stop/restart/validate services endpoints --- webapp/service_routes.py | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/webapp/service_routes.py b/webapp/service_routes.py index d9a0f014..6a725a13 100644 --- a/webapp/service_routes.py +++ b/webapp/service_routes.py @@ -99,3 +99,69 @@ def set_node_service_file(session_id, node_id, service): data = data["data"] session.services.set_service_file(node_id, service, file_name, data) return jsonify() + + +@api.route("/sessions//nodes//services//start", methods=["PUT"]) +def start_node_service(session_id, node_id, service_name): + session = core_utils.get_session(coreemu, session_id) + node = core_utils.get_node(session, node_id) + status = -1 + for service in node.services: + if service.name == service_name: + status = session.services.startup_service(node, service, wait=True) + break + + if status: + return jsonify(), 400 + else: + return jsonify() + + +@api.route("/sessions//nodes//services//stop", methods=["PUT"]) +def stop_node_service(session_id, node_id, service_name): + session = core_utils.get_session(coreemu, session_id) + node = core_utils.get_node(session, node_id) + status = -1 + for service in node.services: + if service.name == service_name: + status = session.services.stop_service(node, service) + break + + if status: + return jsonify(), 400 + else: + return jsonify() + + +@api.route("/sessions//nodes//services//restart", methods=["PUT"]) +def restart_node_service(session_id, node_id, service_name): + session = core_utils.get_session(coreemu, session_id) + node = core_utils.get_node(session, node_id) + status = -1 + for service in node.services: + if service.name == service_name: + status = session.services.stop_service(node, service) + if not status: + status = session.services.startup_service(node, service, wait=True) + break + + if status: + return jsonify(), 400 + else: + return jsonify() + + +@api.route("/sessions//nodes//services//validate", methods=["PUT"]) +def validate_node_service(session_id, node_id, service_name): + session = core_utils.get_session(coreemu, session_id) + node = core_utils.get_node(session, node_id) + status = -1 + for service in node.services: + if service.name == service_name: + status = session.services.validate_service(node, service) + break + + if status: + return jsonify(), 400 + else: + return jsonify()