mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Close a project
This commit is contained in:
1 parent
986a7f55ef
commit
3f5c2390cd
5 files changed
+76
-8
No files matched your search
@@ -56,6 +56,24 @@ class ProjectHandler:
|
||||
project.commit()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/project/{uuid}/close",
|
||||
description="Close project",
|
||||
parameters={
|
||||
"uuid": "Project instance UUID",
|
||||
},
|
||||
status_codes={
|
||||
204: "Project closed",
|
||||
404: "Project instance doesn't exist"
|
||||
})
|
||||
def close(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["uuid"])
|
||||
project.close()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/project/{uuid}",
|
||||
|
||||
@@ -27,6 +27,7 @@ class BaseVM:
|
||||
self._uuid = uuid
|
||||
self._project = project
|
||||
self._manager = manager
|
||||
project.add_vm(self)
|
||||
|
||||
log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name,
|
||||
name=self.name,
|
||||
|
||||
@@ -46,6 +46,7 @@ class Project:
|
||||
if location is None:
|
||||
self._location = tempfile.mkdtemp()
|
||||
|
||||
self._vms = set()
|
||||
self._vms_to_destroy = set()
|
||||
self._path = os.path.join(self._location, self._uuid)
|
||||
try:
|
||||
@@ -68,6 +69,11 @@ class Project:
|
||||
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def vms(self):
|
||||
|
||||
return self._vms
|
||||
|
||||
def vm_working_directory(self, vm):
|
||||
"""
|
||||
Return a working directory for a specific VM.
|
||||
@@ -98,10 +104,21 @@ class Project:
|
||||
"location": self._location
|
||||
}
|
||||
|
||||
def add_vm(self, vm):
|
||||
"""
|
||||
Add a VM to the project. In theory this should be called by
|
||||
the VM initializer.
|
||||
|
||||
:params vm: A VM instance
|
||||
"""
|
||||
|
||||
self._vms.add(vm)
|
||||
|
||||
def close(self):
|
||||
"""Close the project, but keep informations on disk"""
|
||||
|
||||
pass
|
||||
for vm in self._vms:
|
||||
vm.close()
|
||||
|
||||
def commit(self):
|
||||
"""Write project changes on disk"""
|
||||
|
||||
Reference in new issue
Block a user