mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 00:08:11 +00:00
Let the server know about the project name and convert old IOU projects on remote servers.
This commit is contained in:
parent
2934232afb
commit
95766fa30d
@ -37,6 +37,7 @@ class ProjectHandler:
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
p = pm.create_project(
|
||||
name=request.json.get("name"),
|
||||
path=request.json.get("path"),
|
||||
project_id=request.json.get("project_id"),
|
||||
temporary=request.json.get("temporary", False)
|
||||
@ -81,6 +82,7 @@ class ProjectHandler:
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
project.temporary = request.json.get("temporary", project.temporary)
|
||||
project.name = request.json.get("name", project.name)
|
||||
project_path = request.json.get("path", project.path)
|
||||
if project_path != project.path:
|
||||
project.path = project_path
|
||||
|
@ -162,8 +162,7 @@ class BaseManager:
|
||||
"""
|
||||
|
||||
new_id = str(uuid4())
|
||||
project_name = os.path.basename(project.path)
|
||||
legacy_project_files_path = os.path.join(project.path, "{}-files".format(project_name))
|
||||
legacy_project_files_path = os.path.join(project.path, "{}-files".format(project.name))
|
||||
new_project_files_path = os.path.join(project.path, "project-files")
|
||||
if os.path.exists(legacy_project_files_path) and not os.path.exists(new_project_files_path):
|
||||
# move the project files
|
||||
@ -175,16 +174,18 @@ class BaseManager:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not move project files directory: {} to {} {}".format(legacy_project_files_path,
|
||||
new_project_files_path, e))
|
||||
|
||||
legacy_iou_dir = os.path.join(project.path, "iou")
|
||||
new_iou_dir = os.path.join(project.path, "project-files", "iou")
|
||||
if os.path.exists(legacy_iou_dir) and not os.path.exists(new_iou_dir):
|
||||
# move the iou dir on remote server
|
||||
try:
|
||||
log.info('Moving "{}" to "{}"'.format(legacy_iou_dir, new_iou_dir))
|
||||
yield from wait_run_in_executor(shutil.move, legacy_iou_dir, new_iou_dir)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not move IOU directory: {} to {} {}".format(legacy_iou_dir,
|
||||
new_iou_dir, e))
|
||||
if project.is_local() is False:
|
||||
legacy_remote_iou_project = os.path.join(project.location, project.name, "iou")
|
||||
new_iou_project_path = os.path.join(project.path, "project-files", "iou")
|
||||
if os.path.exists(legacy_remote_iou_project) and not os.path.exists(new_iou_project_path):
|
||||
# move the legacy remote IOU project (remote servers only)
|
||||
log.info("Converting old remote IOU project...")
|
||||
try:
|
||||
log.info('Moving "{}" to "{}"'.format(legacy_remote_iou_project, new_iou_project_path))
|
||||
yield from wait_run_in_executor(shutil.move, legacy_remote_iou_project, new_iou_project_path)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not move IOU directory: {} to {} {}".format(legacy_remote_iou_project,
|
||||
new_iou_project_path, e))
|
||||
|
||||
if hasattr(self, "get_legacy_vm_workdir"):
|
||||
# rename old project VM working dir
|
||||
|
@ -41,8 +41,9 @@ class Project:
|
||||
:param temporary: Boolean the project is a temporary project (destroy when closed)
|
||||
"""
|
||||
|
||||
def __init__(self, project_id=None, path=None, location=None, temporary=False):
|
||||
def __init__(self, name=None, project_id=None, path=None, location=None, temporary=False):
|
||||
|
||||
self._name = name
|
||||
if project_id is None:
|
||||
self._id = str(uuid4())
|
||||
else:
|
||||
@ -75,6 +76,7 @@ class Project:
|
||||
def __json__(self):
|
||||
|
||||
return {
|
||||
"name": self._name,
|
||||
"project_id": self._id,
|
||||
"location": self._location,
|
||||
"temporary": self._temporary,
|
||||
@ -85,6 +87,10 @@ class Project:
|
||||
|
||||
return Config.instance().get_section_config("Server")
|
||||
|
||||
def is_local(self):
|
||||
|
||||
return self._config().get("local", False)
|
||||
|
||||
@classmethod
|
||||
def _get_default_project_directory(cls):
|
||||
"""
|
||||
@ -113,7 +119,7 @@ class Project:
|
||||
@location.setter
|
||||
def location(self, location):
|
||||
|
||||
if location != self._location and self._config().get("local", False) is False:
|
||||
if location != self._location and self.is_local() is False:
|
||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modify the project directory location")
|
||||
|
||||
self._location = location
|
||||
@ -127,12 +133,22 @@ class Project:
|
||||
def path(self, path):
|
||||
|
||||
if hasattr(self, "_path"):
|
||||
if path != self._path and self._config().get("local", False) is False:
|
||||
if path != self._path and self.is_local() is False:
|
||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modify the project directory location")
|
||||
|
||||
self._path = path
|
||||
self._update_temporary_file()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def vms(self):
|
||||
|
||||
|
@ -60,7 +60,7 @@ class ProjectManager:
|
||||
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
|
||||
return self._projects[project_id]
|
||||
|
||||
def create_project(self, project_id=None, path=None, temporary=False):
|
||||
def create_project(self, name=None, project_id=None, path=None, temporary=False):
|
||||
"""
|
||||
Create a project and keep a references to it in project manager.
|
||||
|
||||
@ -71,7 +71,7 @@ class ProjectManager:
|
||||
return self._projects[project_id]
|
||||
# FIXME: should we have an error?
|
||||
#raise aiohttp.web.HTTPConflict(text="Project ID {} is already in use on this server".format(project_id))
|
||||
project = Project(project_id=project_id, path=path, temporary=temporary)
|
||||
project = Project(name=name, project_id=project_id, path=path, temporary=temporary)
|
||||
self._projects[project.id] = project
|
||||
return project
|
||||
|
||||
|
@ -21,6 +21,11 @@ PROJECT_CREATE_SCHEMA = {
|
||||
"description": "Request validation to create a new Project instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "Project name",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1
|
||||
},
|
||||
"path": {
|
||||
"description": "Project directory",
|
||||
"type": ["string", "null"],
|
||||
@ -46,6 +51,11 @@ PROJECT_UPDATE_SCHEMA = {
|
||||
"description": "Request validation to update a Project instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "Project name",
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"temporary": {
|
||||
"description": "If project is a temporary project",
|
||||
"type": "boolean"
|
||||
@ -63,6 +73,11 @@ PROJECT_OBJECT_SCHEMA = {
|
||||
"description": "Project instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "Project name",
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"location": {
|
||||
"description": "Base directory where the project should be created on remote server",
|
||||
"type": "string",
|
||||
|
Loading…
Reference in New Issue
Block a user