Class: Microsandbox::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/microsandbox/snapshot.rb

Overview

Creation and management of sandbox snapshots. A snapshot captures a stopped sandbox’s upper layer into a portable artifact; boot from it with ‘Sandbox.create(from_snapshot: “name-or-digest”)`.

Class Method Summary collapse

Class Method Details

.create(source_sandbox, name: nil, path: nil, labels: nil, force: false, record_integrity: false) ⇒ SnapshotInfo

Create a snapshot of a stopped sandbox.

Parameters:

  • source_sandbox (String)

    name of the (stopped) source sandbox

  • name (String, nil) (defaults to: nil)

    destination name under the snapshots dir

  • path (String, nil) (defaults to: nil)

    explicit destination directory (alternative to name)

  • labels (Hash, nil) (defaults to: nil)

    user labels

  • force (Boolean) (defaults to: false)

    overwrite an existing artifact at the destination

  • record_integrity (Boolean) (defaults to: false)

    compute + record upper-layer integrity

Returns:



91
92
93
94
95
96
97
98
99
# File 'lib/microsandbox/snapshot.rb', line 91

def create(source_sandbox, name: nil, path: nil, labels: nil, force: false, record_integrity: false)
  opts = {}
  opts["name"] = name.to_s if name
  opts["path"] = path.to_s if path
  opts["labels"] = stringify(labels) if labels
  opts["force"] = true if force
  opts["record_integrity"] = true if record_integrity
  SnapshotInfo.new(Native::Snapshot.create(source_sandbox.to_s, opts))
end

.export(name_or_path, out_path, with_parents: false, with_image: false, plain_tar: false) ⇒ nil

Bundle a snapshot into a ‘.tar.zst` (or plain `.tar`) archive.

Parameters:

  • with_parents (Boolean) (defaults to: false)

    include ancestor snapshots

  • with_image (Boolean) (defaults to: false)

    include OCI image artifacts (boots offline)

  • plain_tar (Boolean) (defaults to: false)

    write an uncompressed ‘.tar`

Returns:

  • (nil)


132
133
134
135
136
137
138
139
# File 'lib/microsandbox/snapshot.rb', line 132

def export(name_or_path, out_path, with_parents: false, with_image: false, plain_tar: false)
  opts = {}
  opts["with_parents"] = true if with_parents
  opts["with_image"] = true if with_image
  opts["plain_tar"] = true if plain_tar
  Native::Snapshot.export(name_or_path.to_s, out_path.to_s, opts)
  nil
end

.get(name_or_digest) ⇒ SnapshotInfo

Metadata for a snapshot by name or digest.

Returns:



103
104
105
# File 'lib/microsandbox/snapshot.rb', line 103

def get(name_or_digest)
  SnapshotInfo.new(Native::Snapshot.get(name_or_digest.to_s))
end

.import(archive_path, dest: nil) ⇒ SnapshotInfo

Unpack a snapshot archive into the snapshots dir.

Parameters:

  • dest (String, nil) (defaults to: nil)

    explicit destination directory

Returns:



144
145
146
# File 'lib/microsandbox/snapshot.rb', line 144

def import(archive_path, dest: nil)
  SnapshotInfo.new(Native::Snapshot.import(archive_path.to_s, dest && dest.to_s))
end

.listArray<SnapshotInfo>

All snapshots.

Returns:



109
110
111
# File 'lib/microsandbox/snapshot.rb', line 109

def list
  Native::Snapshot.list.map { |info| SnapshotInfo.new(info) }
end

.remove(name_or_path, force: false) ⇒ nil

Remove a snapshot artifact by name or path.

Parameters:

  • force (Boolean) (defaults to: false)

    remove even if referenced

Returns:

  • (nil)


116
117
118
119
# File 'lib/microsandbox/snapshot.rb', line 116

def remove(name_or_path, force: false)
  Native::Snapshot.remove(name_or_path.to_s, force)
  nil
end

.verify(name_or_path) ⇒ SnapshotVerifyReport

Verify a snapshot’s recorded upper-layer integrity.



123
124
125
# File 'lib/microsandbox/snapshot.rb', line 123

def verify(name_or_path)
  SnapshotVerifyReport.new(Native::Snapshot.verify(name_or_path.to_s))
end