mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Support auto stop for the GNS3 VM
Ref https://github.com/GNS3/gns3-gui/issues/1254
This commit is contained in:
parent
fc8b4c3216
commit
9255dc07b7
@ -87,6 +87,8 @@ class Controller:
|
|||||||
log.info("Stop controller")
|
log.info("Stop controller")
|
||||||
for compute in self._computes.values():
|
for compute in self._computes.values():
|
||||||
yield from compute.close()
|
yield from compute.close()
|
||||||
|
if self.gns3vm.enable and self.gns3vm.auto_stop:
|
||||||
|
yield from self.gns3vm.stop()
|
||||||
self._computes = {}
|
self._computes = {}
|
||||||
self._projects = {}
|
self._projects = {}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class GNS3VM:
|
|||||||
self._engines = {}
|
self._engines = {}
|
||||||
self._settings = {
|
self._settings = {
|
||||||
"vmname": None,
|
"vmname": None,
|
||||||
"auto_stop": False,
|
"auto_stop": True,
|
||||||
"headless": False,
|
"headless": False,
|
||||||
"enable": False,
|
"enable": False,
|
||||||
"engine": "vmware"
|
"engine": "vmware"
|
||||||
@ -120,6 +120,13 @@ class GNS3VM:
|
|||||||
"""
|
"""
|
||||||
return self._settings["enable"]
|
return self._settings["enable"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def auto_stop(self):
|
||||||
|
"""
|
||||||
|
The GNSVM should auto stop
|
||||||
|
"""
|
||||||
|
return self._settings["auto_stop"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def settings(self):
|
def settings(self):
|
||||||
return self._settings
|
return self._settings
|
||||||
@ -169,3 +176,12 @@ class GNS3VM:
|
|||||||
engine.vmname = self._settings["vmname"]
|
engine.vmname = self._settings["vmname"]
|
||||||
yield from engine.start()
|
yield from engine.start()
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def stop(self):
|
||||||
|
"""
|
||||||
|
Stop the GNS3 VM
|
||||||
|
"""
|
||||||
|
engine = self._current_engine()
|
||||||
|
if not engine.running:
|
||||||
|
log.info("Stop the GNS3 VM")
|
||||||
|
yield from engine.stop()
|
||||||
|
@ -282,6 +282,21 @@ def test_stop(controller, async_run):
|
|||||||
assert c.connected is False
|
assert c.connected is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_stop_vm(controller, async_run):
|
||||||
|
"""
|
||||||
|
Start the controller with a GNS3 VM running
|
||||||
|
"""
|
||||||
|
controller.gns3vm.settings = {
|
||||||
|
"enable": True,
|
||||||
|
"engine": "vmware",
|
||||||
|
"auto_stop": True
|
||||||
|
}
|
||||||
|
controller.gns3vm.running = True
|
||||||
|
with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.stop") as mock:
|
||||||
|
async_run(controller.stop())
|
||||||
|
assert mock.called
|
||||||
|
|
||||||
|
|
||||||
def test_load_project(controller, async_run, tmpdir):
|
def test_load_project(controller, async_run, tmpdir):
|
||||||
data = {
|
data = {
|
||||||
"name": "Experience",
|
"name": "Experience",
|
||||||
|
Loading…
Reference in New Issue
Block a user