async def stop(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) await vm.stop() response.set_status(204)
def create(request, response): iou = IOU.instance() vm = yield from iou.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), path=request.json.get("path"), console=request.json.get("console")) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: if name == "startup_config_content" and ( vm.startup_config_content and len(vm.startup_config_content) > 0): continue if name == "private_config_content" and ( vm.private_config_content and len(vm.private_config_content) > 0): continue if request.json.get("use_default_iou_values") and ( name == "ram" or name == "nvram"): continue setattr(vm, name, value) response.set_status(201) response.json(vm)
async def create(request, response): iou = IOU.instance() vm = await iou.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), path=request.json.get("path"), console=request.json.get("console"), console_type=request.json.get( "console_type", "telnet")) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: if name == "application_id": continue # we must ignore this to avoid overwriting the application_id allocated by the IOU manager if name == "startup_config_content" and ( vm.startup_config_content and len(vm.startup_config_content) > 0): continue if name == "private_config_content" and ( vm.private_config_content and len(vm.private_config_content) > 0): continue if request.json.get("use_default_iou_values") and ( name == "ram" or name == "nvram"): continue setattr(vm, name, value) response.set_status(201) response.json(vm)
def reload(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) yield from vm.reload() response.set_status(204)
def duplicate(request, response): new_node = yield from IOU.instance().duplicate_node( request.match_info["node_id"], request.json["destination_node_id"] ) response.set_status(201) response.json(new_node)
async def stream_pcap_file(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) port_number = int(request.match_info["port_number"]) nio = vm.get_nio(adapter_number, port_number) await iou_manager.stream_pcap_file(nio, vm.project.id, request, response)
async def stop_capture(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) port_number = int(request.match_info["port_number"]) await vm.stop_capture(adapter_number, port_number) response.set_status(204)
async def start_capture(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) 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"]) await vm.start_capture(adapter_number, port_number, pcap_file_path, request.json["data_link_type"]) response.json({"pcap_file_path": str(pcap_file_path)})
def stop_capture(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) 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) response.set_status(204)
def start_capture(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) 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"]) yield from vm.start_capture(adapter_number, port_number, pcap_file_path, request.json["data_link_type"]) response.json({"pcap_file_path": str(pcap_file_path)})
def delete_nio(request, response): iou_manager = IOU.instance() vm = iou_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"]), int(request.match_info["port_number"])) response.set_status(204)
def update(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) 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 update(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) 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)
async def download_image(request, response): filename = request.match_info["filename"] iou_manager = IOU.instance() image_path = iou_manager.get_abs_image_path(filename) # Raise error if user try to escape if filename[0] == ".": raise aiohttp.web.HTTPForbidden() await response.stream_file(image_path)
def download_image(request, response): filename = request.match_info["filename"] iou_manager = IOU.instance() image_path = iou_manager.get_abs_image_path(filename) # Raise error if user try to escape if filename[0] == ".": raise aiohttp.web.HTTPForbidden() yield from response.file(image_path)
def create_nio(request, response): iou_manager = IOU.instance() vm = iou_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_tap", "nio_ethernet", "nio_generic_ethernet"): raise aiohttp.web.HTTPConflict(text="NIO of type {} is not supported".format(nio_type)) nio = iou_manager.create_nio(request.json) yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), int(request.match_info["port_number"]), nio) response.set_status(201) response.json(nio)
async def create_nio(request, response): iou_manager = IOU.instance() vm = iou_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_tap", "nio_ethernet", "nio_generic_ethernet"): raise aiohttp.web.HTTPConflict(text="NIO of type {} is not supported".format(nio_type)) nio = iou_manager.create_nio(request.json) await vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), int(request.match_info["port_number"]), nio) response.set_status(201) response.json(nio)
async def update_nio(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) port_number = int(request.match_info["port_number"]) nio = vm.get_nio(adapter_number, port_number) if "filters" in request.json: nio.filters = request.json["filters"] await vm.adapter_update_nio_binding(adapter_number, port_number, nio) response.set_status(201) response.json(request.json)
def update_nio(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) port_number = int(request.match_info["port_number"]) nio = vm.adapters[adapter_number].get_nio(port_number) if "filters" in request.json and nio: nio.filters = request.json["filters"] yield from vm.adapter_update_nio_binding( adapter_number, port_number, nio) response.set_status(201) response.json(nio)
def update(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) if vm.use_default_iou_values: # update the default IOU values in case the image or use_default_iou_values have changed # this is important to have the correct NVRAM amount in order to correctly push the configs to the NVRAM yield from vm.update_default_iou_values() vm.updated() response.json(vm)
def create(request, response): iou = IOU.instance() vm = yield from iou.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), console=request.json.get("console")) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: if name == "startup_config_content" and (vm.startup_config_content and len(vm.startup_config_content) > 0): continue if name == "private_config_content" and (vm.private_config_content and len(vm.private_config_content) > 0): continue setattr(vm, name, value) response.set_status(201) response.json(vm)
async def update(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: if name == "application_id": continue # we must ignore this to avoid overwriting the application_id allocated by the IOU manager setattr(vm, name, value) if vm.use_default_iou_values: # update the default IOU values in case the image or use_default_iou_values have changed # this is important to have the correct NVRAM amount in order to correctly push the configs to the NVRAM await vm.update_default_iou_values() vm.updated() response.json(vm)
def update(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: if name == "application_id": continue # we must ignore this to avoid overwriting the application_id allocated by the IOU manager setattr(vm, name, value) if vm.use_default_iou_values: # update the default IOU values in case the image or use_default_iou_values have changed # this is important to have the correct NVRAM amount in order to correctly push the configs to the NVRAM yield from vm.update_default_iou_values() vm.updated() response.json(vm)
def create(request, response): iou = IOU.instance() vm = yield from iou.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), path=request.json.get("path"), console=request.json.get("console")) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: if name == "application_id": continue # we must ignore this to avoid overwriting the application_id allocated by the IOU manager if name == "startup_config_content" and (vm.startup_config_content and len(vm.startup_config_content) > 0): continue if name == "private_config_content" and (vm.private_config_content and len(vm.private_config_content) > 0): continue if request.json.get("use_default_iou_values") and (name == "ram" or name == "nvram"): continue setattr(vm, name, value) response.set_status(201) response.json(vm)
def iou(port_manager): # Cleanup the IOU object IOU._instance = None iou = IOU.instance() iou.port_manager = port_manager return iou
def delete_nio(request, response): iou_manager = IOU.instance() vm = iou_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"]), int(request.match_info["port_number"])) response.set_status(204)
def duplicate(request, response): new_node = yield from IOU.instance().duplicate_node( request.match_info["node_id"], request.json["destination_node_id"]) response.set_status(201) response.json(new_node)
async def console_ws(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) return await vm.start_websocket_console(request)
def manager(port_manager): m = IOU.instance() m.port_manager = port_manager return m
def upload_image(request, response): iou_manager = IOU.instance() yield from iou_manager.write_image(request.match_info["filename"], request.content) response.set_status(204)
def delete(request, response): yield from IOU.instance().delete_node(request.match_info["node_id"]) response.set_status(204)
def show(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.json(vm)
def upload_image(request, response): iou_manager = IOU.instance() yield from iou_manager.write_image(request.match_info["filename"], request.content) response.set_status(204)
def list_iou_images(request, response): iou_manager = IOU.instance() images = yield from iou_manager.list_images() response.set_status(200) response.json(images)
async def list_iou_images(request, response): iou_manager = IOU.instance() images = await iou_manager.list_images() response.set_status(200) response.json(images)
async def upload_image(request, response): iou_manager = IOU.instance() filename = os.path.normpath(request.match_info["filename"]) await iou_manager.write_image(filename, request.content) response.set_status(204)
def suspend(request, response): iou_manager = IOU.instance() iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204)
def list_iou_images(request, response): iou_manager = IOU.instance() images = yield from iou_manager.list_images() response.set_status(200) response.json(images)
def suspend(request, response): iou_manager = IOU.instance() iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204)
def iou(port_manager): # Cleanup the IOU object IOU._instance = None iou = IOU.instance() iou.port_manager = port_manager return iou
def reload(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) yield from vm.reload() response.set_status(204)
def show(request, response): iou_manager = IOU.instance() vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.json(vm)
def manager(port_manager): m = IOU.instance() m.port_manager = port_manager return m
async def manager(loop, port_manager): m = IOU.instance() m.port_manager = port_manager return m
def delete(request, response): yield from IOU.instance().delete_node(request.match_info["node_id"]) response.set_status(204)