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


Python qemu.Qemu类代码示例

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


在下文中一共展示了Qemu类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:DJdano5,项目名称:gns3-server,代码行数:12,代码来源:test_qemu_manager.py

示例2: 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:DJdano5,项目名称:gns3-server,代码行数:28,代码来源:test_qemu_manager.py

示例3: test_binary_list

def test_binary_list(loop):

    files_to_create = ["qemu-system-x86", "qemu-system-x42", "qemu-kvm", "hello"]

    for file_to_create in files_to_create:
        path = os.path.join(os.environ["PATH"], file_to_create)
        with open(path, "w+") as f:
            f.write("1")
        os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

    with asyncio_patch(
        "gns3server.modules.qemu.subprocess_check_output",
        return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard",
    ) as mock:
        qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list()))

        if sys.platform.startswith("win"):
            version = ""
        else:
            version = "2.2.0"

        assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
        assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} in qemus
        assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} in qemus
        assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
开发者ID:astoffel,项目名称:gns3-server,代码行数:25,代码来源:test_qemu_manager.py

示例4: test_get_qemu_version

def test_get_qemu_version(loop):

    with asyncio_patch("gns3server.modules.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:DJdano5,项目名称:gns3-server,代码行数:8,代码来源:test_qemu_manager.py

示例5: 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.modules.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:DJdano5,项目名称:gns3-server,代码行数:12,代码来源:test_qemu_manager.py

示例6: test_stop

def test_stop(loop, vm, running_subprocess_mock):
    process = running_subprocess_mock

    # Wait process kill success
    future = asyncio.Future()
    future.set_result(True)
    process.wait.return_value = future

    with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
        nio = Qemu.instance().create_nio(vm.qemu_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
        vm.adapter_add_nio_binding(0, nio)
        loop.run_until_complete(asyncio.async(vm.start()))
        assert vm.is_running()
        loop.run_until_complete(asyncio.async(vm.stop()))
        assert vm.is_running() is False
        process.terminate.assert_called_with()
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:16,代码来源:test_qemu_vm.py

示例7: test_create_image_relative_path

def test_create_image_relative_path(loop, tmpdir, fake_qemu_img_binary):
    options = {
        "format": "raw",
        "size": 100
    }
    with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
        with patch("gns3server.modules.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
            loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
            args, kwargs = process.call_args
            assert args == (
                fake_qemu_img_binary,
                "create",
                "-f",
                "raw",
                str(tmpdir / "hda.qcow2"),
                "100M"
            )
开发者ID:DJdano5,项目名称:gns3-server,代码行数:17,代码来源:test_qemu_manager.py

示例8: manager

def manager(port_manager):
    m = Qemu.instance()
    m.port_manager = port_manager
    return m
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:4,代码来源:test_qemu_vm.py

示例9: test_port_remove_nio_binding

def test_port_remove_nio_binding(vm, loop):
    nio = Qemu.instance().create_nio(vm.qemu_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
    loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
    loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
    assert vm._ethernet_adapters[0].ports[0] is None
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:5,代码来源:test_qemu_vm.py

示例10: test_add_nio_binding_ethernet

def test_add_nio_binding_ethernet(vm, loop, ethernet_device):
    with patch("gns3server.modules.base_manager.BaseManager.has_privileged_access", return_value=True):
        nio = Qemu.instance().create_nio(vm.qemu_path, {"type": "nio_generic_ethernet", "ethernet_device": ethernet_device})
        loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
        assert nio.ethernet_device == ethernet_device
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:5,代码来源:test_qemu_vm.py

示例11: test_add_nio_binding_udp

def test_add_nio_binding_udp(vm, loop):
    nio = Qemu.instance().create_nio(vm.qemu_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
    loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
    assert nio.lport == 4242
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:4,代码来源:test_qemu_vm.py

示例12: qemu

def qemu(port_manager):
    Qemu._instance = None
    qemu = Qemu.instance()
    qemu.port_manager = port_manager
    return qemu
开发者ID:DJdano5,项目名称:gns3-server,代码行数:5,代码来源:test_manager.py

示例13: test_get_legacy_vm_workdir

def test_get_legacy_vm_workdir():

    assert Qemu.get_legacy_vm_workdir(42, "bla") == "qemu/vm-42"
开发者ID:tnarnold,项目名称:gns3-server,代码行数:3,代码来源:test_qemu_manager.py

示例14: test_get_legacy_vm_workdir

def test_get_legacy_vm_workdir():

    assert Qemu.get_legacy_vm_workdir(42, "bla") == os.path.join("qemu", "vm-42")
开发者ID:DJdano5,项目名称:gns3-server,代码行数:3,代码来源:test_qemu_manager.py


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