machine

package
v0.5.0-62-gb750372 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

Index

Constants

View Source
const (
	MachineIDLen      = 64
	MachineIDShortLen = 12
)
View Source
const (
	// The machine state is unknown
	MachineStateUnknown = MachineState("unknown")
	// The machine has been created but not started
	MachineStateCreated = MachineState("created")
	// The machine is the process of restarting
	MachineStateRestarting = MachineState("restarting")
	// The machine is active and online
	MachineStateRunning = MachineState("running")
	// The machine is paused
	MachineStatePaused = MachineState("paused")
	// The machine is suspended with a valid memory snapshot
	MachineStateSuspended = MachineState("suspended")
	// The machine has previously run and has subsequently shutdown gracefully.
	// In this state, the VMM is no longer present or active.
	MachineStateExited = MachineState("exited")
	// The machine has not exited gracefully
	MachineStateDead = MachineState("dead")
)

Variables

View Source
var (
	NullMachineID = MachineID("")
)

Functions

func IsShortMachineID

func IsShortMachineID(id string) bool

IsShortID determines if an arbitrary string *looks like* a short ID.

func ValidateMachineID

func ValidateMachineID(id string) error

ValidateMachineID checks whether a MachineID string is a valid image MachineID.

Types

type MachineConfig

type MachineConfig struct {
	// ID is the UUID of the guest.
	ID MachineID `json:"id,omitempty"`

	// Name is the name of the guest.
	Name MachineName `json:"name,omitempty"`

	// Description of the guest.
	Description string `json:"description,omitempty"`

	// Architecture of the machine, e.g.: x86_64, arm64.
	Architecture string `json:"architecture"`

	// Platform of the machine, e.g.: kvm, xen.
	Platform string `json:"platform"`

	// Driver represents the hypervisor once the machine has entered into an
	// instantiated lifecycle.
	DriverName string `json:"driver,omitempty"`

	// Source represents where the machine image derived from
	Source string `json:"source,omitempty"`

	// KernelPath is the guest kernel host path.
	KernelPath string `json:"kernel_path,omitempty"`

	// Arguments are the list of arguments to pass to the kernel
	Arguments []string `json:"arguments,omitempty"`

	// InitrdPath is the guest initrd image host path.
	// ImagePath and InitrdPath cannot be set at the same time.
	InitrdPath string `json:"initrd_path,omitempty"`

	// HardwareAcceleration indicates whether host machine acceleration should be
	// used when available by the underlying driver.
	HardwareAcceleration bool

	// NumVCPUs specifies default number of vCPUs for the VM.
	NumVCPUs uint64 `json:"num_vcpus,omitempty"`

	// MemorySize specifies default memory size in MiB for the VM.
	MemorySize uint64 `json:"mem_size,omitempty"`

	// DestroyOnExit indicates whether the machine should be destroyed once it
	// exists
	DestroyOnExit bool

	// LogFile is the path to use for saving the serial console to file.
	LogFile string `json:"log_file"`

	// CreatedAt represents when the machine was created with its respected driver
	// or VMM.
	CreatedAt time.Time `json:"created_at"`

	// ExitedAt represents when the machine fully shutdown
	ExitedAt time.Time `json:"exited_at"`

	// ExitStatus represents the error code returned after a machine exits
	ExitStatus int `json:"exit_status"`
}

MachineConfig describes an individual virtual machine

func NewMachineConfig

func NewMachineConfig(mopts ...MachineOption) (*MachineConfig, error)

type MachineID

type MachineID string

MachineID is a 16 byte universally unique identifier.

func NewRandomMachineID

func NewRandomMachineID() (MachineID, error)

NewRandomMachineID returns a random machine ID.

It uses the crypto/rand reader as a source of randomness.

func (MachineID) Short

func (mid MachineID) Short() MachineShortID

func (MachineID) ShortString

func (mid MachineID) ShortString() string

func (MachineID) String

func (mid MachineID) String() string

type MachineName

type MachineName string

MachineName is the name of the guest.

type MachineOption

type MachineOption func(mo *MachineConfig) error

func WithAcceleration

func WithAcceleration(hwAccel bool) MachineOption

func WithArchitecture

func WithArchitecture(arch string) MachineOption

func WithArguments

func WithArguments(arguments []string) MachineOption

func WithDescription

func WithDescription(description string) MachineOption

func WithDestroyOnExit

func WithDestroyOnExit(destroyOnExit bool) MachineOption

