本文整理汇总了Python中gns3server.modules.vpcs.VPCS类的典型用法代码示例。如果您正苦于以下问题:Python VPCS类的具体用法?Python VPCS怎么用?Python VPCS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VPCS类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_start_0_6_1
def test_start_0_6_1(loop, vm):
"""
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
queue = vm.project.get_listen_queue()
vm._vpcs_version = parse_version("0.6.1")
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
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.console),
'-m', '1',
'-i',
'1',
'-F',
'-s',
'4242',
'-c',
'4243',
'-t',
'127.0.0.1')
assert vm.is_running()
(action, event) = queue.get_nowait()
assert action == "vm.started"
assert event == vm
示例2: test_port_remove_nio_binding
def test_port_remove_nio_binding(vm):
nio = VPCS.instance().create_nio(
vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}
)
vm.port_add_nio_binding(0, nio)
vm.port_remove_nio_binding(0)
assert vm._ethernet_adapter.ports[0] is None
示例3: test_start
def test_start(loop, vm):
process = MagicMock()
process.returncode = None
queue = vm.project.get_listen_queue()
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
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.console),
'-m', '1',
'-i',
'1',
'-F',
'-R',
'-s',
'4242',
'-c',
'4243',
'-t',
'127.0.0.1')
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
(action, event) = queue.get_nowait()
assert action == "vm.started"
assert event == vm
示例4: test_stop
def test_stop(loop, vm):
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.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(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()
示例5: test_start
def test_start(loop, vm):
process = MagicMock()
process.returncode = None
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.is_running()
示例6: test_get_mac_id_no_id_available
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):
vm_id = str(uuid.uuid4())
loop.run_until_complete(vpcs.create_vm("PC {}".format(i), project.id, vm_id))
assert vpcs.get_mac_id(vm_id) == i
示例7: test_get_mac_id
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_vm("PC 1", project.id, vm1_id))
loop.run_until_complete(vpcs.create_vm("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_vm(vm1_id))
loop.run_until_complete(vpcs.create_vm("PC 3", project.id, vm3_id))
assert vpcs.get_mac_id(vm3_id) == 0
示例8: test_get_mac_id_multiple_project
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()
project2 = ProjectManager.instance().create_project()
loop.run_until_complete(vpcs.create_vm("PC 1", project1.id, vm1_id))
loop.run_until_complete(vpcs.create_vm("PC 2", project1.id, vm2_id))
loop.run_until_complete(vpcs.create_vm("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
示例9: vpcs
def vpcs(port_manager):
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
return vpcs
示例10: manager
def manager(port_manager):
m = VPCS.instance()
m.port_manager = port_manager
return m
示例11: test_add_nio_binding_tap_no_privileged_access
def test_add_nio_binding_tap_no_privileged_access(vm):
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=False):
with pytest.raises(aiohttp.web.HTTPForbidden):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": "test"})
vm.port_add_nio_binding(0, nio)
assert vm._ethernet_adapter.ports[0] is None
示例12: test_add_nio_binding_tap
def test_add_nio_binding_tap(vm):
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=True):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_tap", "tap_device": "test"})
vm.port_add_nio_binding(0, nio)
assert nio.tap_device == "test"
示例13: test_add_nio_binding_udp
def test_add_nio_binding_udp(vm):
nio = VPCS.instance().create_nio(vm.vpcs_path, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
assert nio.lport == 4242