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


Python Topology.project方法代码示例

本文整理汇总了Python中gns3.topology.Topology.project方法的典型用法代码示例。如果您正苦于以下问题:Python Topology.project方法的具体用法?Python Topology.project怎么用?Python Topology.project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gns3.topology.Topology的用法示例。


在下文中一共展示了Topology.project方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dump_http_auth

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_dump_http_auth(vpcs_device, project, remote_server):

    remote_server.setUser("hello")
    remote_server.setPassword("world")

    from gns3.modules.vpcs.vpcs_device import VPCSDevice
    from gns3.modules.vpcs import VPCS

    vpcs_device = VPCSDevice(VPCS(), remote_server, project)
    vpcs_device._vpcs_device_id = str(uuid.uuid4())
    vpcs_device._settings = {"name": "VPCS 1", "script_file": "", "console": None, "startup_script": None}
    vpcs_device.setInitialized(True)

    topology = Topology()
    topology.project = project
    topology.addNode(vpcs_device)

    dump = topology.dump(include_gui_data=False)
    assert dict(dump) == {
        "project_id": project.id(),
        "auto_start": False,
        "name": project.name(),
        "version": __version__,
        "revision": 4,
        "topology": {
            "nodes": [
                {
                    "description": "VPCS device",
                    "id": vpcs_device.id(),
                    "ports": [
                        {
                            "id": vpcs_device.ports()[0].id(),
                            "name": "Ethernet0",
                            "port_number": 0,
                            "adapter_number": 0
                        }
                    ],
                    "properties": {
                        "name": vpcs_device.name()
                    },
                    "server_id": remote_server.id(),
                    "type": "VPCSDevice",
                    "vm_id": None
                }
            ],
            "servers": [
                {
                    "vm": False,
                    "host": "127.0.0.1",
                    "id": remote_server.id(),
                    "local": False,
                    "port": 8001,
                    "protocol": "http",
                    "ram_limit": 0,
                    "user": "hello"
                }
            ]
        },
        "type": "topology"
    }
开发者ID:an0202,项目名称:gns3-gui,代码行数:62,代码来源:test_topology.py

示例2: test_randomize_id

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_randomize_id(project, tmpdir):
    project.setTopologyFile(str(tmpdir / "test.gns3"))

    project_uuid = str(uuid.uuid4())
    vm_uuid1 = str(uuid.uuid4())
    os.makedirs(str(tmpdir / "project-files" / "vpcs" / vm_uuid1))
    open(str(tmpdir / "project-files" / "vpcs" / vm_uuid1 / "test.log"), "w+").close()
    vm_uuid2 = str(uuid.uuid4())
    orig_topology = {
        "project_id": project_uuid,
        "topology": {
            "nodes": [
                {
                    "vm_id": vm_uuid1,
                },
                {
                    "vm_id": vm_uuid2
                }
            ]
        }
    }
    topology = Topology()
    topology.project = project
    top = topology._randomize_id(orig_topology)
    assert top["project_id"] != project_uuid
    assert top["topology"]["nodes"][0]["vm_id"] != vm_uuid1

    assert not os.path.exists(str(tmpdir / "project-files" / "vpcs" / vm_uuid1 / "test.log"))
    assert os.path.exists(str(tmpdir / "project-files" / "vpcs" / top["topology"]["nodes"][0]["vm_id"] / "test.log"))

    assert top["topology"]["nodes"][1]["vm_id"] != vm_uuid2
    assert top["topology"]["nodes"][0]["vm_id"] != top["topology"]["nodes"][1]["vm_id"]
开发者ID:an0202,项目名称:gns3-gui,代码行数:34,代码来源:test_topology.py

示例3: test_image_in_project

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_image_in_project(tmpdir):
    project_dir = tmpdir / "project" / "project-files"
    os.makedirs(str(project_dir / "images"))

    project = Project()
    project.setFilesDir(str(tmpdir / "project"))

    topology = Topology()
    topology.project = project

    with open(str(project_dir / "images" / "1.jpg"), "w+") as f:
        f.write("AA")

    image1 = PixmapImageItem(None, "images/1.jpg")
    topology.addImage(image1)
    assert image1 in topology._images

    image2 = PixmapImageItem(None, "images/1.jpg")
    topology.addImage(image2)
    assert image1 in topology._images
    assert image2 in topology._images

    topology.removeImage(image2)
    assert os.path.exists(str(project_dir / "images" / "1.jpg"))

    # If not image use this file delete it
    topology.removeImage(image1)
    assert not os.path.exists(str(project_dir / "images" / "1.jpg"))
