mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
Update a project
This commit is contained in:
parent
abc885049f
commit
0e76527ce2
@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from ..web.route import Route
|
from ..web.route import Route
|
||||||
from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA
|
from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA
|
||||||
from ..modules.project_manager import ProjectManager
|
from ..modules.project_manager import ProjectManager
|
||||||
from aiohttp.web import HTTPConflict
|
from aiohttp.web import HTTPConflict
|
||||||
|
|
||||||
@ -39,6 +39,26 @@ class ProjectHandler:
|
|||||||
)
|
)
|
||||||
response.json(p)
|
response.json(p)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@Route.put(
|
||||||
|
r"/project/{uuid}",
|
||||||
|
description="Update a project",
|
||||||
|
parameters={
|
||||||
|
"uuid": "Project instance UUID",
|
||||||
|
},
|
||||||
|
status_codes={
|
||||||
|
200: "Project updated",
|
||||||
|
404: "Project instance doesn't exist"
|
||||||
|
},
|
||||||
|
output=PROJECT_OBJECT_SCHEMA,
|
||||||
|
input=PROJECT_UPDATE_SCHEMA)
|
||||||
|
def update(request, response):
|
||||||
|
|
||||||
|
pm = ProjectManager.instance()
|
||||||
|
project = pm.get_project(request.match_info["uuid"])
|
||||||
|
project.temporary = request.json.get("temporary", project.temporary)
|
||||||
|
response.json(project)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@Route.post(
|
@Route.post(
|
||||||
r"/project/{uuid}/commit",
|
r"/project/{uuid}/commit",
|
||||||
|
@ -76,6 +76,16 @@ class Project:
|
|||||||
|
|
||||||
return self._vms
|
return self._vms
|
||||||
|
|
||||||
|
@property
|
||||||
|
def temporary(self):
|
||||||
|
|
||||||
|
return self._temporary
|
||||||
|
|
||||||
|
@temporary.setter
|
||||||
|
def temporary(self, temporary):
|
||||||
|
|
||||||
|
self._temporary = temporary
|
||||||
|
|
||||||
def vm_working_directory(self, vm):
|
def vm_working_directory(self, vm):
|
||||||
"""
|
"""
|
||||||
Return a working directory for a specific VM.
|
Return a working directory for a specific VM.
|
||||||
|
@ -41,9 +41,22 @@ PROJECT_CREATE_SCHEMA = {
|
|||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PROJECT_UPDATE_SCHEMA = {
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "Request validation to update a Project instance",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"temporary": {
|
||||||
|
"description": "If project is a temporary project",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"additionalProperties": False,
|
||||||
|
}
|
||||||
|
|
||||||
PROJECT_OBJECT_SCHEMA = {
|
PROJECT_OBJECT_SCHEMA = {
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"description": "Request validation to create a new Project instance",
|
"description": "Project instance",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"location": {
|
"location": {
|
||||||
|
@ -60,6 +60,16 @@ def test_create_project_with_uuid(server):
|
|||||||
assert response.json["location"] == "/tmp"
|
assert response.json["location"] == "/tmp"
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_temporary_project(server):
|
||||||
|
query = {"temporary": True}
|
||||||
|
response = server.post("/project", query)
|
||||||
|
assert response.status == 200
|
||||||
|
query = {"temporary": False}
|
||||||
|
response = server.put("/project/{uuid}".format(uuid=response.json["uuid"]), query)
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.json["temporary"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_commit_project(server, project):
|
def test_commit_project(server, project):
|
||||||
with asyncio_patch("gns3server.modules.project.Project.commit", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.project.Project.commit", return_value=True) as mock:
|
||||||
response = server.post("/project/{uuid}/commit".format(uuid=project.uuid), example=True)
|
response = server.post("/project/{uuid}/commit".format(uuid=project.uuid), example=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user