mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-30 09:38:53 +00:00
Move to version 3 of the REST API.
Rename packet capture endpoints.
This commit is contained in:
parent
eeaf10b418
commit
359f9a7384
@ -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)
|
||||
|
@ -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"""
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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)):
|
||||
"""
|
||||
|
@ -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.
|
||||
"""
|
||||
|
@ -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):
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block head %}
|
||||
<script>
|
||||
var socket = new WebSocket("ws://" + location.host + "/v2/compute/notifications/ws");
|
||||
var socket = new WebSocket("ws://" + location.host + "/v3/compute/notifications/ws");
|
||||
socket.onopen = function (event) {
|
||||
document.getElementById("notifications").innerText = "Connected";
|
||||
};
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block head %}
|
||||
<script>
|
||||
var socket = new WebSocket("ws://" + location.host + "/v2/projects/{{project.id}}/notifications/ws");
|
||||
var socket = new WebSocket("ws://" + location.host + "/v3/projects/{{project.id}}/notifications/ws");
|
||||
socket.onopen = function (event) {
|
||||
document.getElementById("notifications").innerText = "Connected";
|
||||
};
|
||||
@ -60,7 +60,7 @@ in futur GNS3 versions.
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{link.capturing}}</td>
|
||||
<td><a href="/v2/projects/{{project.id}}/links/{{link.id}}/pcap">Download</a></td>
|
||||
<td><a href="/v3/projects/{{project.id}}/links/{{link.id}}/pcap">Download</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
@ -97,7 +97,7 @@ def compute_api(http_client, ws_client):
|
||||
Return an helper allowing you to call the hypervisor API via HTTP
|
||||
"""
|
||||
|
||||
return Query(http_client, ws_client, prefix="/compute", api_version=2)
|
||||
return Query(http_client, ws_client, prefix="/compute", api_version=3)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -106,7 +106,7 @@ def controller_api(http_client, ws_client, controller):
|
||||
Return an helper allowing you to call the server API without any prefix
|
||||
"""
|
||||
|
||||
return Query(http_client, ws_client, api_version=2)
|
||||
return Query(http_client, ws_client, api_version=3)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -41,17 +41,17 @@ def test_init(compute):
|
||||
def test_getUrl(controller):
|
||||
|
||||
compute = Compute("my_compute_id", protocol="https", host="localhost", port=84, controller=controller)
|
||||
assert compute._getUrl("/test") == "https://localhost:84/v2/compute/test"
|
||||
assert compute._getUrl("/test") == "https://localhost:84/v3/compute/test"
|
||||
# IPV6 localhost
|
||||
compute = Compute("my_compute_id", protocol="https", host="::1", port=84, controller=controller)
|
||||
assert compute._getUrl("/test") == "https://[::1]:84/v2/compute/test"
|
||||
assert compute._getUrl("/test") == "https://[::1]:84/v3/compute/test"
|
||||
|
||||
# Listen on all interfaces aka 0.0.0.0 require us to connect via 127.0.0.1
|
||||
compute = Compute("my_compute_id", protocol="https", host="0.0.0.0", port=84, controller=controller)
|
||||
assert compute._getUrl("/test") == "https://127.0.0.1:84/v2/compute/test"
|
||||
assert compute._getUrl("/test") == "https://127.0.0.1:84/v3/compute/test"
|
||||
# IPV6
|
||||
compute = Compute("my_compute_id", protocol="https", host="::", port=84, controller=controller)
|
||||
assert compute._getUrl("/test") == "https://[::1]:84/v2/compute/test"
|
||||
assert compute._getUrl("/test") == "https://[::1]:84/v3/compute/test"
|
||||
|
||||
|
||||
def test_get_url(controller):
|
||||
@ -86,7 +86,7 @@ async def test_compute_httpQuery(compute):
|
||||
response.status = 200
|
||||
await compute.post("/projects", {"a": "b"})
|
||||
await compute.close()
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/compute/projects", data=b'{"a": "b"}', headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
|
||||
mock.assert_called_with("POST", "https://example.com:84/v3/compute/projects", data=b'{"a": "b"}', headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
|
||||
assert compute._auth is None
|
||||
|
||||
|
||||
@ -101,7 +101,7 @@ async def test_compute_httpQueryAuth(compute):
|
||||
compute.password = "toor"
|
||||
await compute.post("/projects", {"a": "b"})
|
||||
await compute.close()
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/compute/projects", data=b'{"a": "b"}', headers={'content-type': 'application/json'}, auth=compute._auth, chunked=None, timeout=20)
|
||||
mock.assert_called_with("POST", "https://example.com:84/v3/compute/projects", data=b'{"a": "b"}', headers={'content-type': 'application/json'}, auth=compute._auth, chunked=None, timeout=20)
|
||||
assert compute._auth.login == "root"
|
||||
assert compute._auth.password == "toor"
|
||||
|
||||
@ -161,7 +161,7 @@ async def test_compute_httpQueryNotConnectedInvalidVersion(compute):
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
with pytest.raises(ControllerError):
|
||||
await compute.post("/projects", {"a": "b"})
|
||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=None, timeout=20)
|
||||
mock.assert_any_call("GET", "https://example.com:84/v3/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=None, timeout=20)
|
||||
await compute.close()
|
||||
|
||||
|
||||
@ -175,7 +175,7 @@ async def test_compute_httpQueryNotConnectedNonGNS3Server(compute):
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
with pytest.raises(ControllerError):
|
||||
await compute.post("/projects", {"a": "b"})
|
||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=None, timeout=20)
|
||||
mock.assert_any_call("GET", "https://example.com:84/v3/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=None, timeout=20)
|
||||
await compute.close()
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ async def test_compute_httpQueryNotConnectedNonGNS3Server2(compute):
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
with pytest.raises(ControllerError):
|
||||
await compute.post("/projects", {"a": "b"})
|
||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=None, timeout=20)
|
||||
mock.assert_any_call("GET", "https://example.com:84/v3/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=None, timeout=20)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -225,7 +225,7 @@ async def test_compute_httpQuery_project(compute):
|
||||
response.status = 200
|
||||
project = Project(name="Test")
|
||||
await compute.post("/projects", project)
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/compute/projects", data=json.dumps(project.__json__()), headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
|
||||
mock.assert_called_with("POST", "https://example.com:84/v3/compute/projects", data=json.dumps(project.__json__()), headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
|
||||
await compute.close()
|
||||
|
||||
# FIXME: https://github.com/aio-libs/aiohttp/issues/2525
|
||||
@ -334,7 +334,7 @@ async def test_downloadFile(project, compute):
|
||||
response.status = 200
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
await compute.download_file(project, "test/titi")
|
||||
mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/files/test/titi".format(project.id), auth=None)
|
||||
mock.assert_called_with("GET", "https://example.com:84/v3/compute/projects/{}/files/test/titi".format(project.id), auth=None)
|
||||
await compute.close()
|
||||
|
||||
|
||||
@ -369,7 +369,7 @@ async def test_forward_get(compute):
|
||||
response.status = 200
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
await compute.forward("GET", "qemu", "images")
|
||||
mock.assert_called_with("GET", "https://example.com:84/v2/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
mock.assert_called_with("GET", "https://example.com:84/v3/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
await compute.close()
|
||||
|
||||
|
||||
@ -392,7 +392,7 @@ async def test_forward_post(compute):
|
||||
response.status = 200
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
await compute.forward("POST", "qemu", "img", data={"id": 42})
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/compute/qemu/img", auth=None, data=b'{"id": 42}', headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
mock.assert_called_with("POST", "https://example.com:84/v3/compute/qemu/img", auth=None, data=b'{"id": 42}', headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
await compute.close()
|
||||
|
||||
|
||||
@ -411,7 +411,7 @@ async def test_images(compute):
|
||||
"filesize": 0}]).encode())
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
images = await compute.images("qemu")
|
||||
mock.assert_called_with("GET", "https://example.com:84/v2/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
mock.assert_called_with("GET", "https://example.com:84/v3/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'}, chunked=None, timeout=None)
|
||||
await compute.close()
|
||||
|
||||
assert images == [
|
||||
@ -428,7 +428,7 @@ async def test_list_files(project, compute):
|
||||
response.status = 200
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
assert await compute.list_files(project) == res
|
||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/projects/{}/files".format(project.id), auth=None, chunked=None, data=None, headers={'content-type': 'application/json'}, timeout=None)
|
||||
mock.assert_any_call("GET", "https://example.com:84/v3/compute/projects/{}/files".format(project.id), auth=None, chunked=None, data=None, headers={'content-type': 'application/json'}, timeout=None)
|
||||
await compute.close()
|
||||
|
||||
|
||||
@ -450,7 +450,7 @@ async def test_interfaces(compute):
|
||||
response.status = 200
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
assert await compute.interfaces() == res
|
||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/network/interfaces", auth=None, chunked=None, data=None, headers={'content-type': 'application/json'}, timeout=20)
|
||||
mock.assert_any_call("GET", "https://example.com:84/v3/compute/network/interfaces", auth=None, chunked=None, data=None, headers={'content-type': 'application/json'}, timeout=20)
|
||||
await compute.close()
|
||||
|
||||
|
||||
|
@ -117,7 +117,7 @@ async def test_cloud_start_capture(compute_api, vm):
|
||||
}
|
||||
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud.start_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/cloud/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
response = await compute_api.post("/projects/{project_id}/cloud/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -127,7 +127,7 @@ async def test_cloud_start_capture(compute_api, vm):
|
||||
async def test_cloud_stop_capture(compute_api, vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/cloud/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/cloud/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -203,7 +203,7 @@ async def test_docker_start_capture(compute_api, vm):
|
||||
with patch("gns3server.compute.docker.docker_vm.DockerVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.start_capture") as mock:
|
||||
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
|
||||
response = await compute_api.post("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
response = await compute_api.post("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -214,7 +214,7 @@ async def test_docker_stop_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.docker.docker_vm.DockerVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -306,7 +306,7 @@ async def test_iou_start_capture(compute_api, vm):
|
||||
}
|
||||
with patch("gns3server.compute.iou.iou_vm.IOUVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.iou.iou_vm.IOUVM.start_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
response = await compute_api.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -317,7 +317,7 @@ async def test_iou_stop_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.iou.iou_vm.IOUVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.iou.iou_vm.IOUVM.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -125,7 +125,7 @@ async def test_nat_start_capture(compute_api, vm):
|
||||
}
|
||||
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.nat.Nat.start_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
response = await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -135,7 +135,7 @@ async def test_nat_start_capture(compute_api, vm):
|
||||
async def test_nat_stop_capture(compute_api, vm):
|
||||
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.nat.Nat.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -428,7 +428,7 @@ async def test_qemu_start_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.qemu.qemu_vm.QemuVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM.start_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/qemu/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
response = await compute_api.post("/projects/{project_id}/qemu/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -439,7 +439,7 @@ async def test_qemu_stop_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.qemu.qemu_vm.QemuVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.qemu.qemu_vm.QemuVM.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/qemu/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/qemu/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -185,7 +185,7 @@ async def test_virtualbox_start_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.virtualbox.virtualbox_vm.VirtualBoxVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.virtualbox.virtualbox_vm.VirtualBoxVM.start_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
response = await compute_api.post("/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -196,7 +196,7 @@ async def test_virtualbox_stop_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.virtualbox.virtualbox_vm.VirtualBoxVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.virtualbox.virtualbox_vm.VirtualBoxVM.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -198,7 +198,7 @@ async def test_vmware_start_capture(compute_api, vm):
|
||||
with patch("gns3server.compute.vmware.vmware_vm.VMwareVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.vmware.vmware_vm.VMwareVM.start_capture") as mock:
|
||||
|
||||
response = await compute_api.post("/projects/{project_id}/vmware/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
response = await compute_api.post("/projects/{project_id}/vmware/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -209,7 +209,7 @@ async def test_vmware_stop_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.vmware.vmware_vm.VMwareVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.vmware.vmware_vm.VMwareVM.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/vmware/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/vmware/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -207,7 +207,7 @@ async def test_vpcs_start_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/vpcs/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
response = await compute_api.post("/projects/{project_id}/vpcs/nodes/{node_id}/adapters/0/ports/0/capture/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
|
||||
assert response.status_code == 200
|
||||
assert mock.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
@ -218,7 +218,7 @@ async def test_vpcs_stop_capture(compute_api, vm):
|
||||
|
||||
with patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.is_running", return_value=True):
|
||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.stop_capture") as mock:
|
||||
response = await compute_api.post("/projects/{project_id}/vpcs/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
response = await compute_api.post("/projects/{project_id}/vpcs/nodes/{node_id}/adapters/0/ports/0/capture/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]))
|
||||
assert response.status_code == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -322,7 +322,7 @@ async def test_start_capture(controller_api, project):
|
||||
link = Link(project)
|
||||
project._links = {link.id: link}
|
||||
with asyncio_patch("gns3server.controller.link.Link.start_capture") as mock:
|
||||
response = await controller_api.post("/projects/{}/links/{}/start_capture".format(project.id, link.id))
|
||||
response = await controller_api.post("/projects/{}/links/{}/capture/start".format(project.id, link.id))
|
||||
assert mock.called
|
||||
assert response.status_code == 201
|
||||
|
||||
@ -333,7 +333,7 @@ async def test_stop_capture(controller_api, project):
|
||||
link = Link(project)
|
||||
project._links = {link.id: link}
|
||||
with asyncio_patch("gns3server.controller.link.Link.stop_capture") as mock:
|
||||
response = await controller_api.post("/projects/{}/links/{}/stop_capture".format(project.id, link.id))
|
||||
response = await controller_api.post("/projects/{}/links/{}/capture/stop".format(project.id, link.id))
|
||||
assert mock.called
|
||||
assert response.status_code == 204
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
import pytest
|
||||
import uuid
|
||||
|
||||
from pathlib import Path
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
from gns3server.controller.template import Template
|
||||
@ -593,7 +594,7 @@ async def test_iou_template_create(controller_api):
|
||||
|
||||
params = {"name": "IOU template",
|
||||
"compute_id": "local",
|
||||
"path": "/path/to/i86bi_linux-ipbase-ms-12.4.bin",
|
||||
"path": str(Path("/path/to/i86bi_linux-ipbase-ms-12.4.bin")),
|
||||
"template_type": "iou"}
|
||||
|
||||
response = await controller_api.post("/templates", params)
|
||||
@ -724,7 +725,7 @@ async def test_vmware_template_create(controller_api):
|
||||
params = {"name": "VMware template",
|
||||
"compute_id": "local",
|
||||
"template_type": "vmware",
|
||||
"vmx_path": "/path/to/vm.vmx"}
|
||||
"vmx_path": str(Path("/path/to/vm.vmx"))}
|
||||
|
||||
response = await controller_api.post("/templates", params)
|
||||
assert response.status_code == 201
|
||||
|
Loading…
Reference in New Issue
Block a user