1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

Add an endpoint for listing the links of a project

This commit is contained in:
Julien Duponchelle 2016-05-17 16:10:47 +02:00
parent ce0d715895
commit b07dcf552c
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 43 additions and 0 deletions

View File

@ -31,6 +31,21 @@ class LinkHandler:
API entry point for Link
"""
@Route.get(
r"/projects/{project_id}/links",
parameters={
"project_id": "Project UUID"
},
status_codes={
200: "List of links returned",
},
description="List links of a project")
def list_links(request, response):
controller = Controller.instance()
project = controller.get_project(request.match_info["project_id"])
response.json([v for v in project.links.values()])
@Route.post(
r"/projects/{project_id}/links",
parameters={

View File

@ -77,6 +77,34 @@ def test_create_link(http_controller, tmpdir, project, compute, async_run):
assert len(response.json["nodes"]) == 2
def test_list_link(http_controller, tmpdir, project, compute, async_run):
response = MagicMock()
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
node1 = async_run(project.add_node(compute, None))
node2 = async_run(project.add_node(compute, None))
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
response = http_controller.post("/projects/{}/links".format(project.id), {
"nodes": [
{
"node_id": node1.id,
"adapter_number": 0,
"port_number": 3
},
{
"node_id": node2.id,
"adapter_number": 2,
"port_number": 4
}
]
})
response = http_controller.get("/projects/{}/links".format(project.id), example=True)
assert response.status == 200
assert len(response.json) == 1
def test_start_capture(http_controller, tmpdir, project, compute, async_run):
link = Link(project)
project._links = {link.id: link}