mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
When importing a project fix the GNS3 version
This commit is contained in:
7 files changed
+98
-13
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -235,7 +235,6 @@ class ProjectHandler:
|
||||
controller = Controller.instance()
|
||||
project = controller.get_project(request.match_info["project_id"])
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
datas = yield from export_project(project, tmp_dir, include_images=bool(request.GET.get("include_images", "0")))
|
||||
# We need to do that now because export could failed and raise an HTTP error
|
||||
|
||||
Reference in new issue
Block a user