开发者ID:GMarciales,项目名称:gns3-gui,代码行数:30,代码来源:test_topology.py

示例4: test_dump_random_id

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_dump_random_id(vpcs_device, project, local_server):
    topology = Topology()
    topology.project = project
    topology.addNode(vpcs_device)

    fake_uuid = str(uuid.uuid4())
    with patch("uuid.uuid4", return_value=fake_uuid):
        dump = topology.dump(include_gui_data=False, random_id=True)
        assert dict(dump) == {
            "project_id": fake_uuid,
            "auto_start": False,
            "name": project.name(),
            "version": __version__,
            "revision": 4,
            "topology": {
                "nodes": [
                    {
                        "id": vpcs_device.id(),
                        "description": "VPCS device",
                        "ports": [
                            {
                                "id": vpcs_device.ports()[0].id(),
                                "name": "Ethernet0",
                                "port_number": 0,
                                "adapter_number": 0
                            }
                        ],
                        "properties": {
                            "name": vpcs_device.name()
                        },
                        "server_id": local_server.id(),
                        "type": "VPCSDevice",
                        "vm_id": fake_uuid}
                ],
                "servers": [
                    {
                        "host": "127.0.0.1",
                        "id": local_server.id(),
                        "local": True,
                        "port": 8000,
                        "protocol": "http",
                        "ram_limit": 0,
                        "vm": False
                    }
                ]
            },
            "type": "topology"
        }
开发者ID:an0202,项目名称:gns3-gui,代码行数:50,代码来源:test_topology.py

示例5: test_dump

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_dump(vpcs_device, project, local_server):
    topology = Topology()
    topology.project = project
    topology.addNode(vpcs_device)

    dump = topology.dump(include_gui_data=False)
    assert dict(dump) == {
        "project_id": project.id(),
        "auto_start": False,
        "name": project.name(),
        "version": __version__,
        "revision": 4,
        "topology": {
            "nodes": [
                {
                    "description": "VPCS device",
                    "id": vpcs_device.id(),
                    "ports": [
                        {
                            "id": vpcs_device.ports()[0].id(),
                            "name": "Ethernet0",
                            "port_number": 0,
                            "adapter_number": 0
                        }
                    ],
                    "properties": {
                        "name": vpcs_device.name()
                    },
                    "server_id": local_server.id(),
                    "type": "VPCSDevice",
                    "vm_id": None
                }
            ],
            "servers": [
                {
                    "vm": False,
                    "host": "127.0.0.1",
                    "id": local_server.id(),
                    "local": True,
                    "port": 8000,
                    "protocol": "http",
                    "ram_limit": 0
                }
            ]
        },
        "type": "topology"
    }
开发者ID:an0202,项目名称:gns3-gui,代码行数:49,代码来源:test_topology.py

示例6: test_image_outside_project

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_image_outside_project(tmpdir):
    """
    By security we do not delete image outside project.
    This should not append but if someone reuse the image items for
    something else.
    """

    project_img_dir = tmpdir / "project" / "project-files" / "images"
    os.makedirs(str(project_img_dir))

    project = Project()
    project.setFilesDir(str(tmpdir / "project"))

    topology = Topology()
    topology.project = project

    with open(str(tmpdir / "1.jpg"), "w+") as f:
        f.write("AA")

    image1 = PixmapImageItem(None, str(tmpdir / "1.jpg"))
    topology.addImage(image1)
    assert image1 in topology._images
    topology.removeImage(image1)
    assert os.path.exists(str(tmpdir / "1.jpg"))
开发者ID:GMarciales,项目名称:gns3-gui,代码行数:26,代码来源:test_topology.py

