Class: Microsandbox::Volume

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

Overview

Management of named persistent volumes. Mount them into a sandbox via Sandbox.create(..., volumes: { "/data" => { named: "my-vol" } }).

Class Method Summary collapse

Class Method Details

.create(name, kind: "dir", size_mib: nil, quota_mib: nil, labels: nil) ⇒ VolumeInfo

Create a named volume.

Parameters:

  • name (String)
  • kind ("dir", "disk") (defaults to: "dir")

    storage kind (default "dir")

  • size_mib (Integer, nil) (defaults to: nil)

    required for kind "disk"

  • quota_mib (Integer, nil) (defaults to: nil)

    optional quota

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

Returns:



151
152
153
154
155
156
157
# File 'lib/microsandbox/volume.rb', line 151

def create(name, kind: "dir", size_mib: nil, quota_mib: nil, labels: nil)
  opts = {"kind" => kind.to_s}
  opts["size_mib"] = Integer(size_mib) if size_mib
  opts["quota_mib"] = Integer(quota_mib) if quota_mib
  opts["labels"] = labels.each_with_object({}) { |(k, v), a| a[k.to_s] = v.to_s } if labels
  VolumeInfo.new(Native::Volume.create(name.to_s, opts))
end

.fs(name) ⇒ VolumeFs

A host-side filesystem view over a named volume (read/write its contents without a running sandbox). The volume need not be mounted.

Returns:



189
190
191
# File 'lib/microsandbox/volume.rb', line 189

def fs(name)
  VolumeFs.new(Native::Volume.fs(name.to_s))
end

.get(name) ⇒ VolumeInfo

Metadata for a volume.

Returns:



161
162
163
# File 'lib/microsandbox/volume.rb', line 161

def get(name)
  VolumeInfo.new(Native::Volume.get(name.to_s))
end

.get_defaultVolumeInfo

The backend's default volume (runtime v0.6.9). Cloud backend only — the full Microsandbox::VolumeInfo#fs surface works against it; the local backend raises UnsupportedError to avoid accidental host access.

Returns:



169
170
171
# File 'lib/microsandbox/volume.rb', line 169

def get_default
  VolumeInfo.new(Native::Volume.get_default)
end

.listArray<VolumeInfo>

All volumes.

Returns:



175
176
177
# File 'lib/microsandbox/volume.rb', line 175

def list
  Native::Volume.list.map { |info| VolumeInfo.new(info) }
end

.remove(name) ⇒ nil

Remove a volume.

Returns:

  • (nil)


181
182
183
184
# File 'lib/microsandbox/volume.rb', line 181

def remove(name)
  Native::Volume.remove(name.to_s)
  nil
end