1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Strip computes info at project export

This commit is contained in:
Julien Duponchelle 2016-07-22 13:39:57 +02:00
parent e6831c25e2
commit eff6a9154d
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 32 additions and 1 deletions

View File

@ -123,6 +123,8 @@ def _export_project_file(project, path, z, include_images):
if node["node_type"] in ["virtualbox", "vmware", "cloud"]:
raise aiohttp.web.HTTPConflict(text="Topology with a {} could not be exported".format(node["node_type"]))
node["compute_id"] = "local" # To make project portable all node by default run on local
if "properties" in node and node["node_type"] != "Docker":
for prop, value in node["properties"].items():
if prop.endswith("image"):
@ -130,8 +132,13 @@ def _export_project_file(project, path, z, include_images):
if include_images is True:
images.add(value)
if "topology" in topology:
topology["topology"]["computes"] = [] # Strip compute informations because could contain secret info like password
for image in images:
_export_images(project, image, z)
z.writestr("project.gns3", json.dumps(topology).encode())

View File

@ -64,7 +64,26 @@ def test_export(tmpdir, project, async_run):
# The .gns3 should be renamed project.gns3 in order to simplify import
with open(os.path.join(path, "test.gns3"), 'w+') as f:
f.write("{}")
data = {
"topology": {
"computes": [
{
"compute_id": "6b7149c8-7d6e-4ca0-ab6b-daa8ab567be0",
"host": "127.0.0.1",
"name": "Remote 1",
"port": 8001,
"protocol": "http"
}
],
"nodes": [
{
"compute_id": "6b7149c8-7d6e-4ca0-ab6b-daa8ab567be0",
"node_type": "vpcs"
}
]
}
}
json.dump(data, f)
with open(os.path.join(path, "vm-1", "dynamips", "test"), 'w+') as f:
f.write("HELLO")
@ -90,6 +109,11 @@ def test_export(tmpdir, project, async_run):
assert 'project-files/snapshots/test' not in myzip.namelist()
assert 'vm-1/dynamips/test_log.txt' not in myzip.namelist()
with myzip.open("project.gns3") as myfile:
topo = json.loads(myfile.read().decode())["topology"]
assert topo["nodes"][0]["compute_id"] == "local" # All node should have compute_id local after export
assert topo["computes"] == []
def test_export_vm(tmpdir, project, async_run, controller):
"""