instance

package
v0.0.0-...-49f7de5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

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) (Instance, error)

Create is linked from instance/drivers.create to allow difference instance types to be created.

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, 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.Backup, 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 ParseCpuset

func ParseCpuset(cpu string) ([]int, error)

ParseCpuset parses a limits.cpu range into a list of CPU ids.

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 {
	Type() instancetype.Type
	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
}

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 Instance

type Instance interface {
	ConfigReader

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

	IsPrivileged() bool

	// Snapshots & migration & backups.
	Restore(source Instance, stateful bool) error
	Snapshots() ([]Instance, error)
	Backups() ([]backup.Backup, error)
	UpdateBackupFile() error

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

	Delete() error
	Export(w io.Writer, properties map[string]string) error

	// Live configuration.
	CGroupSet(key string, value string) 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.
	Console() (*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
	Project() string
	Name() string
	Description() string
	Architecture() int
	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)

	// FIXME: Those should be internal functions.
	// Needed for migration for now.
	StorageStart() (bool, error)
	StorageStop() (bool, error)
	DeferTemplateApply(trigger string) error
}

Instance interface.

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.

Directories

Path Synopsis
qmp

Jump to

Keyboard shortcuts

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