diff options
author | Matthias Fetzer <fetzerms@users.noreply.github.com> | 2020-03-04 10:43:23 +0100 |
---|---|---|
committer | Administrator <admin@rofl.cat> | 2020-03-11 11:27:50 +0100 |
commit | 508d380b8ef4079d539a3845705f1bf3aeff3a67 (patch) | |
tree | 1305c4009005102a378646781b5bfd295768acca /src/services | |
parent | 09a2b2789c3914a6756bd3b487e51fa0737af8ca (diff) | |
download | vyos-1x-508d380b8ef4079d539a3845705f1bf3aeff3a67.tar.gz vyos-1x-508d380b8ef4079d539a3845705f1bf3aeff3a67.zip |
http api: T2096: Added show and generate
Diffstat (limited to 'src/services')
-rwxr-xr-x | src/services/vyos-http-api-server | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index da6e5b118..b5ad8b159 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -308,6 +308,49 @@ def config_file_op(): return success(res) +@app.route('/generate', method='POST') +@auth_required +def generate_op(): + session = app.config['vyos_session'] + + command = bottle.request.forms.get("data") + command = json.loads(command) + + try: + cmd = command['cmd'] + res = session.generate(cmd) + except KeyError: + return error(400, "Missing required field \"cmd\"") + except VyOSError as e: + return error(400, str(e)) + except Exception as e: + print(traceback.format_exc(), file=sys.stderr) + return error(500, "An internal error occured. Check the logs for details.") + + return success(res) + +@app.route('/show', method='POST') +@auth_required +def show_op(): + session = app.config['vyos_session'] + + command = bottle.request.forms.get("data") + command = json.loads(command) + + try: + cmd = command['cmd'] + res = session.show(cmd) + except KeyError: + return error(400, "Missing required field \"cmd\"") + except VyOSError as e: + return error(400, str(e)) + except Exception as e: + print(traceback.format_exc(), file=sys.stderr) + return error(500, "An internal error occured. Check the logs for details.") + + return success(res) + + if __name__ == '__main__': # systemd's user and group options don't work, do it by hand here, # else no one else will be able to commit |