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


Python VPCS.instance方法代碼示例

本文整理匯總了Python中gns3server.compute.vpcs.VPCS.instance方法的典型用法代碼示例。如果您正苦於以下問題:Python VPCS.instance方法的具體用法?Python VPCS.instance怎麽用?Python VPCS.instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gns3server.compute.vpcs.VPCS的用法示例。


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

示例1: stop_capture

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    def stop_capture(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        port_number = int(request.match_info["port_number"])
        yield from vm.stop_capture(port_number)
        response.set_status(204)
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:9,代碼來源:vpcs_handler.py

示例2: test_start_0_6_1

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_start_0_6_1(loop, vm, async_run):
    """
    Version 0.6.1 doesn't have the -R options. It's not require
    because GNS3 provide a patch for this.
    """
    process = MagicMock()
    process.returncode = None
    vm._vpcs_version = parse_version("0.6.1")

    with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
                nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                async_run(vm.port_add_nio_binding(0, nio))
                async_run(vm.start())
                assert mock_exec.call_args[0] == (vm._vpcs_path(),
                                                  '-p',
                                                  str(vm._internal_console_port),
                                                  '-m', '1',
                                                  '-i',
                                                  '1',
                                                  '-F',
                                                  '-s',
                                                  ANY,
                                                  '-c',
                                                  ANY,
                                                  '-t',
                                                  '127.0.0.1')
                assert vm.is_running()
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:31,代碼來源:test_vpcs_vm.py

示例3: stream_pcap_file

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    async def stream_pcap_file(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        port_number = int(request.match_info["port_number"])
        nio = vm.get_nio(port_number)
        await vpcs_manager.stream_pcap_file(nio, vm.project.id, request, response)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:9,代碼來源:vpcs_handler.py

示例4: test_stop

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_stop(loop, vm, async_run):
    process = MagicMock()

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

    with NotificationManager.instance().queue() as queue:
        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
            with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
                with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
                    nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                    async_run(vm.port_add_nio_binding(0, nio))

                    async_run(vm.start())
                    assert vm.is_running()

                    with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                        loop.run_until_complete(asyncio.async(vm.stop()))
                    assert vm.is_running() is False

                    if sys.platform.startswith("win"):
                        process.send_signal.assert_called_with(1)
                    else:
                        process.terminate.assert_called_with()

                    async_run(queue.get(0))  #  Ping
                    async_run(queue.get(0))  #  Started

                    (action, event, kwargs) = async_run(queue.get(0))
                    assert action == "node.updated"
                    assert event == vm
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:36,代碼來源:test_vpcs_vm.py

示例5: delete_nio

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    async def delete_nio(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        port_number = int(request.match_info["port_number"])
        await vm.port_remove_nio_binding(port_number)
        response.set_status(204)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:9,代碼來源:vpcs_handler.py

示例6: test_reload

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_reload(loop, vm, async_run):
    process = MagicMock()

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

    with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
                nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                async_run(vm.port_add_nio_binding(0, nio))
                async_run(vm.start())
                assert vm.is_running()

                with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
                    async_run(vm.reload())
                assert vm.is_running() is True

                if sys.platform.startswith("win"):
                    process.send_signal.assert_called_with(1)
                else:
                    process.terminate.assert_called_with()
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:27,代碼來源:test_vpcs_vm.py

示例7: test_start

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_start(loop, vm, async_run):
    process = MagicMock()
    process.returncode = None

    with NotificationManager.instance().queue() as queue:
        async_run(queue.get(0))  # Ping

        with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
            with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
                with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
                    nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
                    async_run(vm.port_add_nio_binding(0, nio))
                    loop.run_until_complete(asyncio.async(vm.start()))
                    assert mock_exec.call_args[0] == (vm._vpcs_path(),
                                                      '-p',
                                                      str(vm._internal_console_port),
                                                      '-m', '1',
                                                      '-i',
                                                      '1',
                                                      '-F',
                                                      '-R',
                                                      '-s',
                                                      ANY,
                                                      '-c',
                                                      ANY,
                                                      '-t',
                                                      '127.0.0.1')
                assert vm.is_running()
                assert vm.command_line == ' '.join(mock_exec.call_args[0])
        (action, event, kwargs) = async_run(queue.get(0))
        assert action == "node.updated"
        assert event == vm
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:34,代碼來源:test_vpcs_vm.py

示例8: update

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    def update(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        vm.name = request.json.get("name", vm.name)
        vm.console = request.json.get("console", vm.console)
        vm.updated()
        response.json(vm)
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:10,代碼來源:vpcs_handler.py

示例9: start_capture

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    def start_capture(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        port_number = int(request.match_info["port_number"])
        pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"])
        yield from vm.start_capture(port_number, pcap_file_path)
        response.json({"pcap_file_path": pcap_file_path})
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:10,代碼來源:vpcs_handler.py

示例10: create

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    def create(request, response):

        vpcs = VPCS.instance()
        vm = yield from vpcs.create_node(request.json["name"],
                                         request.match_info["project_id"],
                                         request.json.get("node_id"),
                                         console=request.json.get("console"),
                                         startup_script=request.json.get("startup_script"))
        response.set_status(201)
        response.json(vm)
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:12,代碼來源:vpcs_handler.py

示例11: test_get_mac_id_no_id_available

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_get_mac_id_no_id_available(loop, project, port_manager):
    # Cleanup the VPCS object
    VPCS._instance = None
    vpcs = VPCS.instance()
    vpcs.port_manager = port_manager
    with pytest.raises(VPCSError):
        for i in range(0, 256):
            node_id = str(uuid.uuid4())
            loop.run_until_complete(vpcs.create_node("PC {}".format(i), project.id, node_id))
            assert vpcs.get_mac_id(node_id) == i
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:12,代碼來源:test_vpcs_manager.py

示例12: update_nio

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    async def update_nio(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        port_number = int(request.match_info["port_number"])
        nio = vm.get_nio(port_number)
        if "filters" in request.json:
            nio.filters = request.json["filters"]
        await vm.port_update_nio_binding(port_number, nio)
        response.set_status(201)
        response.json(request.json)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:13,代碼來源:vpcs_handler.py

示例13: create_nio

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
    def create_nio(request, response):

        vpcs_manager = VPCS.instance()
        vm = vpcs_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", "nio_tap"):
            raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
        nio = vpcs_manager.create_nio(request.json)
        yield from vm.port_add_nio_binding(int(request.match_info["port_number"]), nio)
        response.set_status(201)
        response.json(nio)
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:13,代碼來源:vpcs_handler.py

示例14: test_get_mac_id_multiple_project

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_get_mac_id_multiple_project(loop, port_manager):
    # Cleanup the VPCS object
    VPCS._instance = None
    vpcs = VPCS.instance()
    vpcs.port_manager = port_manager
    vm1_id = str(uuid.uuid4())
    vm2_id = str(uuid.uuid4())
    vm3_id = str(uuid.uuid4())
    project1 = ProjectManager.instance().create_project(project_id=str(uuid.uuid4()))
    project2 = ProjectManager.instance().create_project(project_id=str(uuid.uuid4()))
    loop.run_until_complete(vpcs.create_node("PC 1", project1.id, vm1_id))
    loop.run_until_complete(vpcs.create_node("PC 2", project1.id, vm2_id))
    loop.run_until_complete(vpcs.create_node("PC 2", project2.id, vm3_id))
    assert vpcs.get_mac_id(vm1_id) == 0
    assert vpcs.get_mac_id(vm2_id) == 1
    assert vpcs.get_mac_id(vm3_id) == 0
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:18,代碼來源:test_vpcs_manager.py

示例15: test_get_mac_id

# 需要導入模塊: from gns3server.compute.vpcs import VPCS [as 別名]
# 或者: from gns3server.compute.vpcs.VPCS import instance [as 別名]
def test_get_mac_id(loop, project, port_manager):
    # Cleanup the VPCS object
    VPCS._instance = None
    vpcs = VPCS.instance()
    vpcs.port_manager = port_manager
    vm1_id = str(uuid.uuid4())
    vm2_id = str(uuid.uuid4())
    vm3_id = str(uuid.uuid4())
    loop.run_until_complete(vpcs.create_node("PC 1", project.id, vm1_id))
    loop.run_until_complete(vpcs.create_node("PC 2", project.id, vm2_id))
    assert vpcs.get_mac_id(vm1_id) == 0
    assert vpcs.get_mac_id(vm1_id) == 0
    assert vpcs.get_mac_id(vm2_id) == 1
    loop.run_until_complete(vpcs.delete_node(vm1_id))
    loop.run_until_complete(vpcs.create_node("PC 3", project.id, vm3_id))
    assert vpcs.get_mac_id(vm3_id) == 0
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:18,代碼來源:test_vpcs_manager.py


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