From 359f9a73841d9515098bbbb9cb518cc548165990 Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 2 Nov 2020 12:05:32 +1030 Subject: [PATCH] Move to version 3 of the REST API. Rename packet capture endpoints. --- gns3server/app.py | 6 +-- gns3server/controller/compute.py | 2 +- .../controller/gns3vm/virtualbox_gns3_vm.py | 2 +- gns3server/controller/link.py | 11 ++-- gns3server/endpoints/compute/__init__.py | 2 +- .../endpoints/compute/atm_switch_nodes.py | 6 +-- gns3server/endpoints/compute/cloud_nodes.py | 4 +- gns3server/endpoints/compute/docker_nodes.py | 6 +-- .../endpoints/compute/dynamips_nodes.py | 6 +-- .../endpoints/compute/ethernet_hub_nodes.py | 6 +-- .../compute/ethernet_switch_nodes.py | 6 +-- .../compute/frame_relay_switch_nodes.py | 6 +-- gns3server/endpoints/compute/iou_nodes.py | 6 +-- gns3server/endpoints/compute/nat_nodes.py | 6 +-- gns3server/endpoints/compute/qemu_nodes.py | 6 +-- .../endpoints/compute/virtualbox_nodes.py | 6 +-- gns3server/endpoints/compute/vmware_nodes.py | 6 +-- gns3server/endpoints/compute/vpcs_nodes.py | 6 +-- gns3server/endpoints/controller/links.py | 54 +++++++++---------- gns3server/endpoints/controller/nodes.py | 2 +- gns3server/templates/compute.html | 2 +- gns3server/templates/project.html | 4 +- tests/conftest.py | 4 +- tests/controller/test_compute.py | 32 +++++------ tests/endpoints/compute/test_cloud_nodes.py | 4 +- tests/endpoints/compute/test_docker_nodes.py | 4 +- tests/endpoints/compute/test_iou_nodes.py | 4 +- tests/endpoints/compute/test_nat_nodes.py | 4 +- tests/endpoints/compute/test_qemu_nodes.py | 4 +- .../compute/test_virtualbox_nodes.py | 4 +- tests/endpoints/compute/test_vmware_nodes.py | 4 +- tests/endpoints/compute/test_vpcs_nodes.py | 4 +- tests/endpoints/controller/test_links.py | 4 +- tests/endpoints/controller/test_templates.py | 5 +- 34 files changed, 120 insertions(+), 118 deletions(-) diff --git a/gns3server/app.py b/gns3server/app.py index 0cc3d035..bdf41541 100644 --- a/gns3server/app.py +++ b/gns3server/app.py @@ -49,7 +49,7 @@ log = logging.getLogger(__name__) app = FastAPI(title="GNS3 controller API", description="This page describes the public controller API for GNS3", - version="v2") + version="v3") origins = [ "http://127.0.0.1", @@ -71,8 +71,8 @@ app.add_middleware( ) app.include_router(index.router, tags=["Index"]) -app.include_router(controller.router, prefix="/v2") -app.mount("/v2/compute", compute_api) +app.include_router(controller.router, prefix="/v3") +app.mount("/v3/compute", compute_api) @app.exception_handler(ControllerError) diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 1db7933d..0323037e 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -497,7 +497,7 @@ class Compute: host = "[{}]".format(host) elif host == "0.0.0.0": host = "127.0.0.1" - return "{}://{}:{}/v2/compute{}".format(self._protocol, host, self._port, path) + return "{}://{}:{}/v3/compute{}".format(self._protocol, host, self._port, path) def get_url(self, path): """ Returns URL for specific path at Compute""" diff --git a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py index fb9fbc99..e06828de 100644 --- a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py +++ b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py @@ -310,7 +310,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM): remaining_try = 300 while remaining_try > 0: try: - async with HTTPClient.get(f"http://127.0.0.1:{api_port}/v2/compute/network/interfaces") as resp: + async with HTTPClient.get(f"http://127.0.0.1:{api_port}/v3/compute/network/interfaces") as resp: if resp.status < 300: try: json_data = await resp.json() diff --git a/gns3server/controller/link.py b/gns3server/controller/link.py index 6d02adee..8e461858 100644 --- a/gns3server/controller/link.py +++ b/gns3server/controller/link.py @@ -345,11 +345,12 @@ class Link: node_id = self.capture_node["node"].id adapter_number = self.capture_node["adapter_number"] port_number = self.capture_node["port_number"] - url = "/projects/{project_id}/{node_type}/nodes/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap".format(project_id=self.project.id, - node_type=node_type, - node_id=node_id, - adapter_number=adapter_number, - port_number=port_number) + url = "/projects/{project_id}/{node_type}/nodes/{node_id}/adapters/{adapter_number}/" \ + "ports/{port_number}/capture/stream".format(project_id=self.project.id, + node_type=node_type, + node_id=node_id, + adapter_number=adapter_number, + port_number=port_number) return compute._getUrl(url) diff --git a/gns3server/endpoints/compute/__init__.py b/gns3server/endpoints/compute/__init__.py index b75d8de9..04c1bfe3 100644 --- a/gns3server/endpoints/compute/__init__.py +++ b/gns3server/endpoints/compute/__init__.py @@ -51,7 +51,7 @@ from . import vpcs_nodes compute_api = FastAPI(title="GNS3 compute API", description="This page describes the private compute API for GNS3. PLEASE DO NOT USE DIRECTLY!", - version="v2") + version="v3") @compute_api.exception_handler(ComputeError) diff --git a/gns3server/endpoints/compute/atm_switch_nodes.py b/gns3server/endpoints/compute/atm_switch_nodes.py index 9f862967..7b09a5fb 100644 --- a/gns3server/endpoints/compute/atm_switch_nodes.py +++ b/gns3server/endpoints/compute/atm_switch_nodes.py @@ -186,7 +186,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: ATMSwitch = De await nio.delete() -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -202,7 +202,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop_capture", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: ATMSwitch = Depends(dep_node)): @@ -214,7 +214,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: ATMSwitch = await node.stop_capture(port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: ATMSwitch = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/cloud_nodes.py b/gns3server/endpoints/compute/cloud_nodes.py index 85a7c632..631c0341 100644 --- a/gns3server/endpoints/compute/cloud_nodes.py +++ b/gns3server/endpoints/compute/cloud_nodes.py @@ -197,7 +197,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: Cloud = Depend await node.remove_nio(port_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -213,7 +213,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: Cloud = Depends(dep_node)): diff --git a/gns3server/endpoints/compute/docker_nodes.py b/gns3server/endpoints/compute/docker_nodes.py index 44ff5e06..e88664ef 100644 --- a/gns3server/endpoints/compute/docker_nodes.py +++ b/gns3server/endpoints/compute/docker_nodes.py @@ -262,7 +262,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: DockerVM = Dep await node.adapter_remove_nio_binding(adapter_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -278,7 +278,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": str(pcap_file_path)} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: DockerVM = Depends(dep_node)): @@ -290,7 +290,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: DockerVM = D await node.stop_capture(adapter_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: DockerVM = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/dynamips_nodes.py b/gns3server/endpoints/compute/dynamips_nodes.py index 890e4d30..6ba57047 100644 --- a/gns3server/endpoints/compute/dynamips_nodes.py +++ b/gns3server/endpoints/compute/dynamips_nodes.py @@ -219,7 +219,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: Router = Depen await nio.delete() -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -242,7 +242,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: Router = Depends(dep_node)): @@ -253,7 +253,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: Router = Dep await node.stop_capture(adapter_number, port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: Router = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/ethernet_hub_nodes.py b/gns3server/endpoints/compute/ethernet_hub_nodes.py index c25aa5d8..06c46248 100644 --- a/gns3server/endpoints/compute/ethernet_hub_nodes.py +++ b/gns3server/endpoints/compute/ethernet_hub_nodes.py @@ -187,7 +187,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: EthernetHub = await nio.delete() -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -203,7 +203,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: EthernetHub = Depends(dep_node)): @@ -215,7 +215,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: EthernetHub await node.stop_capture(port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: EthernetHub = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/ethernet_switch_nodes.py b/gns3server/endpoints/compute/ethernet_switch_nodes.py index 42fab5e5..051338e3 100644 --- a/gns3server/endpoints/compute/ethernet_switch_nodes.py +++ b/gns3server/endpoints/compute/ethernet_switch_nodes.py @@ -186,7 +186,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: EthernetSwitch await nio.delete() -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -202,7 +202,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int,port_number: int, node: EthernetSwitch = Depends(dep_node)): @@ -214,7 +214,7 @@ async def stop_capture(adapter_number: int,port_number: int, node: EthernetSwitc await node.stop_capture(port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: EthernetSwitch = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/frame_relay_switch_nodes.py b/gns3server/endpoints/compute/frame_relay_switch_nodes.py index daff363e..2728e81b 100644 --- a/gns3server/endpoints/compute/frame_relay_switch_nodes.py +++ b/gns3server/endpoints/compute/frame_relay_switch_nodes.py @@ -188,7 +188,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: FrameRelaySwit await nio.delete() -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -204,7 +204,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: FrameRelaySwitch = Depends(dep_node)): @@ -216,7 +216,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: FrameRelaySw await node.stop_capture(port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: FrameRelaySwitch = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/iou_nodes.py b/gns3server/endpoints/compute/iou_nodes.py index 21995938..be3320d9 100644 --- a/gns3server/endpoints/compute/iou_nodes.py +++ b/gns3server/endpoints/compute/iou_nodes.py @@ -237,7 +237,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: IOUVM = Depend await node.adapter_remove_nio_binding(adapter_number, port_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -252,7 +252,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": str(pcap_file_path)} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: IOUVM = Depends(dep_node)): @@ -263,7 +263,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: IOUVM = Depe await node.stop_capture(adapter_number, port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: IOUVM = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/nat_nodes.py b/gns3server/endpoints/compute/nat_nodes.py index 62a5cb3b..de255126 100644 --- a/gns3server/endpoints/compute/nat_nodes.py +++ b/gns3server/endpoints/compute/nat_nodes.py @@ -192,7 +192,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: Nat = Depends( await node.remove_nio(port_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -208,7 +208,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: Nat = Depends(dep_node)): @@ -220,7 +220,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: Nat = Depend await node.stop_capture(port_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: Nat = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/qemu_nodes.py b/gns3server/endpoints/compute/qemu_nodes.py index c1988fcd..5e8ca4d0 100644 --- a/gns3server/endpoints/compute/qemu_nodes.py +++ b/gns3server/endpoints/compute/qemu_nodes.py @@ -252,7 +252,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: QemuVM = Depen await node.adapter_remove_nio_binding(adapter_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -268,7 +268,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": str(pcap_file_path)} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: QemuVM = Depends(dep_node)): @@ -280,7 +280,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: QemuVM = Dep await node.stop_capture(adapter_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: QemuVM = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/virtualbox_nodes.py b/gns3server/endpoints/compute/virtualbox_nodes.py index 441d782b..42b1df5c 100644 --- a/gns3server/endpoints/compute/virtualbox_nodes.py +++ b/gns3server/endpoints/compute/virtualbox_nodes.py @@ -260,7 +260,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: VirtualBoxVM = await node.adapter_remove_nio_binding(adapter_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -276,7 +276,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": str(pcap_file_path)} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: VirtualBoxVM = Depends(dep_node)): @@ -288,7 +288,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: VirtualBoxVM await node.stop_capture(adapter_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: VirtualBoxVM = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/vmware_nodes.py b/gns3server/endpoints/compute/vmware_nodes.py index 12b435b1..2c706b77 100644 --- a/gns3server/endpoints/compute/vmware_nodes.py +++ b/gns3server/endpoints/compute/vmware_nodes.py @@ -225,7 +225,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: VMwareVM = Dep await node.adapter_remove_nio_binding(adapter_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -241,7 +241,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: VMwareVM = Depends(dep_node)): @@ -253,7 +253,7 @@ async def stop_capture(adapter_number: int, port_number: int, node: VMwareVM = D await node.stop_capture(adapter_number) -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: VMwareVM = Depends(dep_node)): """ diff --git a/gns3server/endpoints/compute/vpcs_nodes.py b/gns3server/endpoints/compute/vpcs_nodes.py index a661ad66..ed1483ad 100644 --- a/gns3server/endpoints/compute/vpcs_nodes.py +++ b/gns3server/endpoints/compute/vpcs_nodes.py @@ -208,7 +208,7 @@ async def delete_nio(adapter_number: int, port_number: int, node: VPCSVM = Depen await node.port_remove_nio_binding(port_number) -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/start_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/start", responses=responses) async def start_capture(adapter_number: int, port_number: int, @@ -224,7 +224,7 @@ async def start_capture(adapter_number: int, return {"pcap_file_path": pcap_file_path} -@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/stop_capture", +@router.post("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stop", status_code=status.HTTP_204_NO_CONTENT, responses=responses) async def stop_capture(adapter_number: int, port_number: int, node: VPCSVM = Depends(dep_node)): @@ -244,7 +244,7 @@ async def reset_console(node: VPCSVM = Depends(dep_node)): await node.reset_console() -@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/pcap", +@router.get("/{node_id}/adapters/{adapter_number}/ports/{port_number}/capture/stream", responses=responses) async def stream_pcap_file(adapter_number: int, port_number: int, node: VPCSVM = Depends(dep_node)): """ diff --git a/gns3server/endpoints/controller/links.py b/gns3server/endpoints/controller/links.py index 80fa9d0b..0a3730aa 100644 --- a/gns3server/endpoints/controller/links.py +++ b/gns3server/endpoints/controller/links.py @@ -136,31 +136,6 @@ async def update_link(link_data: schemas.Link, link: Link = Depends(dep_link)): return link.__json__() -@router.post("/{link_id}/start_capture", - status_code=status.HTTP_201_CREATED, - response_model=schemas.Link, - responses=responses) -async def start_capture(capture_data: dict, link: Link = Depends(dep_link)): - """ - Start packet capture on the link. - """ - - await link.start_capture(data_link_type=capture_data.get("data_link_type", "DLT_EN10MB"), - capture_file_name=capture_data.get("capture_file_name")) - return link.__json__() - - -@router.post("/{link_id}/stop_capture", - status_code=status.HTTP_204_NO_CONTENT, - responses=responses) -async def stop_capture(link: Link = Depends(dep_link)): - """ - Stop packet capture on the link. - """ - - await link.stop_capture() - - @router.delete("/{link_id}", status_code=status.HTTP_204_NO_CONTENT, responses=responses) @@ -185,9 +160,34 @@ async def reset_link(link: Link = Depends(dep_link)): return link.__json__() -@router.get("/{link_id}/pcap", +@router.post("/{link_id}/capture/start", + status_code=status.HTTP_201_CREATED, + response_model=schemas.Link, + responses=responses) +async def start_capture(capture_data: dict, link: Link = Depends(dep_link)): + """ + Start packet capture on the link. + """ + + await link.start_capture(data_link_type=capture_data.get("data_link_type", "DLT_EN10MB"), + capture_file_name=capture_data.get("capture_file_name")) + return link.__json__() + + +@router.post("/{link_id}/capture/stop", + status_code=status.HTTP_204_NO_CONTENT, + responses=responses) +async def stop_capture(link: Link = Depends(dep_link)): + """ + Stop packet capture on the link. + """ + + await link.stop_capture() + + +@router.get("/{link_id}/capture/stream", responses=responses) -async def pcap(request: Request, link: Link = Depends(dep_link)): +async def stream_pcap(request: Request, link: Link = Depends(dep_link)): """ Stream the PCAP capture file from compute. """ diff --git a/gns3server/endpoints/controller/nodes.py b/gns3server/endpoints/controller/nodes.py index 42c3cb6a..20c7b303 100644 --- a/gns3server/endpoints/controller/nodes.py +++ b/gns3server/endpoints/controller/nodes.py @@ -380,7 +380,7 @@ async def ws_console(websocket: WebSocket, node: Node = Depends(dep_node)): compute = node.compute await websocket.accept() log.info(f"New client {websocket.client.host}:{websocket.client.port} has connected to controller console WebSocket") - ws_console_compute_url = f"ws://{compute.host}:{compute.port}/v2/compute/projects/" \ + ws_console_compute_url = f"ws://{compute.host}:{compute.port}/v3/compute/projects/" \ f"{node.project.id}/{node.node_type}/nodes/{node.id}/console/ws" async def ws_receive(ws_console_compute): diff --git a/gns3server/templates/compute.html b/gns3server/templates/compute.html index dd563d26..2ef05621 100644 --- a/gns3server/templates/compute.html +++ b/gns3server/templates/compute.html @@ -2,7 +2,7 @@ {% block head %}