image

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2017 License: MPL-2.0 Imports: 20 Imported by: 0

README

Image Format Specification

An image file: image.tar.zst is an zstd compressed tar-ball containing the following files:

  • disk.img, raw disk image (as sparse file).
  • layer.qcow2, qcow2 file with disk.img as backing file.
  • machine.json, JSON definition of machine configuration.

When constructing the tar-ball it's important to use GNU tar with the -S option to ensure sparse file support.

Documentation

Overview

Package image exposes methods and abstractions for extracting and managing virtual machine images. Amongst other things this involves securing that the images don't reference external files as backing store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomMAC

func RandomMAC() string

RandomMAC generates a new random MAC with the local bit set.

Types

type Downloader

type Downloader func(imageFile *os.File) error

Downloader is a function capable of downloading an image to an *os.File. The downloader writes the image file to the imageFile supplied, and returns an error if all retries etc. fails.

func DownloadImage

func DownloadImage(url string) Downloader

DownloadImage returns a Downloader that will download the image from the given url. This will attempt multiple retries if necessary.

If there is a non-200 response this will return a MalformedPayloadError.

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance represents an instance of an image.

func (*Instance) DiskFile

func (i *Instance) DiskFile() string

DiskFile returns the qcow2 file this image instance is backed by.

func (*Instance) Format

func (i *Instance) Format() string

Format returns the image format: 'qcow2'

func (*Instance) Machine

func (i *Instance) Machine() vm.Machine

Machine returns the virtual machine configuration for this instance.

func (*Instance) Release

func (i *Instance) Release()

Release frees the resources held by an instance.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager loads and tracks images.

func NewManager

func NewManager(imageFolder string, gc gc.ResourceTracker, monitor runtime.Monitor) (*Manager, error)

NewManager creates a new image manager using the imageFolder for storing images and instances of images.

func (*Manager) Instance

func (m *Manager) Instance(imageID string, download Downloader) (*Instance, error)

Instance will return an Instance of the image with imageID. If no such image exists in the cache, download() will be called to download it to a temporary filename.

This method will insert the downloaded image into the cache, and ensures that if won't be downloaded twice, if another invocation already is downloading an image with the same imageID.

It is the responsibility of the caller to make sure that imageID is a string that uniquely identifies the image. Sane patterns includes "url:<url>", or "taskId:<taskId>/<runId>/<artifact>". It also the callers responsibility to enforce any sort of access control.

type MutableImage

type MutableImage struct {
	// contains filtered or unexported fields
}

MutableImage is an vm.MutableImage implementation that keeps the image in a single folder. This can be used for testing images and building new images.

func NewMutableImage

func NewMutableImage(folder string, size int, machine *vm.Machine) (*MutableImage, error)

NewMutableImage creates a new blank MutableImage of given size in GiB, and using the given machine configuration.

This is used when building new images.

func NewMutableImageFromFile

func NewMutableImageFromFile(imageFile, imageFolder string) (*MutableImage, error)

NewMutableImageFromFile creates a mutable image from an existing compressed image tar archive.

func (*MutableImage) DiskFile

func (img *MutableImage) DiskFile() string

DiskFile returns path to disk file to use in QEMU. This also marks the image as being in-use.

func (*MutableImage) Dispose

func (img *MutableImage) Dispose()

Dispose will delete all resources hold by the MutableImage

func (*MutableImage) Format

func (img *MutableImage) Format() string

Format returns the image format: 'raw'.

func (*MutableImage) Machine

func (img *MutableImage) Machine() vm.Machine

Machine returns the vm.Machine definition of the virtual machine.

func (*MutableImage) Package

func (img *MutableImage) Package(targetFile string) error

Package will write an zstd compressed tar archive of the image to targetFile. This method cannot be called the image is in-use.

func (*MutableImage) Release

func (img *MutableImage) Release()

Release marks the MutableImage as no longer in use. This allows Package() or Dispose() to be called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL