mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-13 09:30:54 +00:00
When we remove a VM, the VM is removed from the project.
This commit is contained in:
parent
3f5c2390cd
commit
7bf121c6da
@ -142,6 +142,7 @@ class BaseManager:
|
|||||||
uuid = str(uuid4())
|
uuid = str(uuid4())
|
||||||
|
|
||||||
vm = self._VM_CLASS(name, uuid, project, self, *args, **kwargs)
|
vm = self._VM_CLASS(name, uuid, project, self, *args, **kwargs)
|
||||||
|
project.add_vm(vm)
|
||||||
if asyncio.iscoroutinefunction(vm.create):
|
if asyncio.iscoroutinefunction(vm.create):
|
||||||
yield from vm.create()
|
yield from vm.create()
|
||||||
else:
|
else:
|
||||||
|
@ -27,7 +27,6 @@ class BaseVM:
|
|||||||
self._uuid = uuid
|
self._uuid = uuid
|
||||||
self._project = project
|
self._project = project
|
||||||
self._manager = manager
|
self._manager = manager
|
||||||
project.add_vm(self)
|
|
||||||
|
|
||||||
log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name,
|
log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
|
@ -95,6 +95,7 @@ class Project:
|
|||||||
:param vm: An instance of VM
|
:param vm: An instance of VM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.remove_vm(vm)
|
||||||
self._vms_to_destroy.add(vm)
|
self._vms_to_destroy.add(vm)
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
@ -106,14 +107,25 @@ class Project:
|
|||||||
|
|
||||||
def add_vm(self, vm):
|
def add_vm(self, vm):
|
||||||
"""
|
"""
|
||||||
Add a VM to the project. In theory this should be called by
|
Add a VM to the project.
|
||||||
the VM initializer.
|
In theory this should be called by the VM manager.
|
||||||
|
|
||||||
:params vm: A VM instance
|
:params vm: A VM instance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._vms.add(vm)
|
self._vms.add(vm)
|
||||||
|
|
||||||
|
def remove_vm(self, vm):
|
||||||
|
"""
|
||||||
|
Remove a VM from the project.
|
||||||
|
In theory this should be called by the VM manager.
|
||||||
|
|
||||||
|
:params vm: A VM instance
|
||||||
|
"""
|
||||||
|
|
||||||
|
if vm in self._vms:
|
||||||
|
self._vms.remove(vm)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close the project, but keep informations on disk"""
|
"""Close the project, but keep informations on disk"""
|
||||||
|
|
||||||
@ -128,6 +140,7 @@ class Project:
|
|||||||
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)
|
||||||
|
self.remove_vm(vm)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
"""Remove project from disk"""
|
"""Remove project from disk"""
|
||||||
|
@ -68,14 +68,17 @@ def test_vm_working_directory(tmpdir, vm):
|
|||||||
|
|
||||||
|
|
||||||
def test_mark_vm_for_destruction(tmpdir, vm):
|
def test_mark_vm_for_destruction(tmpdir, vm):
|
||||||
p = Project(location=str(tmpdir))
|
project = Project(location=str(tmpdir))
|
||||||
p.mark_vm_for_destruction(vm)
|
project.add_vm(vm)
|
||||||
assert len(p._vms_to_destroy) == 1
|
project.mark_vm_for_destruction(vm)
|
||||||
|
assert len(project._vms_to_destroy) == 1
|
||||||
|
assert len(project.vms) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_commit(tmpdir, manager):
|
def test_commit(tmpdir, manager):
|
||||||
project = Project(location=str(tmpdir))
|
project = Project(location=str(tmpdir))
|
||||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||||
|
project.add_vm(vm)
|
||||||
directory = project.vm_working_directory(vm)
|
directory = project.vm_working_directory(vm)
|
||||||
project.mark_vm_for_destruction(vm)
|
project.mark_vm_for_destruction(vm)
|
||||||
assert len(project._vms_to_destroy) == 1
|
assert len(project._vms_to_destroy) == 1
|
||||||
@ -83,6 +86,7 @@ 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
|
||||||
|
assert len(project.vms) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_project_delete(tmpdir):
|
def test_project_delete(tmpdir):
|
||||||
@ -95,8 +99,8 @@ def test_project_delete(tmpdir):
|
|||||||
|
|
||||||
def test_project_add_vm(tmpdir, manager):
|
def test_project_add_vm(tmpdir, manager):
|
||||||
project = Project(location=str(tmpdir))
|
project = Project(location=str(tmpdir))
|
||||||
# The VM initalizer call the add_vm method
|
|
||||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||||
|
project.add_vm(vm)
|
||||||
assert len(project.vms) == 1
|
assert len(project.vms) == 1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user