当前位置: 首页>>代码示例>>Python>>正文


Python controller.Controller类代码示例

本文整理汇总了Python中gns3server.controller.Controller的典型用法代码示例。如果您正苦于以下问题:Python Controller类的具体用法?Python Controller怎么用?Python Controller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Controller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

    async def update(request, response):

        controller = Controller().instance()
        gns3_vm = controller.gns3vm
        await gns3_vm.update_settings(request.json)
        controller.save()
        response.json(gns3_vm)
        response.set_status(201)
开发者ID:GNS3,项目名称:gns3-server,代码行数:8,代码来源:gns3_vm_handler.py

示例2: update

    async def update(request, response):

        controller = Controller().instance()
        iou_license = controller.iou_license
        iou_license.update(request.json)
        controller.save()
        response.json(iou_license)
        response.set_status(201)
开发者ID:GNS3,项目名称:gns3-server,代码行数:8,代码来源:server_handler.py

示例3: reload

    def reload(request, response):

        project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"])
        node = project.get_node(request.match_info["node_id"])
        yield from node.reload()
        response.json(node)
        response.set_status(201)
开发者ID:athmane,项目名称:gns3-server,代码行数:7,代码来源:node_handler.py

示例4: pcap

    def pcap(request, response):

        project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"])
        link = project.get_link(request.match_info["link_id"])

        while link.capture_file_path is None:
            raise aiohttp.web.HTTPNotFound(text="pcap file not found")

        while not os.path.isfile(link.capture_file_path):
            yield from asyncio.sleep(0.5)

        try:
            with open(link.capture_file_path, "rb") as f:

                response.content_type = "application/vnd.tcpdump.pcap"
                response.set_status(200)
                response.enable_chunked_encoding()
                yield from response.prepare(request)

                while True:
                    chunk = f.read(4096)
                    if not chunk:
                        yield from asyncio.sleep(0.1)
                    yield from response.write(chunk)
        except OSError:
            raise aiohttp.web.HTTPNotFound(text="pcap file {} not found or not accessible".format(link.capture_file_path))
开发者ID:athmane,项目名称:gns3-server,代码行数:26,代码来源:link_handler.py

示例5: write_file

    def write_file(request, response):

        controller = Controller.instance()
        project = yield from controller.get_loaded_project(request.match_info["project_id"])
        path = request.match_info["path"]
        path = os.path.normpath(path).strip("/")

        # Raise error if user try to escape
        if path[0] == ".":
            raise aiohttp.web.HTTPForbidden
        path = os.path.join(project.path, path)

        response.set_status(200)

        try:
            with open(path, 'wb+') as f:
                while True:
                    packet = yield from request.content.read(512)
                    if not packet:
                        break
                    f.write(packet)
        except FileNotFoundError:
            raise aiohttp.web.HTTPNotFound()
        except PermissionError:
            raise aiohttp.web.HTTPForbidden()
        except OSError as e:
            raise aiohttp.web.HTTPConflict(text=str(e))
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:27,代码来源:project_handler.py

示例6: get_file

    def get_file(request, response):

        controller = Controller.instance()
        project = yield from controller.get_loaded_project(request.match_info["project_id"])
        path = request.match_info["path"]
        path = os.path.normpath(path).strip('/')

        # Raise error if user try to escape
        if path[0] == ".":
            raise aiohttp.web.HTTPForbidden
        path = os.path.join(project.path, path)

        response.content_type = "application/octet-stream"
        response.set_status(200)
        response.enable_chunked_encoding()
        # Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
        response.content_length = None

        try:
            with open(path, "rb") as f:
                response.start(request)
                while True:
                    data = f.read(4096)
                    if not data:
                        break
                    yield from response.write(data)

        except FileNotFoundError:
            raise aiohttp.web.HTTPNotFound()
        except PermissionError:
            raise aiohttp.web.HTTPForbidden()
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:31,代码来源:project_handler.py

示例7: import_project

    def import_project(request, response):

        controller = Controller.instance()

        if request.get("path"):
            config = Config.instance()
            if config.get_section_config("Server").getboolean("local", False) is False:
                response.set_status(403)
                return
        path = request.json.get("path")
        name = request.json.get("name")

        # We write the content to a temporary location and after we extract it all.
        # It could be more optimal to stream this but it is not implemented in Python.
        # Spooled means the file is temporary kept in memory until max_size is reached
        try:
            with tempfile.SpooledTemporaryFile(max_size=10000) as temp:
                while True:
                    packet = yield from request.content.read(512)
                    if not packet:
                        break
                    temp.write(packet)
                project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name)
        except OSError as e:
            raise aiohttp.web.HTTPInternalServerError(text="Could not import the project: {}".format(e))

        response.json(project)
        response.set_status(201)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:28,代码来源:project_handler.py

