From c8ed96d91b1e42ad50c0c66bf6db859cd093a9a3 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 15 Sep 2021 18:04:43 +0930 Subject: [PATCH] Add isolate and unisolate endpoints. Ref https://github.com/GNS3/gns3-gui/issues/3190 --- gns3server/api/routes/controller/nodes.py | 22 ++++++++++++++++++++++ tests/api/routes/controller/test_nodes.py | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gns3server/api/routes/controller/nodes.py b/gns3server/api/routes/controller/nodes.py index c175d583..0f28eb73 100644 --- a/gns3server/api/routes/controller/nodes.py +++ b/gns3server/api/routes/controller/nodes.py @@ -260,6 +260,28 @@ async def reload_node(node: Node = Depends(dep_node)) -> Response: return Response(status_code=status.HTTP_204_NO_CONTENT) +@router.post("/{node_id}/isolate", status_code=status.HTTP_204_NO_CONTENT) +async def isolate_node(node: Node = Depends(dep_node)) -> Response: + """ + Isolate a node (suspend all attached links). + """ + + for link in node.links: + await link.update_suspend(True) + return Response(status_code=status.HTTP_204_NO_CONTENT) + + +@router.post("/{node_id}/unisolate", status_code=status.HTTP_204_NO_CONTENT) +async def unisolate_node(node: Node = Depends(dep_node)) -> Response: + """ + Un-isolate a node (resume all attached suspended links). + """ + + for link in node.links: + await link.update_suspend(False) + return Response(status_code=status.HTTP_204_NO_CONTENT) + + @router.get("/{node_id}/links", response_model=List[schemas.Link], response_model_exclude_unset=True) async def get_node_links(node: Node = Depends(dep_node)) -> List[schemas.Link]: """ diff --git a/tests/api/routes/controller/test_nodes.py b/tests/api/routes/controller/test_nodes.py index 1f6820f9..0769f073 100644 --- a/tests/api/routes/controller/test_nodes.py +++ b/tests/api/routes/controller/test_nodes.py @@ -181,6 +181,20 @@ async def test_reload_node(app: FastAPI, client: AsyncClient, project: Project, assert response.status_code == status.HTTP_204_NO_CONTENT +async def test_isolate_node(app: FastAPI, client: AsyncClient, project: Project, compute: Compute, node: Node): + + compute.post = AsyncioMagicMock() + response = await client.post(app.url_path_for("isolate_node", project_id=project.id, node_id=node.id)) + assert response.status_code == status.HTTP_204_NO_CONTENT + + +async def test_unisolate_node(app: FastAPI, client: AsyncClient, project: Project, compute: Compute, node: Node): + + compute.post = AsyncioMagicMock() + response = await client.post(app.url_path_for("unisolate_node", project_id=project.id, node_id=node.id)) + assert response.status_code == status.HTTP_204_NO_CONTENT + + async def test_duplicate_node( app: FastAPI, client: AsyncClient,