mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Allow user to change project path on local server
This commit is contained in:
1 parent
9f7b8574c8
commit
5a0c224292
5 files changed
+35
-15
No files matched your search
@@ -32,7 +32,7 @@ class ProjectHandler:
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
p = pm.create_project(
|
||||
location=request.json.get("location"),
|
||||
path=request.json.get("path"),
|
||||
project_id=request.json.get("project_id"),
|
||||
temporary=request.json.get("temporary", False)
|
||||
)
|
||||
|
||||
@@ -35,11 +35,12 @@ class Project:
|
||||
In theory VM are isolated project/project.
|
||||
|
||||
:param project_id: Force project identifier (None by default auto generate an UUID)
|
||||
:param path: Path of the project. (None use the standard directory)
|
||||
:param location: Parent path of the project. (None should create a tmp directory)
|
||||
:param temporary: Boolean the project is a temporary project (destroy when closed)
|
||||
"""
|
||||
|
||||
def __init__(self, project_id=None, location=None, temporary=False):
|
||||
def __init__(self, project_id=None, path=None, location=None, temporary=False):
|
||||
|
||||
if project_id is None:
|
||||
self._id = str(uuid4())
|
||||
@@ -58,12 +59,17 @@ class Project:
|
||||
|
||||
self._vms = set()
|
||||
self._vms_to_destroy = set()
|
||||
self._path = os.path.join(self._location, self._id)
|
||||
|
||||
self.temporary = temporary
|
||||
|
||||
if path is None:
|
||||
path = os.path.join(self._location, self._id)
|
||||
try:
|
||||
os.makedirs(self._path, exist_ok=True)
|
||||
os.makedirs(path, exist_ok=True)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
|
||||
self.temporary = temporary
|
||||
self.path = path
|
||||
|
||||
log.debug("Create project {id} in directory {path}".format(path=self._path, id=self._id))
|
||||
|
||||
def _config(self):
|
||||
@@ -110,8 +116,9 @@ class Project:
|
||||
@path.setter
|
||||
def path(self, path):
|
||||
|
||||
if path != self._path and self._config().get("local", False) is False:
|
||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
|
||||
if hasattr(self, "_path"):
|
||||
if path != self._path and self._config().get("local", False) is False:
|
||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
|
||||
|
||||
self._path = path
|
||||
self._update_temporary_file()
|
||||
@@ -141,6 +148,9 @@ class Project:
|
||||
project status.
|
||||
"""
|
||||
|
||||
if not hasattr(self, "_path"):
|
||||
return
|
||||
|
||||
if self._temporary:
|
||||
try:
|
||||
with open(os.path.join(self._path, ".gns3_temporary"), 'w+') as f:
|
||||
|
||||
@@ -21,8 +21,8 @@ PROJECT_CREATE_SCHEMA = {
|
||||
"description": "Request validation to create a new Project instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"description": "Base directory where the project should be created on remote server",
|
||||
"path": {
|
||||
"description": "Project directory",
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user