async def stop_capture(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) await vm.stop_capture(adapter_number) response.set_status(204)
async def stream_pcap_file(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) nio = vm.get_nio(adapter_number) await virtualbox_manager.stream_pcap_file(nio, vm.project.id, request, response)
async def create(request, response): vbox_manager = VirtualBox.instance() vm = await vbox_manager.create_node( request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), request.json.pop("vmname"), linked_clone=request.json.pop("linked_clone", False), console=request.json.get("console", None), console_type=request.json.get("console_type", "telnet"), adapters=request.json.get("adapters", 0)) if "ram" in request.json: ram = request.json.pop("ram") if ram != vm.ram: await vm.set_ram(ram) for name, value in request.json.items(): if name != "node_id": if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) response.set_status(201) response.json(vm)
async def delete_nio(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) await vm.adapter_remove_nio_binding(adapter_number) response.set_status(204)
def delete(request, response): # check the project_id exists ProjectManager.instance().get_project(request.match_info["project_id"]) yield from VirtualBox.instance().delete_node( request.match_info["node_id"]) response.set_status(204)
def reload(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) yield from vm.reload() response.set_status(204)
async def console_ws(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node( request.match_info["node_id"], project_id=request.match_info["project_id"]) return await vm.start_websocket_console(request)
async def resume(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) await vm.resume() response.set_status(204)
def stop_capture(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) vm.stop_capture(int(request.match_info["adapter_number"])) response.set_status(204)
def update(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) if "name" in request.json: name = request.json.pop("name") vmname = request.json.pop("vmname", None) if name != vm.name: oldname = vm.name vm.name = name if vm.linked_clone: try: yield from vm.set_vmname(vm.name) except VirtualBoxError as e: # In case of error we rollback (we can't change the name when running) vm.name = oldname vm.updated() raise e if "adapters" in request.json: adapters = int(request.json.pop("adapters")) if adapters != vm.adapters: yield from vm.set_adapters(adapters) if "ram" in request.json: ram = request.json.pop("ram") if ram != vm.ram: yield from vm.set_ram(ram) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) vm.updated() response.json(vm)
def start_capture(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"]) yield from vm.start_capture(adapter_number, pcap_file_path) response.json({"pcap_file_path": pcap_file_path})
def delete_nio(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) yield from vm.adapter_remove_nio_binding( int(request.match_info["adapter_number"])) response.set_status(204)
async def stream_pcap_file(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node( request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) nio = vm.get_nio(adapter_number) await virtualbox_manager.stream_pcap_file(nio, vm.project.id, request, response)
def start(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) if (yield from vm.check_hw_virtualization()): pm = ProjectManager.instance() if pm.check_hardware_virtualization(vm) is False: raise HTTPConflict(text="Cannot start VM because hardware virtualization (VT-x/AMD-V) is already used by another software like VMware or KVM (on Linux)") yield from vm.start() response.set_status(204)
def update_nio(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) nio = vm.ethernet_adapters[int(request.match_info["adapter_number"])] if "filters" in request.json and nio: nio.filters = request.json["filters"] yield from vm.adapter_update_nio_binding(int(request.match_info["adapter_number"]), nio) response.set_status(201) response.json(request.json)
def create_nio(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) nio_type = request.json["type"] if nio_type not in ("nio_udp", "nio_nat"): raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type)) nio = vbox_manager.create_nio(request.json) yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio) response.set_status(201) response.json(nio)
def update_nio(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node( request.match_info["node_id"], project_id=request.match_info["project_id"]) nio = vm.ethernet_adapters[int(request.match_info["adapter_number"])] if "filters" in request.json and nio: nio.filters = request.json["filters"] yield from vm.adapter_update_nio_binding( int(request.match_info["adapter_number"]), nio) response.set_status(201) response.json(request.json)
async def update_nio(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) nio = vm.get_nio(adapter_number) if "filters" in request.json: nio.filters = request.json["filters"] if "suspend" in request.json: nio.suspend = request.json["suspend"] await vm.adapter_update_nio_binding(adapter_number, nio) response.set_status(201) response.json(request.json)
async def update_nio(request, response): virtualbox_manager = VirtualBox.instance() vm = virtualbox_manager.get_node( request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) nio = vm.get_nio(adapter_number) if "filters" in request.json: nio.filters = request.json["filters"] if "suspend" in request.json: nio.suspend = request.json["suspend"] await vm.adapter_update_nio_binding(adapter_number, nio) response.set_status(201) response.json(request.json)
def create(request, response): vbox_manager = VirtualBox.instance() vm = yield from vbox_manager.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), request.json.pop("vmname"), linked_clone=request.json.pop("linked_clone", False), console=request.json.get("console", None), adapters=request.json.get("adapters", 0)) if "ram" in request.json: ram = request.json.pop("ram") if ram != vm.ram: yield from vm.set_ram(ram) for name, value in request.json.items(): if name != "node_id": if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) response.set_status(201) response.json(vm)
async def get_vms(request, response): vbox_manager = VirtualBox.instance() vms = await vbox_manager.list_vms() response.json(vms)
def manager(port_manager): m = VirtualBox.instance() m.port_manager = port_manager return m
def delete(request, response): # check the project_id exists ProjectManager.instance().get_project(request.match_info["project_id"]) yield from VirtualBox.instance().delete_node(request.match_info["node_id"]) response.set_status(204)
def show(request, response): vbox_manager = VirtualBox.instance() vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.json(vm)
def get_vms(request, response): vbox_manager = VirtualBox.instance() vms = yield from vbox_manager.list_vms() response.json(vms)
async def manager(loop, port_manager): m = VirtualBox.instance() m.port_manager = port_manager return m