def run_cmd_host(host_id):
"""Execute host specific command."""
#Select host on the server.
res = RSPET_API.select([host_id])
#Check if host selected correctly (if not probably host_id is invalid).
if res["code"] != rspet_server.ReturnCodes.OK:
abort(404)
#Read 'command' argument from query string.
comm = request.args.get('command')
if not comm or comm in EXCLUDED_FUNCTIONS:
abort(400)
try:
#Read 'args' argument from query string.
args = request.args.getlist('args')
#Cast arguments to string.
for i, val in enumerate(args):
args[i] = str(val)
except KeyError:
args = []
#Execute command.
res = RSPET_API.call_plugin(comm, args)
#Unselect host. Maintain statelessness of RESTful.
RSPET_API.select()
return jsonify(res)
评论列表
文章目录