1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

Explicitly close VM when the server is shutdown.

This commit is contained in:
grossmj 2015-01-22 23:40:51 -07:00
parent e61e976368
commit 0d503b779e
2 changed files with 13 additions and 5 deletions

View File

@ -94,12 +94,17 @@ class BaseManager:
return self._config return self._config
@classmethod
@asyncio.coroutine @asyncio.coroutine
def unload(cls): def unload(self):
# TODO: close explicitly all the VMs here? for uuid in self._vms.keys():
cls._instance = None try:
self.delete_vm(uuid)
except Exception as e:
log.warn("Could not delete VM {}: {}".format(uuid, e))
if hasattr(BaseManager, "_instance"):
BaseManager._instance = None
def get_vm(self, uuid): def get_vm(self, uuid):
""" """
@ -144,6 +149,8 @@ class BaseManager:
self._vms[vm.uuid] = vm self._vms[vm.uuid] = vm
return vm return vm
# FIXME: should be named close_vm and we should have a
# delete_vm when a user deletes a VM (including files in workdir)
@asyncio.coroutine @asyncio.coroutine
def delete_vm(self, uuid): def delete_vm(self, uuid):
""" """

View File

@ -68,7 +68,8 @@ def server(request, loop, port_manager):
def tear_down(): def tear_down():
for module in MODULES: for module in MODULES:
loop.run_until_complete(module.unload()) instance = module.instance()
loop.run_until_complete(instance.unload())
srv.close() srv.close()
srv.wait_closed() srv.wait_closed()
request.addfinalizer(tear_down) request.addfinalizer(tear_down)