Class: Microsandbox::SnapshotInfo
- Inherits:
-
Object
- Object
- Microsandbox::SnapshotInfo
- Defined in:
- lib/microsandbox/snapshot.rb
Overview
Metadata for a snapshot artifact, returned by Microsandbox::Snapshot.create/Microsandbox::Snapshot.open/ Microsandbox::Snapshot.get/Microsandbox::Snapshot.list/Microsandbox::Snapshot.list_dir/Microsandbox::Snapshot.import.
‘digest` and `path` are always present. The artifact-opening paths (`create`/`open`/`list_dir`, and Microsandbox::SandboxHandle#snapshot) carry the full manifest — `size_bytes`, `image_ref`, `image_manifest_digest`, `format`, `fstype`, `parent_digest`, `created_at`, `source_sandbox`, and `labels`. The index paths (`get`/`list`/`import`) populate `name`, `parent_digest`, `image_ref`, `format`, `size_bytes`, and `created_at` (manifest-only fields such as `fstype`/`source_sandbox`/`labels` are nil/empty there).
Instance Attribute Summary collapse
-
#digest ⇒ String
readonly
Manifest digest (“sha256:…”) — the canonical identity.
-
#fstype ⇒ String?
readonly
Upper-layer filesystem type, e.g.
-
#image_manifest_digest ⇒ String?
readonly
OCI manifest digest of the pinned image (manifest paths).
-
#image_ref ⇒ String?
readonly
Source OCI image reference.
-
#labels ⇒ Hash{String=>String}
readonly
User labels ({} for index-only entries).
-
#name ⇒ String?
readonly
Name alias (nil for digest-only entries).
-
#parent_digest ⇒ String?
readonly
Parent snapshot digest.
-
#path ⇒ String
readonly
Artifact directory path.
-
#size_bytes ⇒ Integer?
readonly
Artifact size in bytes.
-
#source_sandbox ⇒ String?
readonly
Best-effort source-sandbox name, if recorded.
Instance Method Summary collapse
- #created_at ⇒ Time?
-
#format ⇒ Symbol?
Disk format (:raw or :qcow2).
-
#initialize(data) ⇒ SnapshotInfo
constructor
A new instance of SnapshotInfo.
- #inspect ⇒ Object
-
#open ⇒ SnapshotInfo
Re-open this snapshot’s artifact (cheap metadata validation), returning a fully-populated SnapshotInfo.
-
#remove(force: false) ⇒ nil
Remove this snapshot’s artifact and its index row.
Constructor Details
#initialize(data) ⇒ SnapshotInfo
Returns a new instance of SnapshotInfo.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/microsandbox/snapshot.rb', line 36 def initialize(data) @digest = data["digest"] @path = data["path"] @name = data["name"] @parent_digest = data["parent_digest"] @image_ref = data["image_ref"] @image_manifest_digest = data["image_manifest_digest"] @fstype = data["fstype"] @source_sandbox = data["source_sandbox"] @labels = data["labels"] || {} @format = data["format"] @size_bytes = data["size_bytes"] @created_at_ms = data["created_at_ms"] end |
Instance Attribute Details
#digest ⇒ String (readonly)
Returns manifest digest (“sha256:…”) — the canonical identity.
16 17 18 |
# File 'lib/microsandbox/snapshot.rb', line 16 def digest @digest end |
#fstype ⇒ String? (readonly)
Returns upper-layer filesystem type, e.g. “ext4” (manifest paths).
28 29 30 |
# File 'lib/microsandbox/snapshot.rb', line 28 def fstype @fstype end |
#image_manifest_digest ⇒ String? (readonly)
Returns OCI manifest digest of the pinned image (manifest paths).
26 27 28 |
# File 'lib/microsandbox/snapshot.rb', line 26 def image_manifest_digest @image_manifest_digest end |
#image_ref ⇒ String? (readonly)
Returns source OCI image reference.
24 25 26 |
# File 'lib/microsandbox/snapshot.rb', line 24 def image_ref @image_ref end |
#labels ⇒ Hash{String=>String} (readonly)
Returns user labels ({} for index-only entries).
32 33 34 |
# File 'lib/microsandbox/snapshot.rb', line 32 def labels @labels end |
#name ⇒ String? (readonly)
Returns name alias (nil for digest-only entries).
20 21 22 |
# File 'lib/microsandbox/snapshot.rb', line 20 def name @name end |
#parent_digest ⇒ String? (readonly)
Returns parent snapshot digest.
22 23 24 |
# File 'lib/microsandbox/snapshot.rb', line 22 def parent_digest @parent_digest end |
#path ⇒ String (readonly)
Returns artifact directory path.
18 19 20 |
# File 'lib/microsandbox/snapshot.rb', line 18 def path @path end |
#size_bytes ⇒ Integer? (readonly)
Returns artifact size in bytes.
34 35 36 |
# File 'lib/microsandbox/snapshot.rb', line 34 def size_bytes @size_bytes end |
#source_sandbox ⇒ String? (readonly)
Returns best-effort source-sandbox name, if recorded.
30 31 32 |
# File 'lib/microsandbox/snapshot.rb', line 30 def source_sandbox @source_sandbox end |
Instance Method Details
#created_at ⇒ Time?
57 58 59 |
# File 'lib/microsandbox/snapshot.rb', line 57 def created_at @created_at_ms && Time.at(@created_at_ms / 1000.0) end |
#format ⇒ Symbol?
Returns disk format (:raw or :qcow2).
52 53 54 |
# File 'lib/microsandbox/snapshot.rb', line 52 def format @format&.to_sym end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/microsandbox/snapshot.rb', line 76 def inspect "#<Microsandbox::SnapshotInfo digest=#{@digest.inspect}#{" name=#{@name.inspect}" if @name}>" end |
#open ⇒ SnapshotInfo
Re-open this snapshot’s artifact (cheap metadata validation), returning a fully-populated Microsandbox::SnapshotInfo. Addresses by path, so it works even for artifacts that were never added to the local index.
65 66 67 |
# File 'lib/microsandbox/snapshot.rb', line 65 def open Snapshot.open(@path || @digest) end |