summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2022-05-25 20:41:20 +0000
committerViacheslav Hletenko <v.gletenko@vyos.io>2022-05-26 00:02:33 +0000
commit45f460a20c0bdcd05d72eda3286b2b6980998fe4 (patch)
tree538f05d6745aaf18448510ada88836551fe3b5ab /src/services
parentec3a05d3dfda497910d42ad99d28d977312ea7a4 (diff)
downloadvyos-1x-45f460a20c0bdcd05d72eda3286b2b6980998fe4.tar.gz
vyos-1x-45f460a20c0bdcd05d72eda3286b2b6980998fe4.zip
http-api: T4442: Add action reset
Add action 'reset' (op-mode) for HTTP-API http://localhost/reset curl --unix-socket /run/api.sock -X POST -Fkey=mykey \ -Fdata='{"op": "reset", "path": ["ip", "bgp", "192.0.2.14"]}' \ http://localhost/reset
Diffstat (limited to 'src/services')
-rwxr-xr-xsrc/services/vyos-http-api-server37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index c1b595412..e9b904ba8 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -201,6 +201,20 @@ 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 +386,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 +621,27 @@ 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
###