mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Change the compute id to the GNS3 VM if it's not a Linux host
This commit is contained in:
parent
eff6a9154d
commit
ce557ecd23
@ -138,7 +138,6 @@ def _export_project_file(project, path, z, include_images):
|
||||
for image in images:
|
||||
_export_images(project, image, z)
|
||||
|
||||
|
||||
z.writestr("project.gns3", json.dumps(topology).encode())
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import uuid
|
||||
import shutil
|
||||
@ -63,6 +64,12 @@ def import_project(controller, project_id, stream):
|
||||
topology = load_topology(os.path.join(path, "project.gns3"))
|
||||
topology["name"] = project_name
|
||||
|
||||
# For some VM type we move them to the GNS3 VM if it's not a Linux host
|
||||
if not sys.platform.startswith("linux"):
|
||||
for node in topology["topology"]["nodes"]:
|
||||
if node["node_type"] in ("docker", "qemu", "iou"):
|
||||
node["compute_id"] = "vm"
|
||||
|
||||
dot_gns3_path = os.path.join(path, project_name + ".gns3")
|
||||
# We change the project_id to avoid erasing the project
|
||||
topology["project_id"] = project_id
|
||||
|
@ -126,3 +126,94 @@ def test_import_with_images(tmpdir, async_run, controller):
|
||||
|
||||
path = os.path.join(project._config().get("images_path"), "IOS", "test.image")
|
||||
assert os.path.exists(path), path
|
||||
|
||||
|
||||
|
||||
def test_import_iou_non_linux(linux_platform, async_run, tmpdir, controller):
|
||||
"""
|
||||
On non linux host IOU should be local
|
||||
"""
|
||||
project_id = str(uuid.uuid4())
|
||||
|
||||
topology = {
|
||||
"project_id": str(uuid.uuid4()),
|
||||
"name": "test",
|
||||
"type": "topology",
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"compute_id": "local",
|
||||
"node_type": "iou",
|
||||
"properties": {}
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"drawings": []
|
||||
},
|
||||
"revision": 5,
|
||||
"version": "2.0.0"
|
||||
}
|
||||
|
||||
with open(str(tmpdir / "project.gns3"), 'w+') as f:
|
||||
json.dump(topology, f)
|
||||
|
||||
zip_path = str(tmpdir / "project.zip")
|
||||
with zipfile.ZipFile(zip_path, 'w') as myzip:
|
||||
myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
|
||||
|
||||
with open(zip_path, "rb") as f:
|
||||
project = async_run(import_project(controller, project_id, f))
|
||||
|
||||
with open(os.path.join(project.path, "test.gns3")) as f:
|
||||
topo = json.load(f)
|
||||
assert topo["topology"]["nodes"][0]["compute_id"] == "local"
|
||||
|
||||
|
||||
|
||||
def test_import_iou_non_linux(windows_platform, async_run, tmpdir, controller):
|
||||
"""
|
||||
On non linux host IOU should be moved to the GNS3 VM
|
||||
"""
|
||||
project_id = str(uuid.uuid4())
|
||||
|
||||
topology = {
|
||||
"project_id": str(uuid.uuid4()),
|
||||
"name": "test",
|
||||
"type": "topology",
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"compute_id": "local",
|
||||
"node_type": "iou",
|
||||
"properties": {}
|
||||
},
|
||||
{
|
||||
"compute_id": "local",
|
||||
"node_type": "vpcs",
|
||||
"properties": {}
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"drawings": []
|
||||
},
|
||||
"revision": 5,
|
||||
"version": "2.0.0"
|
||||
}
|
||||
|
||||
with open(str(tmpdir / "project.gns3"), 'w+') as f:
|
||||
json.dump(topology, f)
|
||||
|
||||
zip_path = str(tmpdir / "project.zip")
|
||||
with zipfile.ZipFile(zip_path, 'w') as myzip:
|
||||
myzip.write(str(tmpdir / "project.gns3"), "project.gns3")
|
||||
|
||||
with open(zip_path, "rb") as f:
|
||||
project = async_run(import_project(controller, project_id, f))
|
||||
|
||||
with open(os.path.join(project.path, "test.gns3")) as f:
|
||||
topo = json.load(f)
|
||||
assert topo["topology"]["nodes"][0]["compute_id"] == "vm"
|
||||
assert topo["topology"]["nodes"][1]["compute_id"] == "local"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user