1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Add API endpoint to return all links attached to a node.

This commit is contained in:
grossmj 2018-06-06 20:46:44 +07:00
parent fd5df0052a
commit 62f87de23a
4 changed files with 29 additions and 7 deletions

View File

@ -90,9 +90,9 @@ class ProjectManager:
return
# send a warning if used disk space is >= 90%
if used_disk_space >= 90:
message = 'Only {}% or less of free disk space detected in "{}" on "{}"'.format(100 - used_disk_space,
project.path,
platform.node())
message = 'Only {:.2f}% or less of free disk space detected in "{}" on "{}"'.format(100 - used_disk_space,
project.path,
platform.node())
log.warning(message)
project.emit("log.warning", {"message": message})

View File

@ -321,7 +321,7 @@ class Node:
self._links.remove(link)
@property
def link(self):
def links(self):
return self._links
@asyncio.coroutine

View File

@ -307,6 +307,28 @@ class NodeHandler:
yield from project.delete_node(request.match_info["node_id"])
response.set_status(204)
@Route.get(
r"/projects/{project_id}/nodes/{node_id}/links",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
200: "Links returned",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Return all the links connected to this node")
def links(request, response):
project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"])
node = project.get_node(request.match_info["node_id"])
links = []
for link in node.links:
links.append(link.__json__())
response.json(links)
response.set_status(200)
@Route.get(
r"/projects/{project_id}/nodes/{node_id}/dynamips/auto_idlepc",
parameters={

View File

@ -98,7 +98,7 @@ def test_add_node(async_run, project, compute):
assert link.create.called
link._project.controller.notification.emit.assert_called_with("link.created", link.__json__())
assert link in node2.link
assert link in node2.links
def test_add_node_already_connected(async_run, project, compute):
@ -348,10 +348,10 @@ def test_delete(async_run, project, compute):
node2._ports = [EthernetPort("E0", 0, 0, 4)]
async_run(link.add_node(node2, 0, 4))
assert link in node2.link
assert link in node2.links
async_run(link.delete())
assert link not in node2.link
assert link not in node2.links
def test_update_filters(async_run, project, compute):