mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-01 04:38:12 +00:00
Delete a project
This commit is contained in:
parent
9a0b260c56
commit
986a7f55ef
@ -49,9 +49,27 @@ class ProjectHandler:
|
|||||||
204: "Changes write on disk",
|
204: "Changes write on disk",
|
||||||
404: "Project instance doesn't exist"
|
404: "Project instance doesn't exist"
|
||||||
})
|
})
|
||||||
def create_project(request, response):
|
def commit(request, response):
|
||||||
|
|
||||||
pm = ProjectManager.instance()
|
pm = ProjectManager.instance()
|
||||||
project = pm.get_project(request.match_info["uuid"])
|
project = pm.get_project(request.match_info["uuid"])
|
||||||
project.commit()
|
project.commit()
|
||||||
response.set_status(204)
|
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)
|
||||||
|
@ -98,10 +98,23 @@ class Project:
|
|||||||
"location": self._location
|
"location": self._location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
"""Close the project, but keep informations on disk"""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
"""Write project changes on disk"""
|
"""Write project changes on disk"""
|
||||||
|
|
||||||
while self._vms_to_destroy:
|
while self._vms_to_destroy:
|
||||||
vm = self._vms_to_destroy.pop()
|
vm = self._vms_to_destroy.pop()
|
||||||
directory = self.vm_working_directory(vm)
|
directory = self.vm_working_directory(vm)
|
||||||
if os.path.exists(directory):
|
if os.path.exists(directory):
|
||||||
shutil.rmtree(directory)
|
shutil.rmtree(directory)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""Remove project from disk"""
|
||||||
|
|
||||||
|
self.close()
|
||||||
|
if os.path.exists(self.path):
|
||||||
|
shutil.rmtree(self.path)
|
||||||
|
@ -51,10 +51,23 @@ def test_create_project_with_uuid(server):
|
|||||||
|
|
||||||
|
|
||||||
def test_commit_project(server, project):
|
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
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
def test_commit_project_invalid_project_uuid(server, project):
|
def test_commit_project_invalid_project_uuid(server, project):
|
||||||
response = server.post("/project/{uuid}/commit".format(uuid=uuid.uuid4()))
|
response = server.post("/project/{uuid}/commit".format(uuid=uuid.uuid4()))
|
||||||
assert response.status == 404
|
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
|
||||||
|
@ -81,3 +81,11 @@ def test_commit(tmpdir, manager):
|
|||||||
project.commit()
|
project.commit()
|
||||||
assert len(project._vms_to_destroy) == 0
|
assert len(project._vms_to_destroy) == 0
|
||||||
assert os.path.exists(directory) is False
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user