Documentation ¶
Index ¶
- Constants
- Variables
- func AllowedUnprivilegedOnlyMap(rawIdmap string) error
- func BackupLoadByName(s *state.State, project, name string) (*backup.InstanceBackup, error)
- func DeviceNextInterfaceHWAddr() (string, error)
- func FilterFull(instances []*api.InstanceFull, clauses filter.ClauseSet) ([]*api.InstanceFull, error)
- func IsSameLogicalInstance(inst Instance, dbInst *db.InstanceArgs) bool
- func LoadInstanceDatabaseObject(ctx context.Context, tx *db.ClusterTx, project, name string) (*cluster.Instance, error)
- func MoveTemporaryName(inst Instance) (string, error)
- func NextSnapshotName(s *state.State, inst Instance, defaultPattern string) (string, error)
- func ResolveImage(ctx context.Context, tx *db.ClusterTx, projectName string, ...) (string, error)
- func ResourceUsage(instConfig map[string]string, instDevices map[string]map[string]string, ...) (int64, int64, int64, error)
- func SnapshotProtobufToInstanceArgs(s *state.State, inst Instance, snap *migration.Snapshot) (*db.InstanceArgs, error)
- func SnapshotToProtobuf(snap *api.InstanceSnapshot) *migration.Snapshot
- func SuitableArchitectures(ctx context.Context, s *state.State, tx *db.ClusterTx, projectName string, ...) ([]int, error)
- func ValidConfig(sysOS *sys.OS, config map[string]string, expanded bool, ...) error
- func ValidName(instanceName string, isSnapshot bool) error
- type Cmd
- type ConfigReader
- type Container
- type CriuMigrationArgs
- type Info
- type Instance
- func CreateInternal(s *state.State, args db.InstanceArgs, op *operations.Operation, ...) (Instance, *operationlock.InstanceOperation, revert.Hook, error)
- func LoadByID(s *state.State, id int) (Instance, error)
- func LoadByProjectAndName(s *state.State, projectName string, instanceName string) (Instance, error)
- func LoadFromBackup(s *state.State, projectName string, instancePath string, applyProfiles bool) (Instance, error)
- func LoadNodeAll(s *state.State, instanceType instancetype.Type) ([]Instance, error)
- type MigrateArgs
- type MigrateReceiveArgs
- type MigrateSendArgs
- type TemplateTrigger
- type VM
Constants ¶
const ( ConsoleTypeConsole = "console" ConsoleTypeVGA = "vga" )
Possible values for the protocol argument of the Instance.Console() method.
const HookStart = "onstart"
HookStart hook used when instance has started.
const HookStop = "onstop"
HookStop hook used when instance has stopped.
const HookStopNS = "onstopns"
HookStopNS hook used when instance has stopped but before namespaces have been destroyed.
const PowerStateRunning = "RUNNING"
PowerStateRunning represents the power state stored when an instance is running.
const PowerStateStopped = "STOPPED"
PowerStateStopped represents the power state stored when an instance is stopped.
Variables ¶
var Create func(s *state.State, args db.InstanceArgs, p api.Project, op *operations.Operation) (Instance, revert.Hook, error)
Create is linked from instance/drivers.create to allow difference instance types to be created. Returns a revert fail function that can be used to undo this function if a subsequent step fails.
var ErrNotImplemented = fmt.Errorf("Not implemented")
ErrNotImplemented is the "Not implemented" error.
var Load func(s *state.State, args db.InstanceArgs, p api.Project) (Instance, error)
Load is linked from instance/drivers.load to allow different instance types to be loaded.
var ValidDevices func(state *state.State, p api.Project, instanceType instancetype.Type, localDevices deviceConfig.Devices, expandedDevices deviceConfig.Devices) error
ValidDevices is linked from instance/drivers.validDevices to validate device config.
Functions ¶
func AllowedUnprivilegedOnlyMap ¶
AllowedUnprivilegedOnlyMap checks that root user is not mapped into instance.
func BackupLoadByName ¶
BackupLoadByName load an instance backup from the database.
func DeviceNextInterfaceHWAddr ¶
DeviceNextInterfaceHWAddr generates a random MAC address.
func FilterFull ¶
func FilterFull(instances []*api.InstanceFull, clauses filter.ClauseSet) ([]*api.InstanceFull, error)
FilterFull returns a filtered list of full instances that match the given clauses.
func IsSameLogicalInstance ¶
func IsSameLogicalInstance(inst Instance, dbInst *db.InstanceArgs) bool
IsSameLogicalInstance returns true if the supplied Instance and db.Instance have the same project and name or if they have the same volatile.uuid values.
func LoadInstanceDatabaseObject ¶
func LoadInstanceDatabaseObject(ctx context.Context, tx *db.ClusterTx, project, name string) (*cluster.Instance, error)
LoadInstanceDatabaseObject loads a db.Instance object, accounting for snapshots.
func MoveTemporaryName ¶
MoveTemporaryName returns a name derived from the instance's volatile.uuid, to use when moving an instance across pools or cluster members which can be used for the naming the temporary copy before deleting the original instance and renaming the copy to the original name. If volatile.uuid is not set, a new UUID is generated and stored in the instance's config.
func NextSnapshotName ¶
NextSnapshotName finds the next snapshot for an instance.
func ResolveImage ¶
func ResolveImage(ctx context.Context, tx *db.ClusterTx, projectName string, source api.InstanceSource) (string, error)
ResolveImage takes an instance source and returns a hash suitable for instance creation or download.
func ResourceUsage ¶ added in v6.7.0
func ResourceUsage(instConfig map[string]string, instDevices map[string]map[string]string, instType api.InstanceType) (int64, int64, int64, error)
ResourceUsage returns an instance's expected CPU, memory and disk usage.
func SnapshotProtobufToInstanceArgs ¶
func SnapshotProtobufToInstanceArgs(s *state.State, inst Instance, snap *migration.Snapshot) (*db.InstanceArgs, error)
SnapshotProtobufToInstanceArgs converts a migration snapshot record to DB instance record format.
func SnapshotToProtobuf ¶
func SnapshotToProtobuf(snap *api.InstanceSnapshot) *migration.Snapshot
SnapshotToProtobuf converts a snapshot record to a migration snapshot record.
func SuitableArchitectures ¶
func SuitableArchitectures(ctx context.Context, s *state.State, tx *db.ClusterTx, projectName string, sourceInst *cluster.Instance, sourceImageRef 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, expanded bool, instanceType instancetype.Type) error
ValidConfig validates an instance's config.
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() api.Project Type() instancetype.Type Architecture() int ID() 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.Set, error) DiskIdmap() (*idmap.Set, error) NextIdmap() (*idmap.Set, error) ConsoleLog(opts liblxc.ConsoleLogOptions) (string, error) InsertSeccompUnixDevice(prefix string, m deviceConfig.Device, pid int) error DevptsFd() (*os.File, error) IdmappedStorage(path string, fstype 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 Op *operationlock.InstanceOperation }
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. Features map[string]any // Map of supported features. }
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 Rebuild(img *api.Image, op *operations.Operation) error Unfreeze() error RegisterDevices() 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, tracker *ioprogress.ProgressTracker) (*api.ImageMetadata, error) // Live configuration. CGroup() (*cgroup.CGroup, error) VolatileSet(changes map[string]string) error // File handling. FileSFTPConn() (net.Conn, error) FileSFTP() (*sftp.Client, 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 any) error) (any, any, error) RenderFull(hostInterfaces []net.Interface) (*api.InstanceFull, any, error) RenderState(hostInterfaces []net.Interface) (*api.InstanceState, error) IsRunning() bool IsFrozen() bool IsEphemeral() bool IsSnapshot() bool IsStateful() bool LockExclusive() (*operationlock.InstanceOperation, error) // Hooks. DeviceEventHandler(*deviceConfig.RunConfig) error OnHook(hookName string, args map[string]string) error // Properties. Location() string Name() string CloudInitID() string Description() string CreationDate() time.Time LastUsedDate() time.Time Profiles() []api.Profile InitPID() int State() string ExpiryDate() time.Time FillNetworkDevice(name string, m deviceConfig.Device) (deviceConfig.Device, error) // Paths. Path() string ExecOutputPath() string RootfsPath() string TemplatesPath() string StatePath() string LogFilePath() string ConsoleBufferLogPath() string LogPath() string RunPath() string DevicesPath() string // Storage. StoragePool() (string, error) // Migration. CanMigrate() string MigrateSend(args MigrateSendArgs) error MigrateReceive(args MigrateReceiveArgs) error // Progress reporting. SetOperation(op *operations.Operation) Operation() *operations.Operation DeferTemplateApply(trigger TemplateTrigger) error Metrics(hostInterfaces []net.Interface) (*metrics.MetricSet, error) }
Instance interface.
func CreateInternal ¶
func CreateInternal(s *state.State, args db.InstanceArgs, op *operations.Operation, clearLogDir bool, checkArchitecture bool) (Instance, *operationlock.InstanceOperation, revert.Hook, 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. Returns the created instance, along with a "create" operation lock that needs to be marked as Done once the instance is fully completed, and a revert fail function that can be used to undo this function if a subsequent step fails.
func LoadByProjectAndName ¶
func LoadByProjectAndName(s *state.State, projectName string, instanceName string) (Instance, error)
LoadByProjectAndName loads an instance by project and name.
func LoadFromBackup ¶
func LoadFromBackup(s *state.State, projectName string, instancePath string, applyProfiles bool) (Instance, error)
LoadFromBackup loads from a mounted instance's backup file. If applyProfiles is false, then the profiles property will be cleared to prevent profile enrichment from DB. Then the expanded config and expanded devices from the backup file will be applied to the local config and local devices respectively. This is done to allow an expanded instance to be returned without needing the DB.
func LoadNodeAll ¶
LoadNodeAll loads all instances on this server.
type MigrateArgs ¶
type MigrateArgs struct { ControlSend func(m proto.Message) error ControlReceive func(m proto.Message) error StateConn func(ctx context.Context) (io.ReadWriteCloser, error) FilesystemConn func(ctx context.Context) (io.ReadWriteCloser, error) Snapshots bool Live bool Disconnect func() ClusterMoveSourceName string // Will be empty if not a cluster move, othwise indicates the source instance. }
MigrateArgs represent arguments for instance migration send and receive.
type MigrateReceiveArgs ¶
type MigrateReceiveArgs struct { MigrateArgs InstanceOperation *operationlock.InstanceOperation Refresh bool RefreshExcludeOlder bool }
MigrateReceiveArgs represent arguments for instance migration receive.
type MigrateSendArgs ¶
type MigrateSendArgs struct { MigrateArgs AllowInconsistent bool }
MigrateSendArgs represent arguments for instance migration send.
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.