Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigKeyChecker(key string, instanceType Type) (func(value string) error, error)
- func ExpandInstanceConfig(globalConfig map[string]any, config map[string]string, profiles []api.Profile) map[string]string
- func ExpandInstanceDevices(devices deviceConfig.Devices, profiles []api.Profile) deviceConfig.Devices
- func GetRootDiskDevice(devices map[string]map[string]string) (string, map[string]string, error)
- func InstanceIncludeWhenCopying(configKey string, remoteCopy bool) bool
- func IsRootDiskDevice(device map[string]string) bool
- func ValidName(instanceName string, isSnapshot bool) error
- type InstanceAction
- type Type
- type VMAgentData
- type VMAgentMount
Constants ¶
const ( // Any represents any type of instance. Any = Type(-1) // Container represents a container instance type. Container = Type(0) // VM represents a virtual-machine instance type. VM = Type(1) )
const ConfigVolatilePrefix = "volatile."
ConfigVolatilePrefix indicates the prefix used for volatile config keys.
Variables ¶
var ConfigKeyPrefixesAny = []string{"environment.", "user.", "image."}
ConfigKeyPrefixesAny indicates valid prefixes for configuration options.
var ConfigKeyPrefixesContainer = []string{"linux.sysctl.", "limits.kernel."}
ConfigKeyPrefixesContainer indicates valid prefixes for container configuration options.
var ErrNoRootDisk = fmt.Errorf("No root device could be found")
ErrNoRootDisk means there is no root disk device found.
var HugePageSizeKeys = [...]string{"limits.hugepages.64KB", "limits.hugepages.1MB", "limits.hugepages.2MB", "limits.hugepages.1GB"}
HugePageSizeKeys is a list of known hugepage size configuration keys.
var HugePageSizeSuffix = [...]string{"64KB", "1MB", "2MB", "1GB"}
HugePageSizeSuffix contains the list of known hugepage size suffixes.
var InstanceConfigKeysAny = map[string]func(value string) error{ "boot.autostart": validate.Optional(validate.IsBool), "boot.autostart.delay": validate.Optional(validate.IsInt64), "boot.autostart.priority": validate.Optional(validate.IsInt64), "boot.stop.priority": validate.Optional(validate.IsInt64), "boot.host_shutdown_timeout": validate.Optional(validate.IsInt64), "cloud-init.network-config": validate.Optional(validate.IsYAML), "cloud-init.user-data": validate.Optional(validate.IsCloudInitUserData), "cloud-init.vendor-data": validate.Optional(validate.IsCloudInitUserData), "cluster.evacuate": validate.Optional(validate.IsOneOf("auto", "migrate", "live-migrate", "stop")), "limits.cpu": validate.Optional(validate.IsValidCPUSet), "limits.cpu.nodes": validate.Optional(validate.IsValidCPUSet), "limits.disk.priority": validate.Optional(validate.IsPriority), "limits.memory": func(value string) error { if value == "" { return nil } if strings.HasSuffix(value, "%") { num, err := strconv.ParseInt(strings.TrimSuffix(value, "%"), 10, 64) if err != nil { return err } if num == 0 { return errors.New("Memory limit can't be 0%") } return nil } num, err := units.ParseByteSizeString(value) if err != nil { return err } if num == 0 { return fmt.Errorf("Memory limit can't be 0") } return nil }, "raw.apparmor": validate.IsAny, "raw.idmap": validate.IsAny, "security.devlxd": validate.Optional(validate.IsBool), "security.devlxd.images": validate.Optional(validate.IsBool), "security.protection.delete": validate.Optional(validate.IsBool), "security.protection.start": validate.Optional(validate.IsBool), "snapshots.schedule": validate.Optional(validate.IsCron([]string{"@hourly", "@daily", "@midnight", "@weekly", "@monthly", "@annually", "@yearly", "@startup", "@never"})), "snapshots.schedule.stopped": validate.Optional(validate.IsBool), "snapshots.pattern": validate.IsAny, "snapshots.expiry": func(value string) error { _, err := shared.GetExpiry(time.Time{}, value) return err }, "volatile.apply_template": validate.IsAny, "volatile.base_image": validate.IsAny, "volatile.cloud-init.instance-id": validate.Optional(validate.IsUUID), "volatile.evacuate.origin": validate.IsAny, "volatile.last_state.power": validate.IsAny, "volatile.last_state.ready": validate.IsBool, "volatile.apply_quota": validate.IsAny, "volatile.uuid": validate.Optional(validate.IsUUID), "volatile.uuid.generation": validate.Optional(validate.IsUUID), }
InstanceConfigKeysAny is a map of config key to validator. (keys applying to containers AND virtual machines).
var InstanceConfigKeysContainer = map[string]func(value string) error{ "limits.cpu.allowance": func(value string) error { if value == "" { return nil } if strings.HasSuffix(value, "%") { _, err := strconv.Atoi(strings.TrimSuffix(value, "%")) if err != nil { return err } return nil } fields := strings.SplitN(value, "/", 2) if len(fields) != 2 { return fmt.Errorf("Invalid allowance: %s", value) } _, err := strconv.Atoi(strings.TrimSuffix(fields[0], "ms")) if err != nil { return err } _, err = strconv.Atoi(strings.TrimSuffix(fields[1], "ms")) if err != nil { return err } return nil }, "limits.cpu.priority": validate.Optional(validate.IsPriority), "limits.hugepages.64KB": validate.Optional(validate.IsSize), "limits.hugepages.1MB": validate.Optional(validate.IsSize), "limits.hugepages.2MB": validate.Optional(validate.IsSize), "limits.hugepages.1GB": validate.Optional(validate.IsSize), "limits.memory.enforce": validate.Optional(validate.IsOneOf("soft", "hard")), "limits.memory.swap": validate.Optional(validate.IsBool), "limits.memory.swap.priority": validate.Optional(validate.IsPriority), "limits.processes": validate.Optional(validate.IsInt64), "linux.kernel_modules": validate.IsAny, "linux.kernel_modules.load": validate.Optional(validate.IsOneOf("boot", "ondemand")), "migration.incremental.memory": validate.Optional(validate.IsBool), "migration.incremental.memory.iterations": validate.Optional(validate.IsUint32), "migration.incremental.memory.goal": validate.Optional(validate.IsUint32), "nvidia.runtime": validate.Optional(validate.IsBool), "nvidia.driver.capabilities": validate.IsAny, "nvidia.require.cuda": validate.IsAny, "nvidia.require.driver": validate.IsAny, "raw.lxc": validate.IsAny, "raw.seccomp": validate.IsAny, "security.idmap.base": validate.Optional(validate.IsUint32), "security.idmap.isolated": validate.Optional(validate.IsBool), "security.idmap.size": validate.Optional(validate.IsUint32), "security.nesting": validate.Optional(validate.IsBool), "security.privileged": validate.Optional(validate.IsBool), "security.protection.shift": validate.Optional(validate.IsBool), "security.syscalls.allow": validate.IsAny, "security.syscalls.deny_default": validate.Optional(validate.IsBool), "security.syscalls.deny_compat": validate.Optional(validate.IsBool), "security.syscalls.deny": validate.IsAny, "security.syscalls.intercept.bpf": validate.Optional(validate.IsBool), "security.syscalls.intercept.bpf.devices": validate.Optional(validate.IsBool), "security.syscalls.intercept.mknod": validate.Optional(validate.IsBool), "security.syscalls.intercept.mount": validate.Optional(validate.IsBool), "security.syscalls.intercept.mount.allowed": validate.IsAny, "security.syscalls.intercept.mount.fuse": validate.IsAny, "security.syscalls.intercept.mount.shift": validate.Optional(validate.IsBool), "security.syscalls.intercept.sched_setscheduler": validate.Optional(validate.IsBool), "security.syscalls.intercept.setxattr": validate.Optional(validate.IsBool), "security.syscalls.intercept.sysinfo": validate.Optional(validate.IsBool), "volatile.last_state.idmap": validate.IsAny, "volatile.idmap.base": validate.IsAny, "volatile.idmap.current": validate.IsAny, "volatile.idmap.next": validate.IsAny, }
InstanceConfigKeysContainer is a map of config key to validator. (keys applying to containers only).
var InstanceConfigKeysVM = map[string]func(value string) error{ "limits.memory.hugepages": validate.Optional(validate.IsBool), "limits.cpu.pin_strategy": validate.Optional(validate.IsOneOf("none", "auto")), "migration.stateful": validate.Optional(validate.IsBool), "raw.qemu": validate.IsAny, "raw.qemu.conf": validate.IsAny, "security.agent.metrics": validate.Optional(validate.IsBool), "security.csm": validate.Optional(validate.IsBool), "security.secureboot": validate.Optional(validate.IsBool), "security.sev": validate.Optional(validate.IsBool), "security.sev.policy.es": validate.Optional(validate.IsBool), "security.sev.session.dh": validate.IsAny, "security.sev.session.data": validate.IsAny, "agent.nic_config": validate.Optional(validate.IsBool), "volatile.apply_nvram": validate.Optional(validate.IsBool), "volatile.vsock_id": validate.Optional(validate.IsInt64), "boot.debug_edk2": validate.Optional(validate.IsBool), }
InstanceConfigKeysVM is a map of config key to validator. (keys applying to VM only).
Functions ¶
func ConfigKeyChecker ¶
ConfigKeyChecker returns a function that will check whether or not a provide value is valid for the associate config key. Returns an error if the key is not known. The checker function only performs syntactic checking of the value, semantic and usage checking must be done by the caller. User defined keys are always considered to be valid, e.g. user.* and environment.* keys.
func ExpandInstanceConfig ¶
func ExpandInstanceConfig(globalConfig map[string]any, config map[string]string, profiles []api.Profile) map[string]string
ExpandInstanceConfig expands the given instance config with the config values of the given profiles.
func ExpandInstanceDevices ¶
func ExpandInstanceDevices(devices deviceConfig.Devices, profiles []api.Profile) deviceConfig.Devices
ExpandInstanceDevices expands the given instance devices with the devices defined in the given profiles.
func GetRootDiskDevice ¶
GetRootDiskDevice returns the instance device that is configured as root disk. Returns the device name and device config map.
func InstanceIncludeWhenCopying ¶
InstanceIncludeWhenCopying is used to decide whether to include a config item or not when copying an instance. The remoteCopy argument indicates if the copy is remote (i.e between LXD nodes) as this affects the keys kept.
func IsRootDiskDevice ¶
IsRootDiskDevice returns true if the given device representation is configured as root disk for an instance. It typically get passed a specific entry of api.Instance.Devices.
Types ¶
type InstanceAction ¶
type InstanceAction string
InstanceAction indicates the type of action being performed.
const ( Stop InstanceAction = "stop" Start InstanceAction = "start" Restart InstanceAction = "restart" Freeze InstanceAction = "freeze" Unfreeze InstanceAction = "unfreeze" )
InstanceAction types.
type Type ¶
type Type int
Type indicates the type of instance.
func New ¶
New validates the supplied string against the allowed types of instance and returns the internal representation of that type. If empty string is supplied then the type returned is TypeContainer. If an invalid name is supplied an error will be returned.
type VMAgentData ¶
type VMAgentData struct { Name string `json:"name"` CloudInitID string `json:"cloud_init_id"` Location string `json:"location"` Config map[string]string `json:"config,omitempty"` Devices map[string]deviceConfig.Device `json:"devices,omitempty"` }
VMAgentData represents the instance data exposed to the VM agent.