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


Python Project.import_zip方法代码示例

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


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

示例1: test_import_with_images

# 需要导入模块: from gns3server.modules.project import Project [as 别名]
# 或者: from gns3server.modules.project.Project import import_zip [as 别名]
def test_import_with_images(tmpdir):

    project_id = str(uuid.uuid4())
    project = Project(name="test", project_id=project_id)

    with open(str(tmpdir / "test.image"), 'w+') as f:
        f.write("B")

    zip_path = str(tmpdir / "project.zip")
    with zipfile.ZipFile(zip_path, 'w') as myzip:
        myzip.write(str(tmpdir / "test.image"), "images/IOS/test.image")

    with open(zip_path, "rb") as f:
        project.import_zip(f)

    # TEST import images
    path = os.path.join(project._config().get("images_path"), "IOS", "test.image")
    assert os.path.exists(path), path
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:20,代码来源:test_project.py

示例2: test_import

# 需要导入模块: from gns3server.modules.project import Project [as 别名]
# 或者: from gns3server.modules.project.Project import import_zip [as 别名]
def test_import(tmpdir):

    project_id = str(uuid.uuid4())
    project = Project(name="test", project_id=project_id)

    topology = {
        "project_id": str(uuid.uuid4()),
        "name": "testtest",
        "topology": {
            "nodes": [
                {
                    "server_id": 3,
                    "type": "VPCSDevice"
                },
                {
                    "server_id": 3,
                    "type": "QemuVM"
                }
            ]
        }
    }

    with open(str(tmpdir / "project.gns3"), 'w+') as f:
        json.dump(topology, f)
    with open(str(tmpdir / "b.png"), 'w+') as f:
        f.write("B")

    zip_path = str(tmpdir / "project.zip")
    with zipfile.ZipFile(zip_path, 'w') as myzip:
        myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
        myzip.write(str(tmpdir / "b.png"), "b.png")
        myzip.write(str(tmpdir / "b.png"), "project-files/dynamips/test")
        myzip.write(str(tmpdir / "b.png"), "project-files/qemu/test")

    with open(zip_path, "rb") as f:
        project.import_zip(f)

    assert os.path.exists(os.path.join(project.path, "b.png"))
    assert os.path.exists(os.path.join(project.path, "test.gns3"))
    assert os.path.exists(os.path.join(project.path, "project-files/dynamips/test"))
    assert os.path.exists(os.path.join(project.path, "servers/vm/project-files/qemu/test"))

    with open(os.path.join(project.path, "test.gns3")) as f:
        content = json.load(f)

    assert content["name"] == "test"
    assert content["project_id"] == project_id
    assert content["topology"]["servers"] == [
        {
            "id": 1,
            "local": True,
            "vm": False
        },
        {
            "id": 2,
            "local": False,
            "vm": True
        },
    ]
    assert content["topology"]["nodes"][0]["server_id"] == 1
    assert content["topology"]["nodes"][1]["server_id"] == 2
开发者ID:ravirajsdeshmukh,项目名称:gns3-server,代码行数:63,代码来源:test_project.py


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