示例7: test_load_1_2_topology

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_load_1_2_topology(project, monkeypatch, main_window, tmpdir):

    topo = {
        "auto_start": False,
        "name": "twovpcs",
        "topology": {
            "links": [
                {
                    "description": "Link from VPCS 1 port Ethernet0 to VPCS 2 port Ethernet0",
                    "destination_node_id": 2,
                    "destination_port_id": 2,
                    "id": 1,
                    "source_node_id": 1,
                    "source_port_id": 1
                }
            ],
            "nodes": [
                {
                    "description": "VPCS device",
                    "id": 1,
                    "label": {
                        "color": "#000000",
                        "font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
                        "text": "VPCS 1",
                        "x": 10.75,
                        "y": -25.0
                    },
                    "ports": [
                        {
                            "description": "connected to VPCS 2 on port Ethernet0",
                            "id": 1,
                            "link_id": 1,
                            "name": "Ethernet0",
                            "nio": "NIO_UDP",
                            "port_number": 0
                        }
                    ],
                    "properties": {
                        "console": 4501,
                        "name": "VPCS 1",
                        "script_file": "startup.vpc"
                    },
                    "server_id": 1,
                    "type": "VPCSDevice",
                    "vpcs_id": 1,
                    "x": -349.5,
                    "y": -206.5
                },
                {
                    "description": "VPCS device",
                    "id": 2,
                    "label": {
                        "color": "#000000",
                        "font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
                        "text": "VPCS 2",
                        "x": 10.75,
                        "y": -25.0
                    },
                    "ports": [
                        {
                            "description": "connected to VPCS 1 on port Ethernet0",
                            "id": 2,
                            "link_id": 1,
                            "name": "Ethernet0",
                            "nio": "NIO_UDP",
                            "port_number": 0
                        }
                    ],
                    "properties": {
                        "console": 4502,
                        "name": "VPCS 2",
                        "script_file": "startup.vpc"
                    },
                    "server_id": 1,
                    "type": "VPCSDevice",
                    "vpcs_id": 2,
                    "x": 69.5,
                    "y": -190.5
                }
            ],
            "servers": [
                {
                    "cloud": False,
                    "host": "127.0.0.1",
                    "id": 1,
                    "local": True,
                    "port": 8000
                }
            ]
        },
        "type": "topology",
        "version": "1.2.3"
    }

    monkeypatch.setattr('gns3.main_window.MainWindow.instance', lambda: main_window)

    project_call = 0
    # We return an uuid for each HTTP post

    def http_loader(self, method, path, callback, body={}, **kwargs):
#.........这里部分代码省略.........
开发者ID:an0202,项目名称:gns3-gui,代码行数:103,代码来源:test_topology.py

示例8: test_load

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import project [as 别名]
def test_load(project, monkeypatch, main_window, tmpdir):

    topo = {
        "project_id": project.id(),
        "auto_start": False,
        "name": "twovpcs",
        "resources_type": "local",
        "topology": {
            "links": [
                {
                    "description": "Link from VPCS 1 port Ethernet0 to VPCS 2 port Ethernet0",
                    "destination_node_id": 2,
                    "destination_port_id": 2,
                    "id": 1,
                    "source_node_id": 1,
                    "source_port_id": 1
                }
            ],
            "nodes": [
                {
                    "description": "VPCS device",
                    "id": 1,
                    "label": {
                        "color": "#000000",
                        "font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
                        "text": "VPCS 1",
                        "x": 10.75,
                        "y": -25.0
                    },
                    "ports": [
                        {
                            "description": "connected to VPCS 2 on port Ethernet0",
                            "id": 1,
                            "link_id": 1,
                            "name": "Ethernet0",
                            "nio": "NIO_UDP",
                            "port_number": 0,
                            "adapter_number": 0
                        }
                    ],
                    "properties": {
                        "console": 4501,
                        "name": "VPCS 1",
                        "script_file": "startup.vpc"
                    },
                    "server_id": 1,
                    "type": "VPCSDevice",
                    "vpcs_id": 1,
                    "vm_id": "2b5476de-6e79-4eb5-b0eb-8c54c7821cb8",
                    "x": -349.5,
                    "y": -206.5
                },
                {
                    "description": "VPCS device",
                    "id": 2,
                    "label": {
                        "color": "#000000",
                        "font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
                        "text": "VPCS 2",
                        "x": 10.75,
                        "y": -25.0
                    },
                    "ports": [
                        {
                            "description": "connected to VPCS 1 on port Ethernet0",
                            "id": 2,
                            "link_id": 1,
                            "name": "Ethernet0",
                            "nio": "NIO_UDP",
                            "port_number": 0
                        }
                    ],
                    "properties": {
                        "console": 4502,
                        "name": "VPCS 2",
                        "script_file": "startup.vpc"
                    },
                    "server_id": 1,
                    "type": "VPCSDevice",
                    "vm_id": "2b5476de-6e79-4eb5-b0eb-8c54c7821cba",
                    "vpcs_id": 2,
                    "x": 69.5,
                    "y": -190.5
                }
            ],
            "servers": [
                {
                    "cloud": False,
                    "host": "127.0.0.1",
                    "id": 1,
                    "local": True,
                    "port": 8000
                }
            ]
        },
        "type": "topology",
        "version": "1.3.0"
    }

    monkeypatch.setattr('gns3.main_window.MainWindow.instance', lambda: main_window)
#.........这里部分代码省略.........
开发者ID:AshokVardhn,项目名称:gns3-gui,代码行数:103,代码来源:test_topology.py


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