mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-26 00:38:10 +00:00
Rename destroy to close or unload (more friendly).
This commit is contained in:
parent
2681defe27
commit
d9b02efbfa
@ -125,3 +125,22 @@ class VirtualBoxHandler:
|
|||||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||||
yield from vm.resume()
|
yield from vm.resume()
|
||||||
response.set_status(204)
|
response.set_status(204)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@Route.post(
|
||||||
|
r"/virtualbox/{uuid}/reload",
|
||||||
|
parameters={
|
||||||
|
"uuid": "VirtualBox VM instance UUID"
|
||||||
|
},
|
||||||
|
status_codes={
|
||||||
|
204: "VirtualBox VM instance reloaded",
|
||||||
|
400: "Invalid VirtualBox VM instance UUID",
|
||||||
|
404: "VirtualBox VM instance doesn't exist"
|
||||||
|
},
|
||||||
|
description="Reload a VirtualBox VM instance")
|
||||||
|
def suspend(request, response):
|
||||||
|
|
||||||
|
vbox_manager = VirtualBox.instance()
|
||||||
|
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||||
|
yield from vm.reload()
|
||||||
|
response.set_status(204)
|
||||||
|
@ -95,9 +95,9 @@ class BaseManager:
|
|||||||
return self._config
|
return self._config
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@asyncio.coroutine # FIXME: why coroutine?
|
def unload(cls):
|
||||||
def destroy(cls):
|
|
||||||
|
|
||||||
|
# TODO: close explicitly all the VMs here?
|
||||||
cls._instance = None
|
cls._instance = None
|
||||||
|
|
||||||
def get_vm(self, uuid):
|
def get_vm(self, uuid):
|
||||||
@ -152,10 +152,10 @@ class BaseManager:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
vm = self.get_vm(uuid)
|
vm = self.get_vm(uuid)
|
||||||
if asyncio.iscoroutinefunction(vm.destroy):
|
if asyncio.iscoroutinefunction(vm.close):
|
||||||
yield from vm.destroy()
|
yield from vm.close()
|
||||||
else:
|
else:
|
||||||
vm.destroy()
|
vm.close()
|
||||||
del self._vms[vm.uuid]
|
del self._vms[vm.uuid]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -33,7 +33,8 @@ class BaseVM:
|
|||||||
uuid=self.uuid))
|
uuid=self.uuid))
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.destroy()
|
|
||||||
|
self.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project(self):
|
def project(self):
|
||||||
@ -120,9 +121,9 @@ class BaseVM:
|
|||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def destroy(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Destroy the VM process.
|
Close the VM process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -77,7 +77,8 @@ class VPCSVM(BaseVM):
|
|||||||
else:
|
else:
|
||||||
self._console = self._manager.port_manager.get_free_console_port()
|
self._console = self._manager.port_manager.get_free_console_port()
|
||||||
|
|
||||||
def destroy(self):
|
def close(self):
|
||||||
|
|
||||||
self._kill_process()
|
self._kill_process()
|
||||||
if self._console:
|
if self._console:
|
||||||
self._manager.port_manager.release_console_port(self._console)
|
self._manager.port_manager.release_console_port(self._console)
|
||||||
|
@ -80,7 +80,7 @@ class Server:
|
|||||||
for module in MODULES:
|
for module in MODULES:
|
||||||
log.debug("Unloading module {}".format(module.__name__))
|
log.debug("Unloading module {}".format(module.__name__))
|
||||||
m = module.instance()
|
m = module.instance()
|
||||||
m.destroy()
|
m.unload()
|
||||||
self._loop.stop()
|
self._loop.stop()
|
||||||
|
|
||||||
def _signal_handling(self):
|
def _signal_handling(self):
|
||||||
|
@ -68,7 +68,7 @@ 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.destroy())
|
loop.run_until_complete(module.unload())
|
||||||
srv.close()
|
srv.close()
|
||||||
srv.wait_closed()
|
srv.wait_closed()
|
||||||
request.addfinalizer(tear_down)
|
request.addfinalizer(tear_down)
|
||||||
|
@ -186,12 +186,12 @@ def test_change_script_file(vm, tmpdir):
|
|||||||
assert vm.script_file == path
|
assert vm.script_file == path
|
||||||
|
|
||||||
|
|
||||||
def test_destroy(vm, port_manager):
|
def test_close(vm, port_manager):
|
||||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||||
vm.start()
|
vm.start()
|
||||||
port = vm.console
|
port = vm.console
|
||||||
vm.destroy()
|
vm.close()
|
||||||
# Raise an exception if the port is not free
|
# Raise an exception if the port is not free
|
||||||
port_manager.reserve_console_port(port)
|
port_manager.reserve_console_port(port)
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
|
Loading…
Reference in New Issue
Block a user