Method: Hyperkit::Client::Images#create_image_from_snapshot

Defined in:
lib/hyperkit/client/images.rb

#create_image_from_snapshot(container, snapshot, options = {}) ⇒ Sawyer::Resource

Create an image from an existing snapshot.

Examples:

Create a private image from snapshot ‘test-container/snapshot1’

Hyperkit.create_image_from_snapshot("test-container", "snapshot1")

Create a public image from snapshot ‘test-container/snapshot1’

Hyperkit.create_image_from_snapshot("test-container", "snapshot1", public: true)

Store properties with the new image, and override its filename

Hyperkit.create_image_from_snapshot("test-container", "snapshot1",
  filename: "ubuntu-trusty.tar.gz",
  properties: {
    os: "ubuntu"
    codename: "trusty"
    version: "14.04"
  }
)

Parameters:

  • container (String)

    Source container name

  • snapshot (String)

    Source snapshot name

  • options (Hash) (defaults to: {})

    Additional data to be passed

Options Hash (options):

  • :filename (String)

    Tarball filename to store with the image on the server and used when exporting the image (default: name of file being uploaded).

  • :public (Boolean)

    Whether or not the image should be publicly-accessible by unauthenticated users (default: false).

  • :properties (Hash)

    Hash of additional properties to store with the image

  • :sync (Boolean)

    If false, returns an asynchronous operation that must be passed to Operations#wait_for_operation. If true, automatically waits and returns the result of the operation. Defaults to value of Hyperkit::Configurable#auto_sync.

Returns:

  • (Sawyer::Resource)

    Operation or result, depending value of :sync parameter and/or auto_sync

Asynchronous:



358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/hyperkit/client/images.rb', line 358

def create_image_from_snapshot(container, snapshot, options={})

  opts = options.slice(:filename, :public, :description)
  opts[:properties] = stringify_hash(options[:properties]) if options[:properties]
  opts[:source] = {
    type: "snapshot",
    name: "#{container}/#{snapshot}"
  }

  response = post(images_path, opts).
  handle_async(response, options[:sync])
end