1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Let the server know about the project name and convert old IOU projects on remote servers.

This commit is contained in:
grossmj 2015-03-08 19:13:01 -06:00
parent 2934232afb
commit 95766fa30d
5 changed files with 51 additions and 17 deletions

View File

@ -37,6 +37,7 @@ class ProjectHandler:
pm = ProjectManager.instance() pm = ProjectManager.instance()
p = pm.create_project( p = pm.create_project(
name=request.json.get("name"),
path=request.json.get("path"), path=request.json.get("path"),
project_id=request.json.get("project_id"), project_id=request.json.get("project_id"),
temporary=request.json.get("temporary", False) temporary=request.json.get("temporary", False)
@ -81,6 +82,7 @@ class ProjectHandler:
pm = ProjectManager.instance() pm = ProjectManager.instance()
project = pm.get_project(request.match_info["project_id"]) project = pm.get_project(request.match_info["project_id"])
project.temporary = request.json.get("temporary", project.temporary) project.temporary = request.json.get("temporary", project.temporary)
project.name = request.json.get("name", project.name)
project_path = request.json.get("path", project.path) project_path = request.json.get("path", project.path)
if project_path != project.path: if project_path != project.path:
project.path = project_path project.path = project_path

View File

@ -162,8 +162,7 @@ class BaseManager:
""" """
new_id = str(uuid4()) 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") 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): if os.path.exists(legacy_project_files_path) and not os.path.exists(new_project_files_path):
# move the project files # 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, raise aiohttp.web.HTTPInternalServerError(text="Could not move project files directory: {} to {} {}".format(legacy_project_files_path,
new_project_files_path, e)) new_project_files_path, e))
legacy_iou_dir = os.path.join(project.path, "iou") if project.is_local() is False:
new_iou_dir = os.path.join(project.path, "project-files", "iou") legacy_remote_iou_project = os.path.join(project.location, project.name, "iou")
if os.path.exists(legacy_iou_dir) and not os.path.exists(new_iou_dir): new_iou_project_path = os.path.join(project.path, "project-files", "iou")
# move the iou dir on remote server 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: try:
log.info('Moving "{}" to "{}"'.format(legacy_iou_dir, new_iou_dir)) log.info('Moving "{}" to "{}"'.format(legacy_remote_iou_project, new_iou_project_path))
yield from wait_run_in_executor(shutil.move, legacy_iou_dir, new_iou_dir) yield from wait_run_in_executor(shutil.move, legacy_remote_iou_project, new_iou_project_path)
except OSError as e: except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not move IOU directory: {} to {} {}".format(legacy_iou_dir, raise aiohttp.web.HTTPInternalServerError(text="Could not move IOU directory: {} to {} {}".format(legacy_remote_iou_project,
new_iou_dir, e)) new_iou_project_path, e))
if hasattr(self, "get_legacy_vm_workdir"): if hasattr(self, "get_legacy_vm_workdir"):
# rename old project VM working dir # rename old project VM working dir

View File

@ -41,8 +41,9 @@ class Project:
:param temporary: Boolean the project is a temporary project (destroy when closed) :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: if project_id is None:
self._id = str(uuid4()) self._id = str(uuid4())
else: else:
@ -75,6 +76,7 @@ class Project:
def __json__(self): def __json__(self):
return { return {
"name": self._name,
"project_id": self._id, "project_id": self._id,
"location": self._location, "location": self._location,
"temporary": self._temporary, "temporary": self._temporary,
@ -85,6 +87,10 @@ class Project:
return Config.instance().get_section_config("Server") return Config.instance().get_section_config("Server")
def is_local(self):
return self._config().get("local", False)
@classmethod @classmethod
def _get_default_project_directory(cls): def _get_default_project_directory(cls):
""" """
@ -113,7 +119,7 @@ class Project:
@location.setter @location.setter
def location(self, location): 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") raise aiohttp.web.HTTPForbidden(text="You are not allowed to modify the project directory location")
self._location = location self._location = location
@ -127,12 +133,22 @@ class Project:
def path(self, path): def path(self, path):
if hasattr(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") raise aiohttp.web.HTTPForbidden(text="You are not allowed to modify the project directory location")
self._path = path self._path = path
self._update_temporary_file() self._update_temporary_file()
@property
def name(self):
return self._name
@name.setter
def name(self, name):
self._name = name
@property @property
def vms(self): def vms(self):

View File

@ -60,7 +60,7 @@ class ProjectManager:
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id)) raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
return self._projects[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. Create a project and keep a references to it in project manager.
@ -71,7 +71,7 @@ class ProjectManager:
return self._projects[project_id] return self._projects[project_id]
# FIXME: should we have an error? # FIXME: should we have an error?
#raise aiohttp.web.HTTPConflict(text="Project ID {} is already in use on this server".format(project_id)) #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 self._projects[project.id] = project
return project return project

View File

@ -21,6 +21,11 @@ PROJECT_CREATE_SCHEMA = {
"description": "Request validation to create a new Project instance", "description": "Request validation to create a new Project instance",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {
"description": "Project name",
"type": ["string", "null"],
"minLength": 1
},
"path": { "path": {
"description": "Project directory", "description": "Project directory",
"type": ["string", "null"], "type": ["string", "null"],
@ -46,6 +51,11 @@ PROJECT_UPDATE_SCHEMA = {
"description": "Request validation to update a Project instance", "description": "Request validation to update a Project instance",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {
"description": "Project name",
"type": "string",
"minLength": 1
},
"temporary": { "temporary": {
"description": "If project is a temporary project", "description": "If project is a temporary project",
"type": "boolean" "type": "boolean"
@ -63,6 +73,11 @@ PROJECT_OBJECT_SCHEMA = {
"description": "Project instance", "description": "Project instance",
"type": "object", "type": "object",
"properties": { "properties": {
"name": {
"description": "Project name",
"type": "string",
"minLength": 1
},
"location": { "location": {
"description": "Base directory where the project should be created on remote server", "description": "Base directory where the project should be created on remote server",
"type": "string", "type": "string",