Class: Microsandbox::SnapshotInfo

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#digestString (readonly)

Returns manifest digest (“sha256:…”) — the canonical identity.

Returns:

  • (String)

    manifest digest (“sha256:…”) — the canonical identity



16
17
18
# File 'lib/microsandbox/snapshot.rb', line 16

def digest
  @digest
end

#fstypeString? (readonly)

Returns upper-layer filesystem type, e.g. “ext4” (manifest paths).

Returns:

  • (String, nil)

    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_digestString? (readonly)

Returns OCI manifest digest of the pinned image (manifest paths).

Returns:

  • (String, nil)

    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_refString? (readonly)

Returns source OCI image reference.

Returns:

  • (String, nil)

    source OCI image reference



24
25
26
# File 'lib/microsandbox/snapshot.rb', line 24

def image_ref
  @image_ref
end

#labelsHash{String=>String} (readonly)

Returns user labels ({} for index-only entries).

Returns:

  • (Hash{String=>String})

    user labels ({} for index-only entries)



32
33
34
# File 'lib/microsandbox/snapshot.rb', line 32

def labels
  @labels
end

#nameString? (readonly)

Returns name alias (nil for digest-only entries).

Returns:

  • (String, nil)

    name alias (nil for digest-only entries)



20
21
22
# File 'lib/microsandbox/snapshot.rb', line 20

def name
  @name
end

#parent_digestString? (readonly)

Returns parent snapshot digest.

Returns:

  • (String, nil)

    parent snapshot digest



22
23
24
# File 'lib/microsandbox/snapshot.rb', line 22

def parent_digest
  @parent_digest
end

#pathString (readonly)

Returns artifact directory path.

Returns:

  • (String)

    artifact directory path



18
19
20
# File 'lib/microsandbox/snapshot.rb', line 18

def path
  @path
end

#size_bytesInteger? (readonly)

Returns artifact size in bytes.

Returns:

  • (Integer, nil)

    artifact size in bytes



34
35
36
# File 'lib/microsandbox/snapshot.rb', line 34

def size_bytes
  @size_bytes
end

#source_sandboxString? (readonly)

Returns best-effort source-sandbox name, if recorded.

Returns:

  • (String, nil)

    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_atTime?

Returns:

  • (Time, nil)


57
58
59
# File 'lib/microsandbox/snapshot.rb', line 57

def created_at
  @created_at_ms && Time.at(@created_at_ms / 1000.0)
end

#formatSymbol?

Returns disk format (:raw or :qcow2).

Returns:

  • (Symbol, nil)

    disk format (:raw or :qcow2)



52
53
54
# File 'lib/microsandbox/snapshot.rb', line 52

def format
  @format&.to_sym
end

#inspectObject



76
77
78
# File 'lib/microsandbox/snapshot.rb', line 76

def inspect
  "#<Microsandbox::SnapshotInfo digest=#{@digest.inspect}#{" name=#{@name.inspect}" if @name}>"
end

#openSnapshotInfo

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.

Returns:



65
66
67
# File 'lib/microsandbox/snapshot.rb', line 65

def open
  Snapshot.open(@path || @digest)
end

#remove(force: false) ⇒ nil

Remove this snapshot’s artifact and its index row.

Parameters:

  • force (Boolean) (defaults to: false)

    remove even if it has indexed children

Returns:

  • (nil)


72
73
74
# File 'lib/microsandbox/snapshot.rb', line 72

def remove(force: false)
  Snapshot.remove(@path || @digest, force: force)
end