When importing a project fix the GNS3 version

This commit is contained in:
Julien Duponchelle committed 2016-07-22 11:52:59 +02:00
1 parent 9b499dc51e
commit 94a262cd46
7 files changed
+98 -13

No files matched your search

+1 -2
View File
@@ -71,6 +71,7 @@ class Compute:
"""
def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, password=None, name=None):
self._http_session = None
assert controller is not None
log.info("Create compute %s", compute_id)
@@ -87,7 +88,6 @@ class Compute:
self._connected = False
self._controller = controller
self._set_auth(user, password)
self._http_session = None
self._version = None
self._cpu_usage_percent = None
self._memory_usage_percent = None
@@ -472,4 +472,3 @@ class Compute:
path = "/projects/{}/files".format(project.id)
res = yield from self.http_query("GET", path, timeout=120)
return res.json
+5 -4
View File
@@ -67,17 +67,19 @@ def export_project(project, temporary_dir, include_images=False):
z.write(path, os.path.relpath(path, project._path), compress_type=zipfile.ZIP_DEFLATED)
for compute in project.computes:
if compute.id == "vm":
if compute.id != "local":
compute_files = yield from compute.list_files(project)
for compute_file in compute_files:
if not _filter_files(compute_file["path"]):
(fp, temp_path) = tempfile.mkstemp(dir=temporary_dir)
(fd, temp_path) = tempfile.mkstemp(dir=temporary_dir)
f = open(fd, "wb", closefd=True)
stream = yield from compute.download_file(project, compute_file["path"])
while True:
data = yield from stream.read(512)
if not data:
break
fp.write(data)
f.write(data)
f.close()
z.write(temp_path, arcname=compute_file["path"], compress_type=zipfile.ZIP_DEFLATED)
return z
@@ -102,7 +104,6 @@ def _filter_files(path):
return False
def _export_project_file(project, path, z, include_images):
"""
Take a project file (.gns3) and patch it for the export
+7 -3
View File
@@ -24,6 +24,7 @@ import zipfile
import aiohttp
from ..config import Config
from .topology import load_topology
"""
@@ -51,15 +52,18 @@ def import_project(controller, project_id, stream):
try:
topology = json.loads(myzip.read("project.gns3").decode())
# If the project name is already used we generate a new one
topology["name"] = controller.get_free_project_name(topology["name"])
project_name = controller.get_free_project_name(topology["name"])
except KeyError:
raise aiohttp.web.HTTPConflict(text="Can't import topology the .gns3 is corrupted or missing")
path = os.path.join(projects_path, topology["name"])
path = os.path.join(projects_path, project_name)
os.makedirs(path)
myzip.extractall(path)
dot_gns3_path = os.path.join(path, topology["name"] + ".gns3")
topology = load_topology(os.path.join(path, "project.gns3"))
topology["name"] = project_name
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
with open(dot_gns3_path, "w+") as f: