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


Python node.Node類代碼示例

本文整理匯總了Python中gns3server.controller.node.Node的典型用法代碼示例。如果您正苦於以下問題:Python Node類的具體用法?Python Node怎麽用?Python Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: test_list_ports_adapters_cloud

def test_list_ports_adapters_cloud(project, compute):
    """
    List port using adapters properties
    """
    node = Node(project, compute, "demo",
                node_id=str(uuid.uuid4()),
                node_type="cloud")
    node.properties["ports_mapping"] = [
        {
            "interface": "eth0",
            "name": "eth0",
            "port_number": 0,
            "type": "ethernet"
        }
    ]

    assert node.__json__()["ports"] == [
        {
            "name": "eth0",
            "short_name": "eth0",
            "data_link_types": {"Ethernet": "DLT_EN10MB"},
            "port_number": 0,
            "adapter_number": 0,
            "link_type": "ethernet"
        }
    ]
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:26,代碼來源:test_node_port_name.py

示例2: test_list_ports_atm_switch

def test_list_ports_atm_switch(project, compute):
    """
    List port for atm switch
    """
    node = Node(project, compute, "demo",
                node_id=str(uuid.uuid4()),
                node_type="atm_switch")
    node.properties["mappings"] = {
        "1:0:100": "10:0:200"
    }

    assert node.__json__()["ports"] == [
        {
            "name": "1",
            "short_name": "1",
            "data_link_types": {"ATM": "DLT_ATM_RFC1483"},
            "port_number": 1,
            "adapter_number": 0,
            "link_type": "serial"
        },
        {
            "name": "10",
            "short_name": "10",
            "data_link_types": {"ATM": "DLT_ATM_RFC1483"},
            "port_number": 10,
            "adapter_number": 0,
            "link_type": "serial"
        }
    ]
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:29,代碼來源:test_node_port_name.py

示例3: test_capture

def test_capture(async_run, project):
    compute1 = MagicMock()

    node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
    node_vpcs._status = "started"
    node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
    node_iou = Node(project, compute1, "I1", node_type="iou")
    node_iou._ports = [EthernetPort("E0", 0, 3, 1)]

    link = UDPLink(project)
    link.create = AsyncioMagicMock()
    async_run(link.add_node(node_vpcs, 0, 4))
    async_run(link.add_node(node_iou, 3, 1))

    capture = async_run(link.start_capture())
    assert link.capturing

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/start_capture".format(project.id, node_vpcs.id), data={
        "capture_file_name": link.default_capture_file_name(),
        "data_link_type": "DLT_EN10MB"
    })

    capture = async_run(link.stop_capture())
    assert link.capturing is False

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/stop_capture".format(project.id, node_vpcs.id))
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:26,代碼來源:test_udp_link.py

示例4: test_update_filters

def test_update_filters(async_run, project, compute):
    node1 = Node(project, compute, "node1", node_type="qemu")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    link._project.emit_notification = MagicMock()
    project.dump = AsyncioMagicMock()
    async_run(link.add_node(node1, 0, 4))

    node2 = Node(project, compute, "node2", node_type="qemu")
    node2._ports = [EthernetPort("E0", 0, 0, 4)]
    async_run(link.add_node(node2, 0, 4))

    link.update = AsyncioMagicMock()
    assert link._created
    async_run(link.update_filters({
        "packet_loss": [10],
        "delay": [50, 10],
        "frequency_drop": [0],
        "bpf": [" \n  "]
    }))
    assert link.filters == {
        "packet_loss": [10],
        "delay": [50, 10]
    }
    assert link.update.called
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:27,代碼來源:test_link.py

示例5: test_create

def test_create(async_run, project):
    compute1 = MagicMock()
    compute2 = MagicMock()

    node1 = Node(project, compute1, "node1", node_type="vpcs")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute2, "node2", node_type="vpcs")
    node2._ports = [EthernetPort("E0", 0, 3, 1)]

    @asyncio.coroutine
    def subnet_callback(compute2):
        """
        Fake subnet callback
        """
        return ("192.168.1.1", "192.168.1.2")

    compute1.get_ip_on_same_subnet.side_effect = subnet_callback

    link = UDPLink(project)
    async_run(link.add_node(node1, 0, 4))

    @asyncio.coroutine
    def compute1_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 1024}
            return response

    @asyncio.coroutine
    def compute2_callback(path, data={}, **kwargs):
        """
        Fake server
        """
        if "/ports/udp" in path:
            response = MagicMock()
            response.json = {"udp_port": 2048}
            return response

    compute1.post.side_effect = compute1_callback
    compute1.host = "example.com"
    compute2.post.side_effect = compute2_callback
    compute2.host = "example.org"
    async_run(link.add_node(node2, 3, 1))

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
        "lport": 1024,
        "rhost": "192.168.1.2",
        "rport": 2048,
        "type": "nio_udp"
    }, timeout=120)
    compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
        "lport": 2048,
        "rhost": "192.168.1.1",
        "rport": 1024,
        "type": "nio_udp"
    }, timeout=120)
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:59,代碼來源:test_udp_link.py

示例6: test_upload_missing_image

def test_upload_missing_image(compute, controller, async_run, images_dir):
    project = Project(str(uuid.uuid4()), controller=controller)
    node = Node(project, compute, "demo",
                node_id=str(uuid.uuid4()),
                node_type="qemu",
                properties={"hda_disk_image": "linux.img"})
    open(os.path.join(images_dir, "linux.img"), 'w+').close()
    assert async_run(node._upload_missing_image("qemu", "linux.img")) is True
    compute.post.assert_called_with("/qemu/images/linux.img", data=ANY, timeout=None)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:9,代碼來源:test_node.py