示例8: export_project

    def export_project(request, response):

        controller = Controller.instance()
        project = yield from controller.get_loaded_project(request.match_info["project_id"])

        try:
            with tempfile.TemporaryDirectory() as tmp_dir:
                datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
                # We need to do that now because export could failed and raise an HTTP error
                # that why response start need to be the later possible
                response.content_type = 'application/gns3project'
                response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
                response.enable_chunked_encoding()
                # Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
                response.content_length = None
                response.start(request)

                for data in datas:
                    response.write(data)
                    yield from response.drain()

                yield from response.write_eof()
        # Will be raise if you have no space left or permission issue on your temporary directory
        # RuntimeError: something was wrong during the zip process
        except (OSError, RuntimeError) as e:
            raise aiohttp.web.HTTPNotFound(text="Can't export project: {}".format(str(e)))
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:26,代码来源:project_handler.py

示例9: notification_ws

    def notification_ws(request, response):

        controller = Controller.instance()
        project = controller.get_project(request.match_info["project_id"])

        ws = aiohttp.web.WebSocketResponse()
        yield from ws.prepare(request)

        asyncio.async(process_websocket(ws))

        with controller.notification.queue(project) as queue:
            while True:
                try:
                    notification = yield from queue.get_json(5)
                except asyncio.futures.CancelledError as e:
                    break
                if ws.closed:
                    break
                ws.send_str(notification)

        if project.auto_close:
            # To avoid trouble with client connecting disconnecting we sleep few seconds before checking
            # if someone else is not connected
            yield from asyncio.sleep(5)
            if not controller.notification.project_has_listeners(project):
                yield from project.close()

        return ws
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:28,代码来源:project_handler.py

示例10: notification

    def notification(request, response):

        controller = Controller.instance()
        project = controller.get_project(request.match_info["project_id"])

        response.content_type = "application/json"
        response.set_status(200)
        response.enable_chunked_encoding()
        # Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
        response.content_length = None

        response.start(request)
        with controller.notification.queue(project) as queue:
            while True:
                try:
                    msg = yield from queue.get_json(5)
                    response.write(("{}\n".format(msg)).encode("utf-8"))
                except asyncio.futures.CancelledError as e:
                    break
                yield from response.drain()

        if project.auto_close:
            # To avoid trouble with client connecting disconnecting we sleep few seconds before checking
            # if someone else is not connected
            yield from asyncio.sleep(5)
            if not controller.notification.project_has_listeners(project):
                yield from project.close()
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:27,代码来源:project_handler.py

示例11: close

    def close(request, response):

        controller = Controller.instance()
        project = controller.get_project(request.match_info["project_id"])
        yield from project.close()
        response.set_status(201)
        response.json(project)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:7,代码来源:project_handler.py

示例12: idlepc_proposals

    def idlepc_proposals(request, response):

        project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"])
        node = project.get_node(request.match_info["node_id"])
        idle = yield from node.dynamips_idlepc_proposals()
        response.json(idle)
        response.set_status(200)
开发者ID:athmane,项目名称:gns3-server,代码行数:7,代码来源:node_handler.py

示例13: delete

    async def delete(request, response):

        controller = Controller.instance()
        project = controller.get_project(request.match_info["project_id"])
        await project.delete()
        controller.remove_project(project)
        response.set_status(204)
开发者ID:GNS3,项目名称:gns3-server,代码行数:7,代码来源:project_handler.py

示例14: stop_capture

    def stop_capture(request, response):

        project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"])
        link = project.get_link(request.match_info["link_id"])
        yield from link.stop_capture()
        response.set_status(201)
        response.json(link)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:7,代码来源:link_handler.py

示例15: raw

    def raw(request, response):

        controller = Controller.instance()
        try:
            yield from response.file(controller.symbols.get_path(request.match_info["symbol_id"]))
        except (KeyError, FileNotFoundError, PermissionError):
            response.set_status(404)
开发者ID:athmane,项目名称:gns3-server,代码行数:7,代码来源:symbol_handler.py


注:本文中的gns3server.controller.Controller类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。