diff options
author | Nataliia Solomko <natalirs1985@gmail.com> | 2024-10-11 13:24:43 +0300 |
---|---|---|
committer | Nataliia Solomko <natalirs1985@gmail.com> | 2024-10-11 13:37:45 +0300 |
commit | 60cd669d2cee2a17d4e6ab6fce9101069d311e23 (patch) | |
tree | eecb5f26c5367d4b88276a035a1d0f01140ba64e /src/services/api/rest/routers.py | |
parent | 7d4264365e487d37115cff0633b25e4b2012a126 (diff) | |
download | vyos-1x-60cd669d2cee2a17d4e6ab6fce9101069d311e23.tar.gz vyos-1x-60cd669d2cee2a17d4e6ab6fce9101069d311e23.zip |
T6695: Machine-readable operational mode support for traceroute
Diffstat (limited to 'src/services/api/rest/routers.py')
-rw-r--r-- | src/services/api/rest/routers.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/services/api/rest/routers.py b/src/services/api/rest/routers.py index da981d5bf..47d06b7e9 100644 --- a/src/services/api/rest/routers.py +++ b/src/services/api/rest/routers.py @@ -68,6 +68,7 @@ from .models import RebootModel from .models import ResetModel from .models import ImportPkiModel from .models import PoweroffModel +from .models import TracerouteModel if TYPE_CHECKING: @@ -209,6 +210,7 @@ class MultipartRequest(Request): '/container-image', '/image', '/configure-section', + '/traceroute', ): if 'path' not in c: self.form_err = ( @@ -742,6 +744,28 @@ def poweroff_op(data: PoweroffModel): return success(res) +@router.post('/traceroute') +def traceroute_op(data: TracerouteModel): + state = SessionState() + session = state.session + + op = data.op + host = data.host + + try: + if op == 'traceroute': + res = session.traceroute(host) + else: + return error(400, f"'{op}' is not a valid operation") + except ConfigSessionError as e: + return error(400, str(e)) + except Exception: + LOG.critical(traceback.format_exc()) + return error(500, 'An internal error occurred. Check the logs for details.') + + return success(res) + + def rest_init(app: 'FastAPI'): if all(r in app.routes for r in router.routes): return |