本文整理汇总了Python中gns3server.compute.docker.Docker.instance方法的典型用法代码示例。如果您正苦于以下问题:Python Docker.instance方法的具体用法?Python Docker.instance怎么用?Python Docker.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gns3server.compute.docker.Docker
的用法示例。
在下文中一共展示了Docker.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop_capture
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例2: test_pull_image
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例3: stream_pcap_file
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例4: start_capture
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)})
示例5: duplicate
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例6: create_nio
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例7: update_nio
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例8: update_nio
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例9: update
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例10: create
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例11: test_list_images
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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
示例12: show
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
def show(request, response):
docker_manager = Docker.instance()
images = yield from docker_manager.list_images()
response.json(images)
示例13: delete_nio
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
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)
示例14: manager
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
def manager(port_manager):
m = Docker.instance()
m.port_manager = port_manager
return m
示例15: show
# 需要导入模块: from gns3server.compute.docker import Docker [as 别名]
# 或者: from gns3server.compute.docker.Docker import instance [as 别名]
async def show(request, response):
docker_manager = Docker.instance()
images = await docker_manager.list_images()
response.json(images)