Fix crash when you start capture on a non running IOU

This commit is contained in:
Julien Duponchelle committed 2015-03-06 14:48:46 +01:00
1 parent 18f3859e87
commit d657f94c18
2 files changed
+54 -17

No files matched your search

+13 -4
View File
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from aiohttp.web import HTTPConflict
from ...web.route import Route
from ...modules.port_manager import PortManager
@@ -255,7 +255,8 @@ class IOUHandler:
status_codes={
200: "Capture started",
400: "Invalid request",
404: "Instance doesn't exist"
404: "Instance doesn't exist",
409: "VM not started"
},
description="Start a packet capture on a IOU VM instance",
input=IOU_CAPTURE_SCHEMA)
@@ -266,8 +267,11 @@ class IOUHandler:
adapter_number = int(request.match_info["adapter_number"])
port_number = int(request.match_info["port_number"])
pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"])
if not vm.is_running():
raise HTTPConflict(text="You can't capture the traffic on a non started VM")
yield from vm.start_capture(adapter_number, port_number, pcap_file_path, request.json["data_link_type"])
response.json({"pcap_file_path": pcap_file_path})
response.json({"pcap_file_path": str(pcap_file_path)})
@Route.post(
r"/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/stop_capture",
@@ -280,13 +284,18 @@ class IOUHandler:
status_codes={
204: "Capture stopped",
400: "Invalid request",
404: "Instance doesn't exist"
404: "Instance doesn't exist",
409: "VM not started"
},
description="Stop a packet capture on a IOU VM instance")
def stop_capture(request, response):
iou_manager = IOU.instance()
vm = iou_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
if not vm.is_running():
raise HTTPConflict(text="You can't capture the traffic on a non started VM")
adapter_number = int(request.match_info["adapter_number"])
port_number = int(request.match_info["port_number"])
yield from vm.stop_capture(adapter_number, port_number)