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


Python docker.Docker类代码示例

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


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

示例1: stop_capture

    async def stop_capture(request, response):

        docker_manager = Docker.instance()
        container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        await container.stop_capture(adapter_number)
        response.set_status(204)
开发者ID:GNS3,项目名称:gns3-server,代码行数:7,代码来源:docker_handler.py

示例2: test_pull_image

def test_pull_image(loop):
    class Response:
        """
        Simulate a response splitted in multiple packets
        """

        def __init__(self):
            self._read = -1

        async def read(self, size):
            self._read += 1
            if self._read == 0:
                return b'{"progress": "0/100",'
            elif self._read == 1:
                return '"id": 42}'
            else:
                None

    mock_query = MagicMock()
    mock_query.content.return_value = Response()

    with asyncio_patch("gns3server.compute.docker.Docker.query", side_effect=DockerHttp404Error("404")):
        with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
            images = loop.run_until_complete(asyncio.ensure_future(Docker.instance().pull_image("ubuntu")))
            mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}, timeout=None)
开发者ID:GNS3,项目名称:gns3-server,代码行数:25,代码来源:test_docker.py

示例3: stream_pcap_file

    async def stream_pcap_file(request, response):

        docker_manager = Docker.instance()
        container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        nio = container.get_nio(adapter_number)
        await docker_manager.stream_pcap_file(nio, container.project.id, request, response)
开发者ID:GNS3,项目名称:gns3-server,代码行数:7,代码来源:docker_handler.py

示例4: start_capture

    async def start_capture(request, response):

        docker_manager = Docker.instance()
        container = docker_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(container.project.capture_working_directory(), request.json["capture_file_name"])
        await container.start_capture(adapter_number, pcap_file_path)
        response.json({"pcap_file_path": str(pcap_file_path)})
开发者ID:GNS3,项目名称:gns3-server,代码行数:8,代码来源:docker_handler.py

示例5: duplicate

    def duplicate(request, response):

        new_node = yield from Docker.instance().duplicate_node(
            request.match_info["node_id"],
            request.json["destination_node_id"]
        )
        response.set_status(201)
        response.json(new_node)
开发者ID:athmane,项目名称:gns3-server,代码行数:8,代码来源:docker_handler.py

示例6: create_nio

 def create_nio(request, response):
     docker_manager = Docker.instance()
     container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
     nio_type = request.json["type"]
     if nio_type != "nio_udp":
         raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
     nio = docker_manager.create_nio(request.json)
     yield from container.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
     response.set_status(201)
     response.json(nio)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:10,代码来源:docker_handler.py

示例7: update_nio

    def update_nio(request, response):

        docker_manager = Docker.instance()
        container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        nio = container.ethernet_adapters[int(request.match_info["adapter_number"])].get_nio(0)
        if "filters" in request.json and nio:
            nio.filters = request.json["filters"]
        yield from container.adapter_update_nio_binding(int(request.match_info["port_number"]), nio)
        response.set_status(201)
        response.json(request.json)
开发者ID:athmane,项目名称:gns3-server,代码行数:10,代码来源:docker_handler.py

示例8: update_nio

    async def update_nio(request, response):

        docker_manager = Docker.instance()
        container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        nio = container.get_nio(adapter_number)
        if "filters" in request.json and nio:
            nio.filters = request.json["filters"]
        await container.adapter_update_nio_binding(adapter_number, nio)
        response.set_status(201)
        response.json(request.json)
开发者ID:GNS3,项目名称:gns3-server,代码行数:11,代码来源:docker_handler.py

示例9: update

    def update(request, response):

        docker_manager = Docker.instance()
        container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])

        props = [
            "name", "console", "aux", "console_type", "console_resolution",
            "console_http_port", "console_http_path", "start_command",
            "environment", "adapters"
        ]

        changed = False
        for prop in props:
            if prop in request.json and request.json[prop] != getattr(container, prop):
                setattr(container, prop, request.json[prop])
                changed = True
        # We don't call container.update for nothing because it will restart the container
        if changed:
            yield from container.update()
        container.updated()
        response.json(container)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:21,代码来源:docker_handler.py

示例10: create

    def create(request, response):
        docker_manager = Docker.instance()
        container = yield from docker_manager.create_node(request.json.pop("name"),
                                                          request.match_info["project_id"],
                                                          request.json.get("node_id"),
                                                          image=request.json.pop("image"),
                                                          start_command=request.json.get("start_command"),
                                                          environment=request.json.get("environment"),
                                                          adapters=request.json.get("adapters"),
                                                          console=request.json.get("console"),
                                                          console_type=request.json.get("console_type"),
                                                          console_resolution=request.json.get("console_resolution", "1024x768"),
                                                          console_http_port=request.json.get("console_http_port", 80),
                                                          console_http_path=request.json.get("console_http_path", "/"),
                                                          aux=request.json.get("aux"))
        for name, value in request.json.items():
            if name != "node_id":
                if hasattr(container, name) and getattr(container, name) != value:
                    setattr(container, name, value)

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

示例11: test_list_images

def test_list_images(loop):
    response = [
        {
            "RepoTags": [
                "ubuntu:12.04",
                "ubuntu:precise",
                "ubuntu:latest"
            ],
            "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
            "Created": 1365714795,
            "Size": 131506275,
            "VirtualSize": 131506275
        },
        {
            "RepoTags": [
                "ubuntu:12.10",
                "ubuntu:quantal",
                "<none>:<none>"
            ],
            "ParentId": "27cf784147099545",
            "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
            "Created": 1364102658,
            "Size": 24653,
            "VirtualSize": 180116135
        }
    ]

    with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
        images = loop.run_until_complete(asyncio.ensure_future(Docker.instance().list_images()))
        mock.assert_called_with("GET", "images/json", params={"all": 0})
    assert len(images) == 5
    assert {"image": "ubuntu:12.04"} in images
    assert {"image": "ubuntu:precise"} in images
    assert {"image": "ubuntu:latest"} in images
    assert {"image": "ubuntu:12.10"} in images
    assert {"image": "ubuntu:quantal"} in images
开发者ID:GNS3,项目名称:gns3-server,代码行数:36,代码来源:test_docker.py

示例12: delete_nio

 def delete_nio(request, response):
     docker_manager = Docker.instance()
     container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
     yield from container.adapter_remove_nio_binding(int(request.match_info["adapter_number"]))
     response.set_status(204)
开发者ID:AJNOURI,项目名称:gns3-server,代码行数:5,代码来源:docker_handler.py

示例13: vm

def vm():
    vm = Docker()
    vm._connected = True
    vm._session = MagicMock()
    vm._session.closed = False
    return vm
开发者ID:GNS3,项目名称:gns3-server,代码行数:6,代码来源:test_docker.py

示例14: show

 async def show(request, response):
     docker_manager = Docker.instance()
     images = await docker_manager.list_images()
     response.json(images)
开发者ID:GNS3,项目名称:gns3-server,代码行数:4,代码来源:docker_handler.py

示例15: unpause

 async def unpause(request, response):
     docker_manager = Docker.instance()
     container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
     await container.unpause()
     response.set_status(204)
开发者ID:GNS3,项目名称:gns3-server,代码行数:5,代码来源:docker_handler.py


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