示例7: test_json_serial_link

def test_json_serial_link(async_run, project, compute, link):
    node1 = Node(project, compute, "node1", node_type="qemu")
    node1._ports = [SerialPort("S0", 0, 0, 4)]
    node2 = Node(project, compute, "node2", node_type="qemu")
    node2._ports = [SerialPort("S0", 0, 1, 3)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    async_run(link.add_node(node1, 0, 4))
    async_run(link.add_node(node2, 1, 3))
    assert link.__json__()["link_type"] == "serial"
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:11,代碼來源:test_link.py

示例8: test_default_capture_file_name

def test_default_capture_file_name(project, compute, async_run):
    node1 = Node(project, compute, "[email protected]", node_type="qemu")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute, "w0.rld", node_type="qemu")
    node2._ports = [EthernetPort("E0", 0, 1, 3)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    async_run(link.add_node(node1, 0, 4))
    async_run(link.add_node(node2, 1, 3))
    assert link.default_capture_file_name() == "Hello_0-4_to_w0rld_1-3.pcap"
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:11,代碼來源:test_link.py

示例9: link

def link(async_run, project, compute):
    node1 = Node(project, compute, "node1", node_type="qemu")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute, "node2", node_type="qemu")
    node2._ports = [EthernetPort("E0", 0, 1, 3)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    async_run(link.add_node(node1, 0, 4))
    async_run(link.add_node(node2, 1, 3))
    return link
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:11,代碼來源:test_link.py

示例10: test_add_node_cloud

def test_add_node_cloud(async_run, project, compute):
    node1 = Node(project, compute, "node1", node_type="qemu")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute, "node2", node_type="cloud")
    node2._ports = [EthernetPort("E0", 0, 0, 4)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    link._project.controller.notification.emit = MagicMock()

    async_run(link.add_node(node1, 0, 4))
    async_run(link.add_node(node2, 0, 4))
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:12,代碼來源:test_link.py

示例11: test_start_iou

def test_start_iou(compute, project, async_run, controller):
    node = Node(project, compute, "demo",
                node_id=str(uuid.uuid4()),
                node_type="iou")
    compute.post = AsyncioMagicMock()

    # Without licence configured it should raise an error
    #with pytest.raises(aiohttp.web.HTTPConflict):
    #    async_run(node.start())

    controller._iou_license_settings = {"license_check": True, "iourc_content": "aa"}
    async_run(node.start())
    compute.post.assert_called_with("/projects/{}/iou/nodes/{}/start".format(node.project.id, node.id), timeout=240, data={"license_check": True, "iourc_content": "aa"})
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:13,代碼來源:test_node.py

示例12: test_add_node_same_node

def test_add_node_same_node(async_run, project, compute):
    """
    Connection to the same node is not allowed
    """
    node1 = Node(project, compute, "node1", node_type="qemu")
    node1._ports = [EthernetPort("E0", 0, 0, 4), EthernetPort("E1", 0, 0, 5)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    link._project.controller.notification.emit = MagicMock()

    async_run(link.add_node(node1, 0, 4))
    with pytest.raises(aiohttp.web.HTTPConflict):
        async_run(link.add_node(node1, 0, 5))
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:14,代碼來源:test_link.py

示例13: test_available_filters

def test_available_filters(async_run, project, compute):
    node1 = Node(project, compute, "node1", node_type="ethernet_switch")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    assert link.available_filters() == []

    # Ethernet switch is not supported should return 0 filters
    async_run(link.add_node(node1, 0, 4))
    assert link.available_filters() == []

    node2 = Node(project, compute, "node2", node_type="vpcs")
    node2._ports = [EthernetPort("E0", 0, 0, 4)]
    async_run(link.add_node(node2, 0, 4))
    assert len(link.available_filters()) > 0
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:16,代碼來源:test_link.py

示例14: test_add_node_serial_to_ethernet

def test_add_node_serial_to_ethernet(async_run, project, compute):
    """
    Serial to ethernet connection is not allowed
    """
    node1 = Node(project, compute, "node1", node_type="qemu")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute, "node2", node_type="qemu")
    node2._ports = [SerialPort("E0", 0, 0, 4)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    link._project.controller.notification.emit = MagicMock()

    async_run(link.add_node(node1, 0, 4))
    with pytest.raises(aiohttp.web.HTTPConflict):
        async_run(link.add_node(node2, 0, 4))
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:16,代碼來源:test_link.py

示例15: test_add_node_cloud_to_cloud

def test_add_node_cloud_to_cloud(async_run, project, compute):
    """
    Cloud to cloud connection is not allowed
    """
    node1 = Node(project, compute, "node1", node_type="cloud")
    node1._ports = [EthernetPort("E0", 0, 0, 4)]
    node2 = Node(project, compute, "node2", node_type="cloud")
    node2._ports = [EthernetPort("E0", 0, 0, 4)]

    link = Link(project)
    link.create = AsyncioMagicMock()
    link._project.emit_notification = MagicMock()

    async_run(link.add_node(node1, 0, 4))
    with pytest.raises(aiohttp.web.HTTPConflict):
        async_run(link.add_node(node2, 0, 4))
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:16,代碼來源:test_link.py


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