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


Python topology.Topology类代码示例

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


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

示例1: test_randomize_id

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,代码行数:32,代码来源:test_topology.py

示例2: test_image_in_project

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,代码行数:28,代码来源:test_topology.py

示例3: test_dump_http_auth

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,代码行数:60,代码来源:test_topology.py

示例4: _idlePCFinderSlot

 def _idlePCFinderSlot(self):
     """
     Slot for the idle-PC finder.
     """
     if Topology.instance().project() is None:
         project = Topology.instance().createLoadProject({"project_name": str(uuid.uuid4())})
         project.project_updated_signal.connect(self._projectCreatedSlot)
     else:
         self._projectCreatedSlot()
开发者ID:maherja,项目名称:gns3-gui,代码行数:9,代码来源:ios_router_wizard.py

示例5: _projectClosedCallback

    def _projectClosedCallback(self, result, error=False, server=None, **kwargs):

        # Status 404 could be when someone else already closed the project
        if error and "status" in result and result["status"] != 404:
            log.error("Error while closing project {}: {}".format(self._id, result["message"]))
        else:
            self.stopListenNotifications()
            log.debug("Project {} closed".format(self._id))

        self._closed = True
        self.project_closed_signal.emit()
        Topology.instance().setProject(None)
开发者ID:athmane,项目名称:gns3-gui,代码行数:12,代码来源:project.py

示例6: test_createDrawing_text

def test_createDrawing_text():
    topology = Topology()
    shape_data = {
        "x": 42,
        "y": 12,
        "z": 0,
        "rotation": 0,
        "drawing_id": str(uuid.uuid4()),
        "svg": "<svg height=\"105.0\" width=\"158.0\"><text/></svg>",
    }
    topology._main_window = MagicMock()
    topology.createDrawing(shape_data)
    topology._main_window.uiGraphicsView.createDrawingItem.assert_called_with("text", 42, 12, 0, rotation=0, svg=shape_data["svg"], drawing_id=shape_data["drawing_id"])
开发者ID:athmane,项目名称:gns3-gui,代码行数:13,代码来源:test_topology.py

示例7: test_createDrawing_ellipse

def test_createDrawing_ellipse():
    topology = Topology()
    shape_data = {
        "x": 42,
        "y": 12,
        "z": 0,
        "rotation": 0,
        "drawing_id": str(uuid.uuid4()),
        "svg": "<svg height=\"105.0\" width=\"158.0\"><ellipse cx=\"79\" cy=\"52\" rx=\"79\" ry=\"53\" style=\"stroke-width:2;stroke:#000000;fill:#ffffff;\" /></svg>",
    }
    topology._main_window = MagicMock()
    topology.createDrawing(shape_data)
    topology._main_window.uiGraphicsView.createDrawingItem.assert_called_with("ellipse", 42, 12, 0, rotation=0, svg=shape_data["svg"], drawing_id=shape_data["drawing_id"])
开发者ID:athmane,项目名称:gns3-gui,代码行数:13,代码来源:test_topology.py

示例8: test_topology_node

def test_topology_node(vpcs_device):
    topology = Topology()
    topology.addNode(vpcs_device)
    assert len(topology.nodes()) == 1
    assert topology.getNode(vpcs_device.id()) == vpcs_device
    topology.removeNode(vpcs_device)
    assert len(topology.nodes()) == 0
开发者ID:an0202,项目名称:gns3-gui,代码行数:7,代码来源:test_topology.py

示例9: test_dump_random_id

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,代码行数:48,代码来源:test_topology.py

示例10: _event_received

    def _event_received(self, result, server=None, **kwargs):

        log.debug("Event received: %s", result)
        if result["action"] in ["vm.started", "vm.stopped"]:
            vm = Topology.instance().getVM(result["event"]["vm_id"])
            if vm is not None:
                if result["action"] == "vm.started":
                    vm.setStatus(Node.started)
                    vm.started_signal.emit()
                elif result["action"] == "vm.stopped":
                    vm.setStatus(Node.stopped)
                    vm.stopped_signal.emit()
        elif result["action"] == "log.error":
            log.error(result["event"]["message"])
            print("Error: " + result["event"]["message"])
        elif result["action"] == "log.warning":
            log.warning(result["event"]["message"])
            print("Warning: " + result["event"]["message"])
        elif result["action"] == "log.info":
            log.info(result["event"]["message"])
            print("Info: " + result["event"]["message"])
        elif result["action"] == "ping":
            # Compatible with 1.4.0 server
            if "event" in result:
                server.setSystemUsage(result["event"])
开发者ID:GNS3,项目名称:gns3-gui,代码行数:25,代码来源:project.py

示例11: test_createDrawing_svg

def test_createDrawing_svg():
    """
    If SVG is more complex we consider it as an image
    """
    topology = Topology()
    shape_data = {
        "x": 42,
        "y": 12,
        "z": 0,
        "rotation": 0,
        "drawing_id": str(uuid.uuid4()),
        "svg": "<svg height=\"105.0\" width=\"158.0\"><rect><line/></rect></svg>",
    }
    topology._main_window = MagicMock()
    topology.createDrawing(shape_data)
    topology._main_window.uiGraphicsView.createDrawingItem.assert_called_with("image", 42, 12, 0, rotation=0, svg=shape_data["svg"], drawing_id=shape_data["drawing_id"])
开发者ID:athmane,项目名称:gns3-gui,代码行数:16,代码来源:test_topology.py

示例12: test_dump

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,代码行数:47,代码来源:test_topology.py

示例13: test_loadFile

def test_loadFile(tmpdir):
    topology = Topology()
    topo = str(tmpdir / "test" / "test.gns3")

    os.makedirs(str(tmpdir / "test"))
    with open(topo, 'w+') as f:
        f.write('{"name": "test", "type": "topology", "auto_start": false, "project_id": null, "topology": {}}')

    with patch("gns3.topology.Topology._load") as mock:
        project = Project()
        topology.loadFile(topo, project)

        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == {"name": "test", "auto_start": False, "project_id": None, "topology": {}, "type": "topology"}
        assert topology._project.filesDir() == str(tmpdir / "test")
        assert topology._project.name() == "test"
开发者ID:an0202,项目名称:gns3-gui,代码行数:17,代码来源:test_topology.py

示例14: test_loadFile

def test_loadFile(tmpdir):
    topology = Topology()
    topo = str(tmpdir / "test" / "test.gns3")

    os.makedirs(str(tmpdir / "test"))
    with open(topo, 'w+') as f:
        f.write('{"name": "test"}')

    with patch("gns3.topology.Topology._load") as mock:
        project = Project()
        topology.loadFile(topo, project)

        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == {"name": "test"}
        assert topology._project.filesDir() == str(tmpdir / "test")
        assert topology._project.name() == "test"
开发者ID:boy6585948,项目名称:gns3-gui,代码行数:17,代码来源:test_topology.py

示例15: _listNodesCallback

 def _listNodesCallback(self, result, error=False, **kwargs):
     if error:
         log.error("Error while listing project: {}".format(result["message"]))
         return
     topo = Topology.instance()
     for node in result:
         topo.createNode(node)
     self.get("/links", self._listLinksCallback)
开发者ID:athmane,项目名称:gns3-gui,代码行数:8,代码来源:project.py


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