Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    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)})
Пример #9
0
    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)
Пример #10
0
    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)})
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
    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)
Пример #20
0
    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)
Пример #21
0
    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)
Пример #22
0
    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)
Пример #23
0
    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)
Пример #24
0
    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)
Пример #25
0
def iou(port_manager):
    # Cleanup the IOU object
    IOU._instance = None
    iou = IOU.instance()
    iou.port_manager = port_manager
    return iou
Пример #26
0
    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)
Пример #27
0
    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)
Пример #28
0
    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)
Пример #29
0
def manager(port_manager):
    m = IOU.instance()
    m.port_manager = port_manager
    return m
Пример #30
0
    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)
Пример #31
0
    def delete(request, response):

        yield from IOU.instance().delete_node(request.match_info["node_id"])
        response.set_status(204)
Пример #32
0
    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)
Пример #33
0
    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)
Пример #34
0
    def list_iou_images(request, response):

        iou_manager = IOU.instance()
        images = yield from iou_manager.list_images()
        response.set_status(200)
        response.json(images)
Пример #35
0
    async def list_iou_images(request, response):

        iou_manager = IOU.instance()
        images = await iou_manager.list_images()
        response.set_status(200)
        response.json(images)
Пример #36
0
    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)
Пример #37
0
    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)
Пример #38
0
    def list_iou_images(request, response):

        iou_manager = IOU.instance()
        images = yield from iou_manager.list_images()
        response.set_status(200)
        response.json(images)
Пример #39
0
    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)
Пример #40
0
def iou(port_manager):
    # Cleanup the IOU object
    IOU._instance = None
    iou = IOU.instance()
    iou.port_manager = port_manager
    return iou
Пример #41
0
    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)
Пример #42
0
    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)
Пример #43
0
def manager(port_manager):
    m = IOU.instance()
    m.port_manager = port_manager
    return m
Пример #44
0
async def manager(loop, port_manager):

    m = IOU.instance()
    m.port_manager = port_manager
    return m
Пример #45
0
    def delete(request, response):

        yield from IOU.instance().delete_node(request.match_info["node_id"])
        response.set_status(204)