Miosa.Checkpoints (Miosa v1.0.1)

Copy Markdown View Source

Create and restore disk snapshots (checkpoints) of MIOSA computers.

A checkpoint captures the full disk state of a computer at a point in time. Restoring a checkpoint rolls the computer back to that exact state.

Example

{:ok, snap} = Miosa.Checkpoints.create(client, computer_id, %{
  name: "before-deploy"
})

{:ok, snaps} = Miosa.Checkpoints.list(client, computer_id)
{:ok, snap} = Miosa.Checkpoints.get(client, computer_id, snap.id)

# Restore with optional SSE progress streaming
:ok = Miosa.Checkpoints.restore(client, computer_id, snap.id)

# Stream restore progress events
events = Miosa.Checkpoints.restore_stream(client, computer_id, snap.id)
Enum.each(events, fn event -> IO.inspect(event) end)

:ok = Miosa.Checkpoints.delete(client, computer_id, snap.id)

Summary

Functions

Creates a new checkpoint (snapshot) of a computer's disk state.

Deletes a checkpoint permanently.

Fetches a single checkpoint by ID.

Lists all checkpoints for a computer, ordered by creation time (newest first).

Restores a computer to a checkpoint state (fire-and-forget).

Restores a checkpoint and returns a Stream of progress events.

Types

create_params()

@type create_params() :: %{
  optional(:name) => String.t(),
  optional(:description) => String.t()
}

Functions

create(client, computer_id, params \\ %{})

Creates a new checkpoint (snapshot) of a computer's disk state.

The computer should be stopped or in a consistent state before snapshotting.

Params

  • :name — Optional display name.
  • :description — Optional description of what this snapshot represents.

delete(client, computer_id, snapshot_id)

@spec delete(Miosa.Client.t(), String.t(), String.t()) ::
  :ok | {:error, Miosa.Error.t()}

Deletes a checkpoint permanently.

get(client, computer_id, snapshot_id)

Fetches a single checkpoint by ID.

list(client, computer_id)

Lists all checkpoints for a computer, ordered by creation time (newest first).

restore(client, computer_id, snapshot_id)

@spec restore(Miosa.Client.t(), String.t(), String.t()) ::
  :ok | {:error, Miosa.Error.t()}

Restores a computer to a checkpoint state (fire-and-forget).

The API will stop the computer (if running), restore the disk, and restart it. Returns :ok once the restore request is accepted.

Use restore_stream/3 to receive incremental progress events via an Elixir Stream.

restore_stream(client, computer_id, snapshot_id)

@spec restore_stream(Miosa.Client.t(), String.t(), String.t()) :: Enumerable.t()

Restores a checkpoint and returns a Stream of progress events.

Each element yielded by the stream is a map with at least :event and :data keys. The stream ends when the restore completes or fails.

Example

stream = Miosa.Checkpoints.restore_stream(client, computer_id, snap_id)
Enum.each(stream, fn %{event: e, data: d} -> IO.puts("#{e}: #{inspect(d)}") end)