當前位置: 首頁>>代碼示例>>Python>>正文


Python qemu.Qemu類代碼示例

本文整理匯總了Python中gns3server.compute.qemu.Qemu的典型用法代碼示例。如果您正苦於以下問題:Python Qemu類的具體用法?Python Qemu怎麽用?Python Qemu使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Qemu類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_kvm_archs_kvm_ok

def test_get_kvm_archs_kvm_ok(loop):

    with patch("os.path.exists", return_value=True):
        archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
        if platform.machine() == 'x86_64':
            assert archs == ['x86_64', 'i386']
        else:
            assert archs == [platform.machine()]

    with patch("os.path.exists", return_value=False):
        archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
        assert archs == []
開發者ID:athmane,項目名稱:gns3-server,代碼行數:12,代碼來源:test_qemu_manager.py

示例2: delete_nio

    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)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:7,代碼來源:qemu_handler.py

示例3: stop_capture

    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)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:7,代碼來源:qemu_handler.py

示例4: stream_pcap_file

    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)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:7,代碼來源:qemu_handler.py

示例5: test_create_image_abs_path

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"
        )
開發者ID:athmane,項目名稱:gns3-server,代碼行數:28,代碼來源:test_qemu_manager.py

示例6: start_capture

    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})
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:8,代碼來源:qemu_handler.py

示例7: duplicate

    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)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:8,代碼來源:qemu_handler.py

示例8: test_get_qemu_version

def test_get_qemu_version(loop):

    with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
        version = loop.run_until_complete(asyncio.async(Qemu.get_qemu_version("/tmp/qemu-test")))
        if sys.platform.startswith("win"):
            assert version == ""
        else:
            assert version == "2.2.0"
開發者ID:athmane,項目名稱:gns3-server,代碼行數:8,代碼來源:test_qemu_manager.py

示例9: update_nio

    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)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:10,代碼來源:qemu_handler.py

示例10: start

    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)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:10,代碼來源:qemu_handler.py

示例11: update

    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)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:11,代碼來源:qemu_handler.py

示例12: download_image

    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)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:11,代碼來源:qemu_handler.py

示例13: create_nio

    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)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:11,代碼來源:qemu_handler.py

示例14: create_img

    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)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:12,代碼來源:qemu_handler.py

示例15: test_create_image_exist

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
開發者ID:athmane,項目名稱:gns3-server,代碼行數:12,代碼來源:test_qemu_manager.py


注:本文中的gns3server.compute.qemu.Qemu類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。