本文整理汇总了Python中gns3server.compute.qemu.Qemu.instance方法的典型用法代码示例。如果您正苦于以下问题:Python Qemu.instance方法的具体用法?Python Qemu.instance怎么用?Python Qemu.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gns3server.compute.qemu.Qemu
的用法示例。
在下文中一共展示了Qemu.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stream_pcap_file
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def stream_pcap_file(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
adapter_number = int(request.match_info["adapter_number"])
nio = vm.get_nio(adapter_number)
await qemu_manager.stream_pcap_file(nio, vm.project.id, request, response)
示例2: delete_nio
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def delete_nio(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
adapter_number = int(request.match_info["adapter_number"])
await vm.adapter_remove_nio_binding(adapter_number)
response.set_status(204)
示例3: stop_capture
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def stop_capture(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
adapter_number = int(request.match_info["adapter_number"])
await vm.stop_capture(adapter_number)
response.set_status(204)
示例4: test_create_image_abs_path
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def test_create_image_abs_path(loop, tmpdir, fake_qemu_img_binary):
options = {
"format": "qcow2",
"preallocation": "metadata",
"cluster_size": 64,
"refcount_bits": 12,
"lazy_refcounts": "off",
"size": 100
}
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, str(tmpdir / "hda.qcow2"), options)))
args, kwargs = process.call_args
assert args == (
fake_qemu_img_binary,
"create",
"-f",
"qcow2",
"-o",
"cluster_size=64",
"-o",
"lazy_refcounts=off",
"-o",
"preallocation=metadata",
"-o",
"refcount_bits=12",
str(tmpdir / "hda.qcow2"),
"100M"
)
示例5: start_capture
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def start_capture(request, response):
qemu_manager = Qemu.instance()
vm = qemu_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(vm.project.capture_working_directory(), request.json["capture_file_name"])
await vm.start_capture(adapter_number, pcap_file_path)
response.json({"pcap_file_path": pcap_file_path})
示例6: duplicate
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def duplicate(request, response):
new_node = yield from Qemu.instance().duplicate_node(
request.match_info["node_id"],
request.json["destination_node_id"]
)
response.set_status(201)
response.json(new_node)
示例7: update_nio
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def update_nio(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
nio = vm.ethernet_adapters[int(request.match_info["adapter_number"])]
if "filters" in request.json and nio:
nio.filters = request.json["filters"]
yield from vm.adapter_update_nio_binding(int(request.match_info["adapter_number"]), nio)
response.set_status(201)
response.json(request.json)
示例8: start
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def start(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
if sys.platform.startswith("linux") and qemu_manager.config.get_section_config("Qemu").getboolean("enable_kvm", True) and "-no-kvm" not in vm.options:
pm = ProjectManager.instance()
if pm.check_hardware_virtualization(vm) is False:
raise aiohttp.web.HTTPConflict(text="Cannot start VM with KVM enabled because hardware virtualization (VT-x/AMD-V) is already used by another software like VMware or VirtualBox")
yield from vm.start()
response.json(vm)
示例9: update
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def update(request, response):
qemu_manager = Qemu.instance()
vm = qemu_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)
示例10: download_image
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def download_image(request, response):
filename = request.match_info["filename"]
qemu_manager = Qemu.instance()
image_path = qemu_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)
示例11: create_nio
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def create_nio(request, response):
qemu_manager = Qemu.instance()
vm = qemu_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"):
raise aiohttp.web.HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
nio = qemu_manager.create_nio(request.json)
await vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
response.set_status(201)
response.json(nio)
示例12: create_img
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def create_img(request, response):
qemu_img = request.json.pop("qemu_img")
path = request.json.pop("path")
if os.path.isabs(path):
config = Config.instance()
if config.get_section_config("Server").getboolean("local", False) is False:
response.set_status(403)
return
yield from Qemu.instance().create_disk(qemu_img, path, request.json)
response.set_status(201)
示例13: test_create_image_exist
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def test_create_image_exist(loop, tmpdir, fake_qemu_img_binary):
open(str(tmpdir / "hda.qcow2"), "w+").close()
options = {
"format": "raw",
"size": 100
}
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
with pytest.raises(QemuError):
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
assert not process.called
示例14: update
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
def update(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
# update the console first to avoid issue if updating console type
vm.console = request.json.pop("console", vm.console)
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)
示例15: update_nio
# 需要导入模块: from gns3server.compute.qemu import Qemu [as 别名]
# 或者: from gns3server.compute.qemu.Qemu import instance [as 别名]
async def update_nio(request, response):
qemu_manager = Qemu.instance()
vm = qemu_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
adapter_number = int(request.match_info["adapter_number"])
nio = vm.get_nio(adapter_number)
if "filters" in request.json:
nio.filters = request.json["filters"]
if "suspend" in request.json:
nio.suspend = request.json["suspend"]
await vm.adapter_update_nio_binding(adapter_number, nio)
response.set_status(201)
response.json(request.json)