mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(instances): a VM a fault stopped or paused says why
libvirt gives each state its reason; the panel showed only the state, so a VM QEMU paused because its storage filled up read "Suspended" like one an administrator paused. - instances.states.REASONS: the fault reasons told (disk error, watchdog, guest crash or kernel panic, a crash of the guest or its QEMU process, libvirt stopping it after a restart, failed post-copy migration, libvirt error, failed start); the ordinary ones (user, migration, snapshot) are not - the lists read the reason with the state in their one getAllDomainStats call (get_domain_rows, get_domain_states: a change of reason reloads a list) and show it under the state badge - the VM page reads state and reason in one virDomainGetState (a reason means something only with its own state) and tells it in an alert; a VM paused by a disk error names each disk and what it met (virDomainGetDiskErrors), and when a storage has no free space, what to do: an administrator frees space and resumes it. Disk errors are read only then: libvirt keeps the last one after a resume. The page's poll reloads on a change of reason too Checked live on a Vagrant host: a guest filling a disk on a 40 MiB pool was paused (I/O error, vda: no space); the page said so, and after the pool grew and the VM was resumed the alert was gone.
This commit is contained in:
parent
7408a575d6
commit
bdc5569cc8
17 changed files with 330 additions and 18 deletions
|
|
@ -3,6 +3,9 @@ from django.db import models
|
|||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from libvirt import (
|
||||
VIR_DOMAIN_DISK_ERROR_NO_SPACE,
|
||||
VIR_DOMAIN_PAUSED,
|
||||
VIR_DOMAIN_PAUSED_IOERROR,
|
||||
VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL,
|
||||
VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL,
|
||||
libvirtError,
|
||||
|
|
@ -11,6 +14,8 @@ from operations import claims
|
|||
from operations.models import Claim
|
||||
from vrtManager.instance import PERSISTENT_XML, wvmInstance
|
||||
|
||||
from .states import DISK_ERRORS, REASONS
|
||||
|
||||
|
||||
class Flavor(models.Model):
|
||||
label = models.CharField(_("label"), max_length=12, unique=True)
|
||||
|
|
@ -81,6 +86,41 @@ class Instance(models.Model):
|
|||
except libvirtError:
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def state_and_reason(self) -> tuple:
|
||||
"""virDomainGetState: (state, reason) of one read, as a reason means
|
||||
something only with its own state; () if the VM cannot be read."""
|
||||
try:
|
||||
return tuple(self.proxy.get_state())
|
||||
except libvirtError:
|
||||
return ()
|
||||
|
||||
@cached_property
|
||||
def state_reason(self):
|
||||
"""Why the VM stopped or paused, when a fault did it (states.REASONS);
|
||||
else None. The lists set it from their one read of the host."""
|
||||
return REASONS.get(self.state_and_reason)
|
||||
|
||||
@cached_property
|
||||
def disk_errors(self) -> dict:
|
||||
"""{target: virDomainDiskErrorCode} of a VM a disk error paused; read
|
||||
only then, as libvirt keeps the last error after a resume."""
|
||||
if self.state_and_reason != (VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_IOERROR):
|
||||
return {}
|
||||
try:
|
||||
return self.proxy.get_disk_errors()
|
||||
except libvirtError:
|
||||
return {}
|
||||
|
||||
@property
|
||||
def disk_error_texts(self) -> list:
|
||||
return [DISK_ERRORS[code] % {"dev": dev} for dev, code in sorted(self.disk_errors.items()) if code in DISK_ERRORS]
|
||||
|
||||
@property
|
||||
def disk_full(self) -> bool:
|
||||
"""A disk error came from a storage with no free space: freeing some is the way out."""
|
||||
return VIR_DOMAIN_DISK_ERROR_NO_SPACE in self.disk_errors.values()
|
||||
|
||||
@cached_property
|
||||
def status(self) -> int:
|
||||
return self.proxy.get_status()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue