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:



143
144
145
146
147
148
149
# File 'lib/microsandbox/volume.rb', line 143

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:



173
174
175
# File 'lib/microsandbox/volume.rb', line 173

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

.get(name) ⇒ VolumeInfo

Metadata for a volume.

Returns:



153
154
155
# File 'lib/microsandbox/volume.rb', line 153

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

.listArray<VolumeInfo>

All volumes.

Returns:



159
160
161
# File 'lib/microsandbox/volume.rb', line 159

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

.remove(name) ⇒ nil

Remove a volume.

Returns:

  • (nil)


165
166
167
168
# File 'lib/microsandbox/volume.rb', line 165

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