diff options
author | Daniil Baturin <daniil@vyos.io> | 2022-05-26 17:35:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-26 17:35:57 +0300 |
commit | f2bc9448f8fbb65382128853d79f46e25e1f7909 (patch) | |
tree | a3493dad283451d7cc3f5067e02278268ebd49ec /src | |
parent | 9854c72dfc8c88c9b1c0b21637091216aed94baa (diff) | |
parent | d15af8e9fdc32bd2e3471a300d9cf32e8eff00a0 (diff) | |
download | vyos-1x-f2bc9448f8fbb65382128853d79f46e25e1f7909.tar.gz vyos-1x-f2bc9448f8fbb65382128853d79f46e25e1f7909.zip |
Merge pull request #1335 from sever-sever/T4442-equ
http-api: T4442: Add action reset
Diffstat (limited to 'src')
-rwxr-xr-x | src/services/vyos-http-api-server | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index 1000d8b72..ed8cf6a44 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -1,6 +1,6 @@ #!/usr/share/vyos-http-api-tools/bin/python3 # -# Copyright (C) 2019-2021 VyOS maintainers and contributors +# Copyright (C) 2019-2022 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -201,6 +201,19 @@ class ShowModel(ApiModel): } } +class ResetModel(ApiModel): + op: StrictStr + path: List[StrictStr] + + class Config: + schema_extra = { + "example": { + "key": "id_key", + "op": "reset", + "path": ["op", "mode", "path"], + } + } + class Success(BaseModel): success: bool data: Union[str, bool, Dict] @@ -372,7 +385,7 @@ class MultipartRoute(APIRoute): return error(400, "Malformed command \"{0}\": \"value\" field must be a string".format(json.dumps(request.offending_command))) if request.ERR_PATH_NOT_LIST_OF_STR: return error(400, "Malformed command \"{0}\": \"path\" field must be a list of strings".format(json.dumps(request.offending_command))) - if endpoint in ('/retrieve','/generate','/show'): + if endpoint in ('/retrieve','/generate','/show','reset'): if request.ERR_NO_OP or request.ERR_NO_PATH: return error(400, "Missing required field. \"op\" and \"path\" fields are required") if endpoint in ('/config-file', '/image'): @@ -607,6 +620,26 @@ def show_op(data: ShowModel): return success(res) +@app.post('/reset') +def reset_op(data: ResetModel): + session = app.state.vyos_session + + op = data.op + path = data.path + + try: + if op == 'reset': + res = session.reset(path) + else: + return error(400, "\"{0}\" is not a valid operation".format(op)) + except ConfigSessionError as e: + return error(400, str(e)) + except Exception as e: + logger.critical(traceback.format_exc()) + return error(500, "An internal error occured. Check the logs for details.") + + return success(res) + ### # GraphQL integration ### |