mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-31 13:23:48 +02:00
Make sure nodes send the right notification when started, stopped or suspended.
This commit is contained in:
parent
51738e19c3
commit
5b604da33a
@ -105,7 +105,9 @@ class BaseNode:
|
|||||||
def status(self, status):
|
def status(self, status):
|
||||||
|
|
||||||
self._node_status = status
|
self._node_status = status
|
||||||
self._project.emit("node.updated", self)
|
if status in ("started", "stopped", "suspended"):
|
||||||
|
self.project.emit("node.{status}".format(status=status), {"node_id": self.id})
|
||||||
|
self.project.emit("node.updated", self) # FIXME: should we send this when we just start/stop/suspend a node?
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def command_line(self):
|
def command_line(self):
|
||||||
|
@ -505,11 +505,12 @@ class DockerVM(BaseNode):
|
|||||||
# t=5 number of seconds to wait before killing the container
|
# t=5 number of seconds to wait before killing the container
|
||||||
try:
|
try:
|
||||||
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
|
yield from self.manager.query("POST", "containers/{}/stop".format(self._cid), params={"t": 5})
|
||||||
log.info("Docker container '{name}' [{image}] stopped".format(
|
log.info("Docker container '{name}' [{image}] stopped".format(name=self._name, image=self._image))
|
||||||
name=self._name, image=self._image))
|
|
||||||
except DockerHttp304Error:
|
except DockerHttp304Error:
|
||||||
# Container is already stopped
|
# Container is already stopped
|
||||||
pass
|
pass
|
||||||
|
finally:
|
||||||
|
self.status = "stopped"
|
||||||
# Ignore runtime error because when closing the server
|
# Ignore runtime error because when closing the server
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
log.debug("Docker runtime error when closing: {}".format(str(e)))
|
log.debug("Docker runtime error when closing: {}".format(str(e)))
|
||||||
@ -519,17 +520,15 @@ class DockerVM(BaseNode):
|
|||||||
def pause(self):
|
def pause(self):
|
||||||
"""Pauses this Docker container."""
|
"""Pauses this Docker container."""
|
||||||
yield from self.manager.query("POST", "containers/{}/pause".format(self._cid))
|
yield from self.manager.query("POST", "containers/{}/pause".format(self._cid))
|
||||||
log.info("Docker container '{name}' [{image}] paused".format(
|
self.status = "suspended"
|
||||||
name=self._name, image=self._image))
|
log.info("Docker container '{name}' [{image}] paused".format(name=self._name, image=self._image))
|
||||||
self.status = "paused"
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def unpause(self):
|
def unpause(self):
|
||||||
"""Unpauses this Docker container."""
|
"""Unpauses this Docker container."""
|
||||||
yield from self.manager.query("POST", "containers/{}/unpause".format(self._cid))
|
yield from self.manager.query("POST", "containers/{}/unpause".format(self._cid))
|
||||||
log.info("Docker container '{name}' [{image}] unpaused".format(
|
|
||||||
name=self._name, image=self._image))
|
|
||||||
self.status = "started"
|
self.status = "started"
|
||||||
|
log.info("Docker container '{name}' [{image}] unpaused".format(name=self._name, image=self._image))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -294,6 +294,7 @@ class Router(BaseNode):
|
|||||||
status = yield from self.get_status()
|
status = yield from self.get_status()
|
||||||
if status == "running":
|
if status == "running":
|
||||||
yield from self._hypervisor.send('vm suspend "{name}"'.format(name=self._name))
|
yield from self._hypervisor.send('vm suspend "{name}"'.format(name=self._name))
|
||||||
|
self.status = "suspended"
|
||||||
log.info('Router "{name}" [{id}] has been suspended'.format(name=self._name, id=self._id))
|
log.info('Router "{name}" [{id}] has been suspended'.format(name=self._name, id=self._id))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -1036,6 +1036,7 @@ class QemuVM(BaseNode):
|
|||||||
raise QemuError("Suspending a QEMU VM is not supported")
|
raise QemuError("Suspending a QEMU VM is not supported")
|
||||||
elif vm_status == "running":
|
elif vm_status == "running":
|
||||||
yield from self._control_vm("stop")
|
yield from self._control_vm("stop")
|
||||||
|
self.status = "suspended"
|
||||||
log.debug("QEMU VM has been suspended")
|
log.debug("QEMU VM has been suspended")
|
||||||
else:
|
else:
|
||||||
log.info("QEMU VM is not running to be suspended, current status is {}".format(vm_status))
|
log.info("QEMU VM is not running to be suspended, current status is {}".format(vm_status))
|
||||||
|
@ -208,6 +208,7 @@ class VirtualBoxVM(BaseNode):
|
|||||||
if self._headless:
|
if self._headless:
|
||||||
args.extend(["--type", "headless"])
|
args.extend(["--type", "headless"])
|
||||||
result = yield from self.manager.execute("startvm", args)
|
result = yield from self.manager.execute("startvm", args)
|
||||||
|
self.status = "started"
|
||||||
log.info("VirtualBox VM '{name}' [{id}] started".format(name=self.name, id=self.id))
|
log.info("VirtualBox VM '{name}' [{id}] started".format(name=self.name, id=self.id))
|
||||||
log.debug("Start result: {}".format(result))
|
log.debug("Start result: {}".format(result))
|
||||||
|
|
||||||
@ -243,10 +244,12 @@ class VirtualBoxVM(BaseNode):
|
|||||||
if self.acpi_shutdown:
|
if self.acpi_shutdown:
|
||||||
# use ACPI to shutdown the VM
|
# use ACPI to shutdown the VM
|
||||||
result = yield from self._control_vm("acpipowerbutton")
|
result = yield from self._control_vm("acpipowerbutton")
|
||||||
|
self.status = "stopped"
|
||||||
log.debug("ACPI shutdown result: {}".format(result))
|
log.debug("ACPI shutdown result: {}".format(result))
|
||||||
else:
|
else:
|
||||||
# power off the VM
|
# power off the VM
|
||||||
result = yield from self._control_vm("poweroff")
|
result = yield from self._control_vm("poweroff")
|
||||||
|
self.status = "stopped"
|
||||||
log.debug("Stop result: {}".format(result))
|
log.debug("Stop result: {}".format(result))
|
||||||
|
|
||||||
log.info("VirtualBox VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
log.info("VirtualBox VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
||||||
@ -273,6 +276,7 @@ class VirtualBoxVM(BaseNode):
|
|||||||
vm_state = yield from self._get_vm_state()
|
vm_state = yield from self._get_vm_state()
|
||||||
if vm_state == "running":
|
if vm_state == "running":
|
||||||
yield from self._control_vm("pause")
|
yield from self._control_vm("pause")
|
||||||
|
self.status = "suspended"
|
||||||
log.info("VirtualBox VM '{name}' [{id}] suspended".format(name=self.name, id=self.id))
|
log.info("VirtualBox VM '{name}' [{id}] suspended".format(name=self.name, id=self.id))
|
||||||
else:
|
else:
|
||||||
log.warn("VirtualBox VM '{name}' [{id}] cannot be suspended, current state: {state}".format(name=self.name,
|
log.warn("VirtualBox VM '{name}' [{id}] cannot be suspended, current state: {state}".format(name=self.name,
|
||||||
@ -286,6 +290,7 @@ class VirtualBoxVM(BaseNode):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
yield from self._control_vm("resume")
|
yield from self._control_vm("resume")
|
||||||
|
self.status = "started"
|
||||||
log.info("VirtualBox VM '{name}' [{id}] resumed".format(name=self.name, id=self.id))
|
log.info("VirtualBox VM '{name}' [{id}] resumed".format(name=self.name, id=self.id))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -480,6 +480,7 @@ class VMwareVM(BaseNode):
|
|||||||
self._hw_virtualization = True
|
self._hw_virtualization = True
|
||||||
|
|
||||||
self._started = True
|
self._started = True
|
||||||
|
self.status = "started"
|
||||||
log.info("VMware VM '{name}' [{id}] started".format(name=self.name, id=self.id))
|
log.info("VMware VM '{name}' [{id}] started".format(name=self.name, id=self.id))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -502,6 +503,7 @@ class VMwareVM(BaseNode):
|
|||||||
yield from self._control_vm("stop")
|
yield from self._control_vm("stop")
|
||||||
finally:
|
finally:
|
||||||
self._started = False
|
self._started = False
|
||||||
|
self.status = "stopped"
|
||||||
|
|
||||||
self._read_vmx_file()
|
self._read_vmx_file()
|
||||||
if self._use_ubridge:
|
if self._use_ubridge:
|
||||||
@ -538,6 +540,7 @@ class VMwareVM(BaseNode):
|
|||||||
if self.manager.host_type != "ws":
|
if self.manager.host_type != "ws":
|
||||||
raise VMwareError("Pausing a VM is only supported by VMware Workstation")
|
raise VMwareError("Pausing a VM is only supported by VMware Workstation")
|
||||||
yield from self._control_vm("pause")
|
yield from self._control_vm("pause")
|
||||||
|
self.status = "suspended"
|
||||||
log.info("VMware VM '{name}' [{id}] paused".format(name=self.name, id=self.id))
|
log.info("VMware VM '{name}' [{id}] paused".format(name=self.name, id=self.id))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -549,6 +552,7 @@ class VMwareVM(BaseNode):
|
|||||||
if self.manager.host_type != "ws":
|
if self.manager.host_type != "ws":
|
||||||
raise VMwareError("Unpausing a VM is only supported by VMware Workstation")
|
raise VMwareError("Unpausing a VM is only supported by VMware Workstation")
|
||||||
yield from self._control_vm("unpause")
|
yield from self._control_vm("unpause")
|
||||||
|
self.status = "started"
|
||||||
log.info("VMware VM '{name}' [{id}] resumed".format(name=self.name, id=self.id))
|
log.info("VMware VM '{name}' [{id}] resumed".format(name=self.name, id=self.id))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
Loading…
Reference in New Issue
Block a user