Merge remote-tracking branch 'origin/asyncio' into asyncio

Conflicts:
	gns3server/modules/project.py
	tests/modules/test_project.py
This commit is contained in:
Jeremy committed 2015-02-04 13:52:46 -07:00
commit b680138073
5 files changed
+67 -9

No files matched your search

+2
View File
@@ -65,6 +65,7 @@ class ProjectHandler:
},
status_codes={
200: "The project has been updated",
403: "You are not allowed to modify this property",
404: "The project doesn't exist"
},
output=PROJECT_OBJECT_SCHEMA,
@@ -74,6 +75,7 @@ class ProjectHandler:
pm = ProjectManager.instance()
project = pm.get_project(request.match_info["project_id"])
project.temporary = request.json.get("temporary", project.temporary)
project.path = request.json.get("path", project.path)
response.json(project)
@classmethod
+26 -7
View File
@@ -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):
+9
View File
@@ -50,6 +50,10 @@ PROJECT_UPDATE_SCHEMA = {
"description": "If project is a temporary project",
"type": "boolean"
},
"path": {
"description": "Path of the project on the server (work only with --local)",
"type": ["string", "null"]
},
},
"additionalProperties": False,
}
@@ -64,6 +68,11 @@ PROJECT_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1
},
"path": {
"description": "Directory of the project on the server",
"type": "string",
"minLength": 1
},
"project_id": {
"description": "Project UUID",
"type": "string",