1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Delete a project

This commit is contained in:
Julien Duponchelle 2015-01-23 11:48:20 +01:00
parent 9a0b260c56
commit 986a7f55ef
4 changed files with 54 additions and 2 deletions

View File

@ -49,9 +49,27 @@ class ProjectHandler:
204: "Changes write on disk",
404: "Project instance doesn't exist"
})
def create_project(request, response):
def commit(request, response):
pm = ProjectManager.instance()
project = pm.get_project(request.match_info["uuid"])
project.commit()
response.set_status(204)
@classmethod
@Route.delete(
r"/project/{uuid}",
description="Delete a project from disk",
parameters={
"uuid": "Project instance UUID",
},
status_codes={
204: "Changes write on disk",
404: "Project instance doesn't exist"
})
def delete(request, response):
pm = ProjectManager.instance()
project = pm.get_project(request.match_info["uuid"])
project.delete()
response.set_status(204)

View File

@ -98,10 +98,23 @@ class Project:
"location": self._location
}
def close(self):
"""Close the project, but keep informations on disk"""
pass
def commit(self):
"""Write project changes on disk"""
while self._vms_to_destroy:
vm = self._vms_to_destroy.pop()
directory = self.vm_working_directory(vm)
if os.path.exists(directory):
shutil.rmtree(directory)
def delete(self):
"""Remove project from disk"""
self.close()
if os.path.exists(self.path):
shutil.rmtree(self.path)

View File

@ -51,10 +51,23 @@ def test_create_project_with_uuid(server):
def test_commit_project(server, project):
response = server.post("/project/{uuid}/commit".format(uuid=project.uuid))
response = server.post("/project/{uuid}/commit".format(uuid=project.uuid), example=True)
assert response.status == 204
def test_commit_project_invalid_project_uuid(server, project):
response = server.post("/project/{uuid}/commit".format(uuid=uuid.uuid4()))
assert response.status == 404
def test_delete_project(server):
query = {"uuid": "00010203-0405-0607-0809-0a0b0c0d0e0f"}
response = server.post("/project", query)
assert response.status == 200
response = server.delete("/project/00010203-0405-0607-0809-0a0b0c0d0e0f")
assert response.status == 204
def test_delete_project_invalid_uuid(server, project):
response = server.delete("/project/{uuid}".format(uuid=uuid.uuid4()))
assert response.status == 404

View File

@ -81,3 +81,11 @@ def test_commit(tmpdir, manager):
project.commit()
assert len(project._vms_to_destroy) == 0
assert os.path.exists(directory) is False
def test_project_delete(tmpdir):
project = Project(location=str(tmpdir))
directory = project.path
assert os.path.exists(directory)
project.delete()
assert os.path.exists(directory) is False