Add snapshot description support (#3094)

Pass the description when creating a snapshot instead of silently
dropping it, and add a PUT endpoint to edit the description later.
An empty description resets to the default text. Also accept an
optional description in the MCP snapshot_create tool.
This commit is contained in:
Guobin Yue authored and GitHub committed 2026-11-16 14:24:20 +01:00
1 parent fe51feec66
commit 8411392233
9 files changed
+148 -11

No files matched your search

+17 -2
View File
@@ -1614,21 +1614,36 @@ class Project:
log.error(f"Cannot write snapshot config '{self._snapshot_conf_path}': {e}")
@open_required
async def snapshot(self, name):
async def snapshot(self, name, description=None):
"""
Snapshot the project
:param name: Name of the snapshot
:param description: Description of the snapshot
"""
if name in [snap.name for snap in self._snapshots.values()]:
raise ControllerError(f"The snapshot name {name} already exists")
snapshot = Snapshot(self, name=name)
snapshot = Snapshot(self, name=name, description=description)
await snapshot.create()
self._snapshots[snapshot.id] = snapshot
self._save_snapshot_config()
return snapshot
@open_required
def update_snapshot(self, snapshot_id, description=None):
"""
Update a snapshot, for example its description
:param snapshot_id: ID of the snapshot
:param description: New description of the snapshot
"""
snapshot = self.get_snapshot(snapshot_id)
snapshot.update(description=description)
self._save_snapshot_config()
return snapshot
@open_required
async def delete_snapshot(self, snapshot_id):
snapshot = self.get_snapshot(snapshot_id)
+23 -6
View File
@@ -74,12 +74,7 @@ class Snapshot:
)
if not description:
date = (
datetime.fromtimestamp(self._created_at, tz=UTC)
.replace(tzinfo=None)
.strftime(DESCRIPTION_DATETIME_FORMAT)
)
description = f"Snapshot '{self._name}' taken on {date}"
description = self._default_description()
self._description = description
self._filename = filename
@@ -105,6 +100,28 @@ class Snapshot:
def created_at(self):
return self._created_at
def _default_description(self) -> str:
"""
Return the default description of the snapshot.
"""
date = (
datetime.fromtimestamp(self._created_at, tz=UTC).replace(tzinfo=None).strftime(DESCRIPTION_DATETIME_FORMAT)
)
return f"Snapshot '{self._name}' taken on {date}"
def update(self, description: str | None = None) -> None:
"""
Update the snapshot description. An empty or null description
resets it to the default one.
:param description: New description of the snapshot
"""
if not description:
description = self._default_description()
self._description = description
async def create(self):
"""
Create the snapshot