Expose the capture status in controller link API

pull/565/head
Julien Duponchelle 8 years ago
parent 549a6280c0
commit 1a22fb9250
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -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}

@ -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):
"""

@ -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

@ -42,10 +42,12 @@ in futur GNS3 versions.
<table border="1">
<tr>
<th>ID</td>
<th>Capture</td>
</tr>
{% for link in project.links.values() %}
<tr>
<td>{{link.id}}</td>
<td>{{link.id}}</td>
<td>{{link.capturing}}</td>
</tr>
{% endfor %}
</table>

@ -68,7 +68,8 @@ def test_json(async_run, project, compute):
"adapter_number": 1,
"port_number": 3
}
]
],
"capturing": False
}

@ -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))

Loading…
Cancel
Save