instance

package
v0.0.0-...-c012b7a Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsoleTypeConsole = "console"
	ConsoleTypeVGA     = "vga"
)

Possible values for the protocol argument of the Instance.Console() method.

View Source
const HookStart = "onstart"

HookStart hook used when instance has started.

View Source
const HookStop = "onstop"

HookStop hook used when instance has stopped.

View Source
const HookStopNS = "onstopns"

HookStopNS hook used when instance has stopped but before namespaces have been destroyed.

Variables

View Source
var Create func(s *state.State, args db.InstanceArgs, revert *revert.Reverter) (Instance, error)

Create is linked from instance/drivers.create to allow difference instance types to be created. Accepts a reverter that revert steps this function does will be added to. It is up to the caller to call the revert's Fail() or Success() function as needed.

View Source
var ErrNotImplemented = fmt.Errorf("Not implemented")

ErrNotImplemented is the "Not implemented" error

View Source
var Load func(s *state.State, args db.InstanceArgs, profiles []api.Profile) (Instance, error)

Load is linked from instance/drivers.load to allow different instance types to be loaded.

View Source
var ValidDevices func(state *state.State, cluster *db.Cluster, projectName string, instanceType instancetype.Type, devices deviceConfig.Devices, expanded bool) error

ValidDevices is linked from instance/drivers.validDevices to validate device config.

Functions

func AllowedUnprivilegedOnlyMap

func AllowedUnprivilegedOnlyMap(rawIdmap string) error

AllowedUnprivilegedOnlyMap checks that root user is not mapped into instance.

func BackupLoadByName

func BackupLoadByName(s *state.State, project, name string) (*backup.InstanceBackup, error)

BackupLoadByName load an instance backup from the database.

func CompareSnapshots

func CompareSnapshots(source Instance, target Instance) ([]Instance, []Instance, error)

CompareSnapshots returns a list of snapshots to sync to the target and a list of snapshots to remove from the target. A snapshot will be marked as "to sync" if it either doesn't exist in the target or its creation date is different to the source. A snapshot will be marked as "to delete" if it doesn't exist in the source or creation date is different to the source.

func DeleteSnapshots

func DeleteSnapshots(s *state.State, projectName, instanceName string) error

DeleteSnapshots calls the Delete() function on each of the supplied instance's snapshots.

func DeviceNextInterfaceHWAddr

func DeviceNextInterfaceHWAddr() (string, error)

DeviceNextInterfaceHWAddr generates a random MAC address.

func Filter

func Filter(instances []*api.Instance, clauses []filter.Clause) []*api.Instance

Filter returns a filtered list of instances that match the given clauses.

func FilterFull

func FilterFull(instances []*api.InstanceFull, clauses []filter.Clause) []*api.InstanceFull

FilterFull returns a filtered list of full instances that match the given clauses.

func LoadInstanceDatabaseObject

func LoadInstanceDatabaseObject(tx *db.ClusterTx, project, name string) (*db.Instance, error)

LoadInstanceDatabaseObject loads a db.Instance object, accounting for snapshots.

func NextSnapshotName

func NextSnapshotName(s *state.State, inst Instance, defaultPattern string) (string, error)

NextSnapshotName finds the next snapshot for an instance.

func ParseRawIdmap

func ParseRawIdmap(value string) ([]idmap.IdmapEntry, error)

ParseRawIdmap parses an IDMAP string.

func ResolveImage

func ResolveImage(s *state.State, project string, source api.InstanceSource) (string, error)

ResolveImage takes an instance source and returns a hash suitable for instance creation or download.

func SuitableArchitectures

func SuitableArchitectures(s *state.State, project string, req api.InstancesPost) ([]int, error)

SuitableArchitectures returns a slice of architecture ids based on an instance create request.

An empty list indicates that the request may be handled by any architecture. A nil list indicates that we can't tell at this stage, typically for private images.

func ValidConfig

func ValidConfig(sysOS *sys.OS, config map[string]string, profile bool, expanded bool) error

ValidConfig validates an instance's config.

func ValidName

func ValidName(instanceName string, isSnapshot bool) error

ValidName validates an instance name. There are different validation rules for instance snapshot names so it takes an argument indicating whether the name is to be used for a snapshot or not.

Types

type Cmd

type Cmd interface {
	Wait() (int, error)
	PID() int
	Signal(s unix.Signal) error
	WindowResize(fd, winchWidth, winchHeight int) error
}

Cmd represents a local or remote command being run.

type ConfigReader

type ConfigReader interface {
	Project() string
	Type() instancetype.Type
	Architecture() int
	ExpandedConfig() map[string]string
	ExpandedDevices() deviceConfig.Devices
	LocalConfig() map[string]string
	LocalDevices() deviceConfig.Devices
}

ConfigReader is used to read instance config.

type Container

type Container interface {
	Instance

	CurrentIdmap() (*idmap.IdmapSet, error)
	DiskIdmap() (*idmap.IdmapSet, error)
	NextIdmap() (*idmap.IdmapSet, error)
	ConsoleLog(opts liblxc.ConsoleLogOptions) (string, error)
	InsertSeccompUnixDevice(prefix string, m deviceConfig.Device, pid int) error
	DevptsFd() (*os.File, error)
	IdmappedStorage(path string) idmap.IdmapStorageType
}

Container interface is for container specific functions.

