mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Now import project on VM work
This commit is contained in:
parent
fec3694710
commit
9bdc0b78eb
@ -305,11 +305,17 @@ class Controller:
|
||||
if base_name not in names:
|
||||
return base_name
|
||||
i = 1
|
||||
while "{}-{}".format(base_name, i) in names:
|
||||
|
||||
projects_path = self.projects_directory()
|
||||
|
||||
while True:
|
||||
new_name = "{}-{}".format(base_name, i)
|
||||
if new_name not in names and not os.path.exists(os.path.join(projects_path, new_name)):
|
||||
break
|
||||
i += 1
|
||||
if i > 1000000:
|
||||
raise aiohttp.web.HTTPConflict(text="A project name could not be allocated (node limit reached?)")
|
||||
return "{}-{}".format(base_name, i)
|
||||
return new_name
|
||||
|
||||
@property
|
||||
def projects(self):
|
||||
@ -318,6 +324,10 @@ class Controller:
|
||||
"""
|
||||
return self._projects
|
||||
|
||||
def projects_directory(self):
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
return os.path.expanduser(server_config.get("projects_path", "~/GNS3/projects"))
|
||||
|
||||
@staticmethod
|
||||
def instance():
|
||||
"""
|
||||
|
@ -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
|
||||
|
||||
|
@ -44,8 +44,7 @@ def import_project(controller, project_id, stream):
|
||||
:param gns3vm: True move Docker, IOU and Qemu to the GNS3 VM
|
||||
:returns: Project
|
||||
"""
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
projects_path = os.path.expanduser(server_config.get("projects_path", "~/GNS3/projects"))
|
||||
projects_path = controller.projects_directory()
|
||||
os.makedirs(projects_path, exist_ok=True)
|
||||
|
||||
with zipfile.ZipFile(stream) as myzip:
|
||||
@ -108,7 +107,8 @@ def _move_files_to_compute(compute, project_id, directory, files_path):
|
||||
path = os.path.join(dirpath, filename)
|
||||
dst = os.path.relpath(path, directory)
|
||||
yield from _upload_file(compute, project_id, path, dst)
|
||||
shutil.rmtree(directory)
|
||||
shutil.rmtree(os.path.join(directory, files_path))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def _upload_file(compute, project_id, file_path, path):
|
||||
@ -118,7 +118,7 @@ def _upload_file(compute, project_id, file_path, path):
|
||||
:param file_path: File path on the controller file system
|
||||
:param path: File path on the remote system relative to project directory
|
||||
"""
|
||||
path = "/projects/{}/files/path".format(project_id, path.replace("\\", "/"))
|
||||
path = "/projects/{}/files/{}".format(project_id, path.replace("\\", "/"))
|
||||
with open(file_path, "rb") as f:
|
||||
yield from compute.http_query("POST", path, f, timeout=None)
|
||||
|
||||
|
@ -349,6 +349,7 @@ class ProjectHandler:
|
||||
response.set_status(200)
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, 'wb+') as f:
|
||||
while True:
|
||||
packet = yield from request.content.read(512)
|
||||
|
Loading…
Reference in New Issue
Block a user