-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshots.py
More file actions
33 lines (23 loc) · 905 Bytes
/
snapshots.py
File metadata and controls
33 lines (23 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from leap0 import Leap0Client, Sandbox, Snapshot
def main() -> None:
client = Leap0Client()
sandbox: Sandbox = client.sandboxes.create()
try:
sandbox.filesystem.write_file(path="/workspace/checkpoint.txt", content="before snapshot\n")
snapshot: Snapshot = sandbox.create_snapshot(name="example-checkpoint")
print("snapshot:", snapshot.id)
restored: Sandbox = client.snapshots.restore(snapshot_name=snapshot.name)
try:
content = restored.filesystem.read_file(path="/workspace/checkpoint.txt")
print("restored file:", content.strip())
finally:
restored.delete()
finally:
sandbox.delete()
client.close()
if __name__ == "__main__":
main()