mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge remote-tracking branch 'origin/asyncio' into asyncio
Conflicts: gns3server/modules/project.py tests/modules/test_project.py
This commit is contained in:
commit
b680138073
5 files changed
+67
-9
No files matched your search
@@ -50,24 +50,26 @@ class Project:
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(project_id))
|
||||
self._id = project_id
|
||||
|
||||
config = Config.instance().get_section_config("Server")
|
||||
self._location = location
|
||||
self._location = None
|
||||
if location is None:
|
||||
self._location = config.get("project_directory", self._get_default_project_directory())
|
||||
self._location = self._config().get("project_directory", self._get_default_project_directory())
|
||||
else:
|
||||
if config.get("local", False) is False:
|
||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
|
||||
self.location = location
|
||||
|
||||
self._vms = set()
|
||||
self._vms_to_destroy = set()
|
||||
self._path = os.path.join(self._location, self._id)
|
||||
try:
|
||||
os.makedirs(os.path.join(self._path, "vms"), exist_ok=True)
|
||||
os.makedirs(self._path, exist_ok=True)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
|
||||
self.temporary = temporary
|
||||
log.debug("Create project {id} in directory {path}".format(path=self._path, id=self._id))
|
||||
|
||||
def _config(self):
|
||||
|
||||
return Config.instance().get_section_config("Server")
|
||||
|
||||
@classmethod
|
||||
def _get_default_project_directory(cls):
|
||||
"""
|
||||
@@ -92,11 +94,27 @@ class Project:
|
||||
|
||||
return self._location
|
||||
|
||||
@location.setter
|
||||
def location(self, location):
|
||||
|
||||
if location != self._location and self._config().get("local", False) is False:
|
||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
|
||||
|
||||
self._location = location
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
|
||||
return self._path
|
||||
|
||||
@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")
|
||||
|
||||
self._path = path
|
||||
|
||||
@property
|
||||
def vms(self):
|
||||
|
||||
@@ -168,7 +186,8 @@ class Project:
|
||||
return {
|
||||
"project_id": self._id,
|
||||
"location": self._location,
|
||||
"temporary": self._temporary
|
||||
"temporary": self._temporary,
|
||||
"path": self._path,
|
||||
}
|
||||
|
||||
def add_vm(self, vm):
|
||||
|
||||
Reference in new issue
Block a user