func WithDriverName

func WithDriverName(driver string) MachineOption

func WithID

func WithID(id MachineID) MachineOption

func WithInitRd

func WithInitRd(initrd string) MachineOption

func WithKernel

func WithKernel(kernel string) MachineOption

func WithLogFile added in v0.4.2

func WithLogFile(file string) MachineOption

func WithMemorySize

func WithMemorySize(memorySize uint64) MachineOption

func WithName

func WithName(name MachineName) MachineOption

func WithNumVCPUs

func WithNumVCPUs(numVCPUs uint64) MachineOption

func WithPlatform

func WithPlatform(plat string) MachineOption

func WithSource

func WithSource(source string) MachineOption

type MachineShortID

type MachineShortID string

MachineID is a 16 byte universally unique identifier.

func TruncateMachineID

func TruncateMachineID(mid MachineID) MachineShortID

TruncateMachineID returns a shorthand version of a string identifier for convenience.

A collision with other shorthands is very unlikely, but possible. In case of a collision a lookup with TruncIndex.Get() will fail, and the caller will need to use a longer prefix, or the full-length Id.

func (MachineShortID) String

func (mid MachineShortID) String() string

type MachineState

type MachineState string

MachineState represents the current state of a machine

func (MachineState) String

func (ms MachineState) String() string

type MachineStore

type MachineStore struct {
	// contains filtered or unexported fields
}

func NewMachineStoreFromPath

func NewMachineStoreFromPath(dir string, msopts ...MachineStoreOption) (*MachineStore, error)

NewMachineStoreFromPath prepares a `*MachineStore` to use to manipulate, save, list, view, etc. in the machine store.

func (*MachineStore) ListAllMachineConfigs

func (ms *MachineStore) ListAllMachineConfigs() (map[MachineID]MachineConfig, error)

ListAllMachineConfigs returns a map of all machine configs saved in the store where the index to the map is the machine's ID.

func (*MachineStore) ListAllMachineIDs

func (ms *MachineStore) ListAllMachineIDs() ([]MachineID, error)

ListAllMachineIDs returns a slice of all machine's saved to the store.

func (*MachineStore) LookupDriverConfig

func (ms *MachineStore) LookupDriverConfig(mid MachineID, dcfg any) error

LookupDriverConfig uses pass-by-reference to return the driver config for the machine defined by the MachineID `mid` to the variable `dcfg`,

func (*MachineStore) LookupMachineConfig

func (ms *MachineStore) LookupMachineConfig(mid MachineID, mcfg any) error

LookupMachineConfig uses pass-by-reference to return the machine config for the machine defined by the MachineID `mid` to the variable `mcfg`.

func (*MachineStore) LookupMachineState

func (ms *MachineStore) LookupMachineState(mid MachineID) (MachineState, error)

LookupMachineState returns the machine state in the store for the machine defined by the MachineID `mid`.

func (*MachineStore) Purge

func (ms *MachineStore) Purge(mid MachineID) error

Purge completely removes all reference of configuration from the store based on the MachineID `mid`.

func (*MachineStore) SaveDriverConfig

func (ms *MachineStore) SaveDriverConfig(mid MachineID, dcfg any) error

SaveDriverConfig saves the driver config `dcfg` for the machine based on the MachineID `mid`.

func (*MachineStore) SaveMachineConfig

func (ms *MachineStore) SaveMachineConfig(mid MachineID, mcfg MachineConfig) error

SaveMachineConfig saves the machine config `mcfg` for the machine based on the MachineID `mid`.

func (*MachineStore) SaveMachineState

func (ms *MachineStore) SaveMachineState(mid MachineID, state MachineState) error

SaveMachineState saves the machine `state` for the machine based on the MachineID `mid`.

type MachineStoreOption

type MachineStoreOption func(ms *MachineStore) error

func WithMachineStoreLogger

func WithMachineStoreLogger(l badger.Logger) MachineStoreOption

WithMachineStoreLogger sets the Badger DB logger interface

func WithMachineStoreTimeout

func WithMachineStoreTimeout(timeout time.Duration) MachineStoreOption

WithMachineStoreTimeout sets a timeout to use when connection to the store

Directories

Path Synopsis
SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
Code generated by kraftkit.sh/tools/go-generate-qemu-devices.
Code generated by kraftkit.sh/tools/go-generate-qemu-devices.
qmp

Jump to

Keyboard shortcuts

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