mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Expose the capture status in controller link API
This commit is contained in:
parent
549a6280c0
commit
1a22fb9250
@ -27,6 +27,7 @@ class Link:
|
|||||||
self._vms = []
|
self._vms = []
|
||||||
self._project = project
|
self._project = project
|
||||||
self._data_link_type = data_link_type
|
self._data_link_type = data_link_type
|
||||||
|
self._capturing = False
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def addVM(self, vm, adapter_number, port_number):
|
def addVM(self, vm, adapter_number, port_number):
|
||||||
@ -86,6 +87,10 @@ class Link:
|
|||||||
def id(self):
|
def id(self):
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def capturing(self):
|
||||||
|
return self._capturing
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
res = []
|
res = []
|
||||||
for side in self._vms:
|
for side in self._vms:
|
||||||
@ -94,4 +99,4 @@ class Link:
|
|||||||
"adapter_number": side["adapter_number"],
|
"adapter_number": side["adapter_number"],
|
||||||
"port_number": side["port_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
|
"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)
|
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
|
@asyncio.coroutine
|
||||||
def stop_capture(self):
|
def stop_capture(self):
|
||||||
@ -99,6 +100,7 @@ class UDPLink(Link):
|
|||||||
if self._capture_vm:
|
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"]))
|
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._capture_vm = None
|
||||||
|
self._capturing = False
|
||||||
|
|
||||||
def _choose_capture_side(self):
|
def _choose_capture_side(self):
|
||||||
"""
|
"""
|
||||||
|
@ -53,7 +53,11 @@ LINK_OBJECT_SCHEMA = {
|
|||||||
"required": ["vm_id", "adapter_number", "port_number"],
|
"required": ["vm_id", "adapter_number", "port_number"],
|
||||||
"additionalProperties": False
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"capturing": {
|
||||||
|
"description": "Read only propertie. Is a capture running on the link",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"required": ["vms"],
|
"required": ["vms"],
|
||||||
"additionalProperties": False
|
"additionalProperties": False
|
||||||
|
@ -42,10 +42,12 @@ in futur GNS3 versions.
|
|||||||
<table border="1">
|
<table border="1">
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</td>
|
<th>ID</td>
|
||||||
|
<th>Capture</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for link in project.links.values() %}
|
{% for link in project.links.values() %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{link.id}}</td>
|
<td>{{link.id}}</td>
|
||||||
|
<td>{{link.capturing}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -68,7 +68,8 @@ def test_json(async_run, project, compute):
|
|||||||
"adapter_number": 1,
|
"adapter_number": 1,
|
||||||
"port_number": 3
|
"port_number": 3
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"capturing": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ def test_capture(async_run, project):
|
|||||||
async_run(link.addVM(vm_iou, 3, 1))
|
async_run(link.addVM(vm_iou, 3, 1))
|
||||||
|
|
||||||
capture = async_run(link.start_capture())
|
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={
|
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(),
|
"capture_file_name": link.capture_file_name(),
|
||||||
@ -156,6 +157,6 @@ def test_capture(async_run, project):
|
|||||||
})
|
})
|
||||||
|
|
||||||
capture = async_run(link.stop_capture())
|
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))
|
compute1.post.assert_any_call("/projects/{}/iou/vms/{}/adapters/3/ports/1/stop_capture".format(project.id, vm_iou.id))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user