instance

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigVolatilePrefix = "volatile."

ConfigVolatilePrefix indicates the prefix used for volatile config keys.

View Source
const SnapshotDelimiter = "/"

Variables

View Source
var ErrNoRootDisk = fmt.Errorf("No root device could be found")

ErrNoRootDisk means there is no root disk device found.

View Source
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.

View Source
var HugePageSizeSuffix = [...]string{"64KB", "1MB", "2MB", "1GB"}

HugePageSizeSuffix contains the list of known hugepage size suffixes.

View Source
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.guestapi": validate.Optional(validate.IsBool),

	"security.protection.delete": 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 := 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).

View Source
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,

	"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.guestapi.images": validate.Optional(validate.IsBool),

	"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.blacklist_default": validate.Optional(validate.IsBool),
	"security.syscalls.blacklist_compat":  validate.Optional(validate.IsBool),
	"security.syscalls.blacklist":         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),

	"security.syscalls.whitelist": validate.IsAny,

	"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).

View Source
var InstanceConfigKeysVM = map[string]func(value string) error{

	"limits.memory.hugepages": validate.Optional(validate.IsBool),

	"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.Optional(validate.IsAny),

	"security.sev.session.data": validate.Optional(validate.IsAny),

	"agent.nic_config": validate.Optional(validate.IsBool),

	"volatile.apply_nvram": validate.Optional(validate.IsBool),

	"volatile.vsock_id": validate.Optional(validate.IsInt64),
}

InstanceConfigKeysVM is a map of config key to validator. (keys applying to VM only).

Functions

func ConfigKeyChecker

func ConfigKeyChecker(key string, instanceType api.InstanceType) (func(value string) error, error)

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 GetExpiry

func GetExpiry(refDate time.Time, s string) (time.Time, error)

GetExpiry returns the expiry date based on the reference date and a length of time. The length of time format is "<integer>(S|M|H|d|w|m|y)", and can contain multiple such fields, e.g. "1d 3H" (1 day and 3 hours).

func GetRootDiskDevice

func GetRootDiskDevice(devices map[string]map[string]string) (string, map[string]string, error)

GetRootDiskDevice returns the instance device that is configured as root disk. Returns the device name and device config map.

func InstanceIncludeWhenCopying

func InstanceIncludeWhenCopying(configKey string, remoteCopy bool) bool

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 servers) as this affects the keys kept.

func IsRootDiskDevice

func IsRootDiskDevice(device map[string]string) bool

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.

func IsSnapshot

func IsSnapshot(name string) bool

func IsUserConfig

func IsUserConfig(key string) bool

IsUserConfig returns true if the config key is a user configuration.

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.

Jump to

Keyboard shortcuts

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