diff options
author | Daniil Baturin <daniil@vyos.io> | 2024-11-07 17:46:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-07 17:46:27 +0000 |
commit | 3eb66e36b81c835f802900c4bc2e973e2657fa31 (patch) | |
tree | 39e8061bcd16155b80b6ab1747b27aa68b43f9ad /src/services | |
parent | c97980d18610d8d48a726986139fed29ad03137a (diff) | |
parent | 18a9cec3deb6cc2dc49020a89208dc70defe9822 (diff) | |
download | vyos-1x-3eb66e36b81c835f802900c4bc2e973e2657fa31.tar.gz vyos-1x-3eb66e36b81c835f802900c4bc2e973e2657fa31.zip |
T6695: Machine-readable operational mode support for traceroute
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/api/rest/models.py | 14 | ||||
-rw-r--r-- | src/services/api/rest/routers.py | 24 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/services/api/rest/models.py b/src/services/api/rest/models.py index 23ae9be9d..27d9fb5ee 100644 --- a/src/services/api/rest/models.py +++ b/src/services/api/rest/models.py @@ -279,6 +279,20 @@ class PoweroffModel(ApiModel): } +class TracerouteModel(ApiModel): + op: StrictStr + host: StrictStr + + class Config: + schema_extra = { + 'example': { + 'key': 'id_key', + 'op': 'traceroute', + 'host': 'host', + } + } + + class Success(BaseModel): success: bool data: Union[str, bool, Dict] diff --git a/src/services/api/rest/routers.py b/src/services/api/rest/routers.py index 5612e947c..e52c77fda 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 |