From 1a22fb925041d0297526b53f2e826ab43db8fb4a Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 21 Apr 2016 16:11:42 +0200 Subject: [PATCH] Expose the capture status in controller link API --- gns3server/controller/link.py | 7 ++++++- gns3server/controller/udp_link.py | 2 ++ gns3server/schemas/link.py | 6 +++++- gns3server/templates/project.html | 4 +++- tests/controller/test_link.py | 3 ++- tests/controller/test_udp_link.py | 3 ++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/link.py b/gns3server/controller/link.py index dbfb1cfa..432dfc99 100644 --- a/gns3server/controller/link.py +++ b/gns3server/controller/link.py @@ -27,6 +27,7 @@ class Link: self._vms = [] self._project = project self._data_link_type = data_link_type + self._capturing = False @asyncio.coroutine def addVM(self, vm, adapter_number, port_number): @@ -86,6 +87,10 @@ class Link: def id(self): return self._id + @property + def capturing(self): + return self._capturing + def __json__(self): res = [] for side in self._vms: @@ -94,4 +99,4 @@ class Link: "adapter_number": side["adapter_number"], "port_number": side["port_number"] }) - return {"vms": res, "link_id": self._id} + return {"vms": res, "link_id": self._id, "capturing": self._capturing} diff --git a/gns3server/controller/udp_link.py b/gns3server/controller/udp_link.py index 1ff91ef3..854ea931 100644 --- a/gns3server/controller/udp_link.py +++ b/gns3server/controller/udp_link.py @@ -90,6 +90,7 @@ class UDPLink(Link): "data_link_type": data_link_type } yield from self._capture_vm["vm"].post("/adapters/{adapter_number}/ports/{port_number}/start_capture".format(adapter_number=self._capture_vm["adapter_number"], port_number=self._capture_vm["port_number"]), data=data) + self._capturing = True @asyncio.coroutine def stop_capture(self): @@ -99,6 +100,7 @@ class UDPLink(Link): if self._capture_vm: yield from self._capture_vm["vm"].post("/adapters/{adapter_number}/ports/{port_number}/stop_capture".format(adapter_number=self._capture_vm["adapter_number"], port_number=self._capture_vm["port_number"])) self._capture_vm = None + self._capturing = False def _choose_capture_side(self): """ diff --git a/gns3server/schemas/link.py b/gns3server/schemas/link.py index f344852a..4d0db2f1 100644 --- a/gns3server/schemas/link.py +++ b/gns3server/schemas/link.py @@ -53,7 +53,11 @@ LINK_OBJECT_SCHEMA = { "required": ["vm_id", "adapter_number", "port_number"], "additionalProperties": False } - } + }, + "capturing": { + "description": "Read only propertie. Is a capture running on the link", + "type": "boolean" + }, }, "required": ["vms"], "additionalProperties": False diff --git a/gns3server/templates/project.html b/gns3server/templates/project.html index f493e411..17ebb7f7 100644 --- a/gns3server/templates/project.html +++ b/gns3server/templates/project.html @@ -42,10 +42,12 @@ in futur GNS3 versions. {% for link in project.links.values() %} - + + {% endfor %}
ID + Capture
{{link.id}}{{link.id}}{{link.capturing}}
diff --git a/tests/controller/test_link.py b/tests/controller/test_link.py index 80ab7a05..4504c3ee 100644 --- a/tests/controller/test_link.py +++ b/tests/controller/test_link.py @@ -68,7 +68,8 @@ def test_json(async_run, project, compute): "adapter_number": 1, "port_number": 3 } - ] + ], + "capturing": False } diff --git a/tests/controller/test_udp_link.py b/tests/controller/test_udp_link.py index 8908bef8..ca16a9d3 100644 --- a/tests/controller/test_udp_link.py +++ b/tests/controller/test_udp_link.py @@ -149,6 +149,7 @@ def test_capture(async_run, project): async_run(link.addVM(vm_iou, 3, 1)) capture = async_run(link.start_capture()) + assert link.capturing compute1.post.assert_any_call("/projects/{}/iou/vms/{}/adapters/3/ports/1/start_capture".format(project.id, vm_iou.id), data={ "capture_file_name": link.capture_file_name(), @@ -156,6 +157,6 @@ def test_capture(async_run, project): }) capture = async_run(link.stop_capture()) + assert link.capturing is False compute1.post.assert_any_call("/projects/{}/iou/vms/{}/adapters/3/ports/1/stop_capture".format(project.id, vm_iou.id)) -