type CriuMigrationArgs

type CriuMigrationArgs struct {
	Cmd          uint
	StateDir     string
	Function     string
	Stop         bool
	ActionScript bool
	DumpDir      string
	PreDumpDir   string
	Features     liblxc.CriuFeatures
}

CriuMigrationArgs arguments for CRIU migration.

type Info

type Info struct {
	Name    string            // Name of an instance driver, e.g. "lxc"
	Version string            // Version number of a loaded instance driver
	Error   error             // Whether there is an operational impediment.
	Type    instancetype.Type // Instance type that the driver provides support for.
}

Info represents information about an instance driver.

type Instance

type Instance interface {
	ConfigReader

	// Instance actions.
	Freeze() error
	Shutdown(timeout time.Duration) error
	Start(stateful bool) error
	Stop(stateful bool) error
	Restart(timeout time.Duration) error
	Unfreeze() error
	RegisterDevices()
	SaveConfigFile() error

	Info() Info
	IsPrivileged() bool

	// Snapshots & migration & backups.
	Restore(source Instance, stateful bool) error
	Snapshot(name string, expiry time.Time, stateful bool) error
	Snapshots() ([]Instance, error)
	Backups() ([]backup.InstanceBackup, error)
	UpdateBackupFile() error

	// Config handling.
	Rename(newName string, applyTemplateTrigger bool) error
	Update(newConfig db.InstanceArgs, userRequested bool) error

	Delete(force bool) error
	Export(w io.Writer, properties map[string]string, expiration time.Time) (api.ImageMetadata, error)

	// Used for security.
	DevPaths() []string

	// Live configuration.
	CGroup() (*cgroup.CGroup, error)
	VolatileSet(changes map[string]string) error

	// File handling.
	FileExists(path string) error
	FilePull(srcpath string, dstpath string) (int64, int64, os.FileMode, string, []string, error)
	FilePush(fileType string, srcpath string, dstpath string, uid int64, gid int64, mode int, write string) error
	FileRemove(path string) error

	// Console - Allocate and run a console tty or a spice Unix socket.
	Console(protocol string) (*os.File, chan error, error)
	Exec(req api.InstanceExecPost, stdin *os.File, stdout *os.File, stderr *os.File) (Cmd, error)

	// Status
	Render(options ...func(response interface{}) error) (interface{}, interface{}, error)
	RenderFull() (*api.InstanceFull, interface{}, error)
	RenderState() (*api.InstanceState, error)
	IsRunning() bool
	IsFrozen() bool
	IsEphemeral() bool
	IsSnapshot() bool
	IsStateful() bool

	// Hooks.
	DeviceEventHandler(*deviceConfig.RunConfig) error
	OnHook(hookName string, args map[string]string) error

	// Properties.
	ID() int
	Location() string
	Name() string
	Description() string
	CreationDate() time.Time
	LastUsedDate() time.Time

	Profiles() []string
	InitPID() int
	State() string
	ExpiryDate() time.Time
	FillNetworkDevice(name string, m deviceConfig.Device) (deviceConfig.Device, error)

	// Paths.
	Path() string
	RootfsPath() string
	TemplatesPath() string
	StatePath() string
	LogFilePath() string
	ConsoleBufferLogPath() string
	LogPath() string
	DevicesPath() string

	// Storage.
	StoragePool() (string, error)

	// Migration.
	Migrate(args *CriuMigrationArgs) error

	// Progress reporting.
	SetOperation(op *operations.Operation)
	Operation() *operations.Operation

	DeferTemplateApply(trigger TemplateTrigger) error
}

Instance interface.

func CreateInternal

func CreateInternal(s *state.State, args db.InstanceArgs, revert *revert.Reverter) (Instance, error)

CreateInternal creates an instance record and storage volume record in the database and sets up devices. Accepts a reverter that revert steps this function does will be added to. It is up to the caller to call the revert's Fail() or Success() function as needed.

func LoadAllInternal

func LoadAllInternal(s *state.State, dbInstances []db.Instance) ([]Instance, error)

LoadAllInternal loads a list of db instances into a list of instances.

func LoadByID

func LoadByID(s *state.State, id int) (Instance, error)

LoadByID loads an instance by ID.

func LoadByProject

func LoadByProject(s *state.State, project string) ([]Instance, error)

LoadByProject loads all instances in a project.

func LoadByProjectAndName

func LoadByProjectAndName(s *state.State, project, name string) (Instance, error)

LoadByProjectAndName loads an instance by project and name.

func LoadFromAllProjects

func LoadFromAllProjects(s *state.State) ([]Instance, error)

LoadFromAllProjects loads all instances across all projects.

func LoadNodeAll

func LoadNodeAll(s *state.State, instanceType instancetype.Type) ([]Instance, error)

LoadNodeAll loads all instances of this nodes.

type TemplateTrigger

type TemplateTrigger string

TemplateTrigger trigger name.

const TemplateTriggerCopy TemplateTrigger = "copy"

TemplateTriggerCopy for when an instance is copied.

const TemplateTriggerCreate TemplateTrigger = "create"

TemplateTriggerCreate for when an instance is created.

const TemplateTriggerRename TemplateTrigger = "rename"

TemplateTriggerRename for when an instance is renamed.

Directories

Path Synopsis
qmp

Jump to

Keyboard shortcuts

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