1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

feat(instances): external snapshots first, internal ones a fallback

The Snapshots tab had three sub-tabs: internal, external and the
lists, with the two kinds side by side as equals. The owner set the
direction: external snapshots are the way; internal ones pause the VM
while its memory is saved and can take long, so they stay only as a
fallback for a VM that cannot take an external one.

The tab now has the external snapshot form on top, its name and
description on one line, with its memory and freeze options; the
internal snapshot under a folded "fallback" line with its warning; and
one list of all snapshots, newest first, each on one line with its
name, description, kind and date, and Revert and Delete.

Codex reviewed snapshots end to end; these are fixed:

- The pause and memory lines follow the VM's state and the kind.
- An internal snapshot is reverted to on a shut-off VM only, on the
  server too; the tab alone held that rule.
- A paused VM's revert says it comes back paused, not that it starts.
- An external snapshot waits, with the reason, while snapshots newer
  than the one reverted to exist; the server refused it unexplained.
- Deleting an external snapshot says its files are merged with the
  disks; "into the next one" was wrong for the last one.
- The description has no 45-character limit only the browser kept.
- Freezing is not shown ticked where it cannot be offered, and
  unticking memory gives back the earlier freeze choice.
- Internal create, revert and delete refuse a saved state or a running
  disk job, as external ones do.
This commit is contained in:
catborise 2026-10-30 21:40:00 +03:00
parent 60f12cefa1
commit 7fc55537e5
7 changed files with 186 additions and 203 deletions

View file

@ -296,12 +296,20 @@ class Instance(models.Model):
return self.proxy.get_video_models(self.arch, self.machine)
def _snapshots(self, flag):
return sorted(self.proxy.get_snapshot(flag), reverse=True, key=lambda k: k["date"])
external = flag == VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL
return sorted(({**snap, "external": external} for snap in self.proxy.get_snapshot(flag)),
reverse=True, key=lambda k: k["date"])
@cached_property
def snapshots(self) -> list[dict]:
"""Both kinds, the newest first; "external" tells them apart."""
return sorted(self.internal_snapshots + self.external_snapshots, reverse=True, key=lambda k: k["date"])
@cached_property
def newer_than_current_snapshot(self) -> bool:
"""Snapshots newer than the one reverted to: an external snapshot waits until they are deleted."""
return any(snap["current"] and snap["children"] for snap in self.external_snapshots)
@cached_property
def internal_snapshots(self) -> list[dict]:
return self._snapshots(VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL)