Documentation ¶
Index ¶
- Constants
- type Bootloader
- type EFIBootloader
- type LinuxBootloader
- type StorageConfig
- type TimeSync
- type USBMassStorage
- type VMComponent
- type VirtioBlk
- type VirtioDevice
- func VirtioFsNew(sharedDir string, mountTag string) (VirtioDevice, error)
- func VirtioGPUNew() (VirtioDevice, error)
- func VirtioInputNew(inputType string) (VirtioDevice, error)
- func VirtioRngNew() (VirtioDevice, error)
- func VirtioSerialNew(logFilePath string) (VirtioDevice, error)
- func VirtioSerialNewStdio() (VirtioDevice, error)
- func VirtioVsockNew(port uint, socketURL string, listen bool) (VirtioDevice, error)
- type VirtioFs
- type VirtioGPU
- type VirtioGPUResolution
- type VirtioInput
- type VirtioNet
- type VirtioRng
- type VirtioSerial
- type VirtioVsock
- type VirtualMachine
- func (vm *VirtualMachine) AddDevice(dev VirtioDevice) error
- func (vm *VirtualMachine) AddDevicesFromCmdLine(cmdlineOpts []string) error
- func (vm *VirtualMachine) AddTimeSyncFromCmdLine(cmdlineOpts string) error
- func (vm *VirtualMachine) Cmd(vfkitPath string) (*exec.Cmd, error)
- func (vm *VirtualMachine) TimeSync() *TimeSync
- func (vm *VirtualMachine) ToCmdLine() ([]string, error)
- func (vm *VirtualMachine) UnmarshalJSON(b []byte) error
- func (vm *VirtualMachine) VirtioGPUDevices() []*VirtioGPU
- func (vm *VirtualMachine) VirtioVsockDevices() []*VirtioVsock
Constants ¶
const ( // Possible values for VirtioInput.InputType VirtioInputPointingDevice = "pointing" VirtioInputKeyboardDevice = "keyboard" // Options for VirtioGPUResolution VirtioGPUResolutionHeight = "height" VirtioGPUResolutionWidth = "width" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bootloader ¶
Bootloader is the base interface for all bootloader classes. It specifies how to boot the virtual machine. It is mandatory to set a Bootloader or the virtual machine won't start.
func BootloaderFromCmdLine ¶ added in v0.1.0
func BootloaderFromCmdLine(optsStrv []string) (Bootloader, error)
type EFIBootloader ¶ added in v0.1.0
type EFIBootloader struct { EFIVariableStorePath string // TODO: virtualization framework allow both create and overwrite CreateVariableStore bool }
EFIBootloader allows to set a few options related to EFI variable storage
func NewEFIBootloader ¶ added in v0.1.0
func NewEFIBootloader(efiVariableStorePath string, createVariableStore bool) *EFIBootloader
NewEFIBootloader creates a new bootloader to start a VM using EFI efiVariableStorePath is the path to a file for EFI storage create is a boolean indicating if the file for the store should be created or not
func (*EFIBootloader) FromOptions ¶ added in v0.1.0
func (bootloader *EFIBootloader) FromOptions(options []option) error
func (*EFIBootloader) MarshalJSON ¶ added in v0.1.0
func (bootloader *EFIBootloader) MarshalJSON() ([]byte, error)
func (*EFIBootloader) ToCmdLine ¶ added in v0.1.0
func (bootloader *EFIBootloader) ToCmdLine() ([]string, error)
type LinuxBootloader ¶ added in v0.1.0
LinuxBootloader determines which kernel/initrd/kernel args to use when starting the virtual machine.
func NewLinuxBootloader ¶ added in v0.1.0
func NewLinuxBootloader(vmlinuzPath, kernelCmdLine, initrdPath string) *LinuxBootloader
NewLinuxBootloader creates a new bootloader to start a VM with the file at vmlinuzPath as the kernel, kernelCmdLine as the kernel command line, and the file at initrdPath as the initrd. On ARM64, the kernel must be uncompressed otherwise the VM will fail to boot.
func (*LinuxBootloader) FromOptions ¶ added in v0.1.0
func (bootloader *LinuxBootloader) FromOptions(options []option) error
func (*LinuxBootloader) MarshalJSON ¶ added in v0.1.0
func (bootloader *LinuxBootloader) MarshalJSON() ([]byte, error)
func (*LinuxBootloader) ToCmdLine ¶ added in v0.1.0
func (bootloader *LinuxBootloader) ToCmdLine() ([]string, error)
type StorageConfig ¶ added in v0.1.0
StorageConfig configures a disk device.
func (*StorageConfig) FromOptions ¶ added in v0.1.0
func (config *StorageConfig) FromOptions(options []option) error
func (*StorageConfig) ToCmdLine ¶ added in v0.1.0
func (config *StorageConfig) ToCmdLine() ([]string, error)
type TimeSync ¶
type TimeSync struct {
VsockPort uint
}
TimeSync enables synchronization of the host time to the linux guest after the host was suspended. This requires qemu-guest-agent to be running in the guest, and to be listening on a vsock socket
func (*TimeSync) FromOptions ¶ added in v0.1.0
type USBMassStorage ¶ added in v0.1.0
type USBMassStorage struct {
StorageConfig
}
func (*USBMassStorage) MarshalJSON ¶ added in v0.1.0
func (dev *USBMassStorage) MarshalJSON() ([]byte, error)
type VMComponent ¶ added in v0.1.0
The VMComponent interface represents a VM element (device, bootloader, ...) which can be converted from/to commandline parameters
func TimeSyncNew ¶ added in v0.1.0
func TimeSyncNew(vsockPort uint) (VMComponent, error)
func USBMassStorageNew ¶ added in v0.1.0
func USBMassStorageNew(imagePath string) (VMComponent, error)
USBMassStorageNew creates a new USB disk to use in the virtual machine. It will use the file at imagePath as the disk image. This image must be in raw or ISO format.
type VirtioBlk ¶ added in v0.1.0
type VirtioBlk struct { StorageConfig DeviceIdentifier string }
VirtioBlk configures a disk device.
func VirtioBlkNew ¶ added in v0.1.0
VirtioBlkNew creates a new disk to use in the virtual machine. It will use the file at imagePath as the disk image. This image must be in raw format.
func (*VirtioBlk) FromOptions ¶ added in v0.1.0
func (*VirtioBlk) MarshalJSON ¶ added in v0.1.0
func (*VirtioBlk) SetDeviceIdentifier ¶ added in v0.1.0
type VirtioDevice ¶
type VirtioDevice VMComponent
The VirtioDevice interface is an interface which is implemented by all virtio devices.
func VirtioFsNew ¶ added in v0.1.0
func VirtioFsNew(sharedDir string, mountTag string) (VirtioDevice, error)
VirtioFsNew creates a new virtio-fs device for file sharing. It will share the directory at sharedDir with the virtual machine. This directory can be mounted in the VM using `mount -t virtiofs mountTag /some/dir`
func VirtioGPUNew ¶ added in v0.1.0
func VirtioGPUNew() (VirtioDevice, error)
VirtioGPUNew creates a new gpu device for the virtual machine. The usesGUI parameter determines whether a graphical application window will be displayed
func VirtioInputNew ¶ added in v0.1.0
func VirtioInputNew(inputType string) (VirtioDevice, error)
VirtioInputNew creates a new input device for the virtual machine. The inputType parameter is the type of virtio-input device that will be added to the machine.
func VirtioRngNew ¶ added in v0.1.0
func VirtioRngNew() (VirtioDevice, error)
VirtioRngNew creates a new random number generator device to feed entropy into the virtual machine.
func VirtioSerialNew ¶ added in v0.1.0
func VirtioSerialNew(logFilePath string) (VirtioDevice, error)
VirtioSerialNew creates a new serial device for the virtual machine. The output the virtual machine sent to the serial port will be written to the file at logFilePath.
func VirtioSerialNewStdio ¶ added in v0.1.0
func VirtioSerialNewStdio() (VirtioDevice, error)
func VirtioVsockNew ¶ added in v0.1.0
func VirtioVsockNew(port uint, socketURL string, listen bool) (VirtioDevice, error)
VirtioVsockNew creates a new virtio-vsock device for 2-way communication between the host and the virtual machine. The communication will happen on vsock port, and on the host it will use the unix socket at socketURL. When listen is true, the host will be listening for connections over vsock. When listen is false, the guest will be listening for connections over vsock.
type VirtioFs ¶ added in v0.1.0
type VirtioFs struct { MountTag string }
VirtioFs configures directory sharing between the guest and the host.
func (*VirtioFs) FromOptions ¶ added in v0.1.0
func (*VirtioFs) MarshalJSON ¶ added in v0.1.0
type VirtioGPU ¶ added in v0.1.0
type VirtioGPU struct { UsesGUI bool `json:"usesGUI"` VirtioGPUResolution }
VirtioGPU configures a GPU device, such as the host computer's display
func (*VirtioGPU) FromOptions ¶ added in v0.1.0
func (*VirtioGPU) MarshalJSON ¶ added in v0.1.0
type VirtioGPUResolution ¶ added in v0.1.0
type VirtioInput ¶ added in v0.1.0
type VirtioInput struct {
InputType string `json:"inputType"` // currently supports "pointing" and "keyboard" input types
}
VirtioInput configures an input device, such as a keyboard or pointing device (mouse) that the virtual machine can use
func (*VirtioInput) FromOptions ¶ added in v0.1.0
func (dev *VirtioInput) FromOptions(options []option) error
func (*VirtioInput) MarshalJSON ¶ added in v0.1.0
func (dev *VirtioInput) MarshalJSON() ([]byte, error)
func (*VirtioInput) ToCmdLine ¶ added in v0.1.0
func (dev *VirtioInput) ToCmdLine() ([]string, error)
type VirtioNet ¶ added in v0.1.0
type VirtioNet struct { Nat bool MacAddress net.HardwareAddr // file parameter is holding a connected datagram socket. // see https://github.com/Code-Hex/vz/blob/7f648b6fb9205d6f11792263d79876e3042c33ec/network.go#L113-L155 Socket *os.File UnixSocketPath string }
VirtioNet configures the virtual machine networking.
func VirtioNetNew ¶ added in v0.1.0
VirtioNetNew creates a new network device for the virtual machine. It will use macAddress as its MAC address.
func (*VirtioNet) FromOptions ¶ added in v0.1.0
func (*VirtioNet) MarshalJSON ¶ added in v0.1.0
func (*VirtioNet) SetSocket ¶ added in v0.1.0
Set the socket to use for the network communication
This maps the virtual machine network interface to a connected datagram socket. This means all network traffic on this interface will go through file. file must be a connected datagram (SOCK_DGRAM) socket.
func (*VirtioNet) SetUnixSocketPath ¶ added in v0.1.0
type VirtioRng ¶ added in v0.1.0
type VirtioRng struct { }
virtioRng configures a random number generator (RNG) device.
func (*VirtioRng) FromOptions ¶ added in v0.1.0
func (*VirtioRng) MarshalJSON ¶ added in v0.1.0
type VirtioSerial ¶ added in v0.1.0
VirtioSerial configures the virtual machine serial ports.
func (*VirtioSerial) FromOptions ¶ added in v0.1.0
func (dev *VirtioSerial) FromOptions(options []option) error
func (*VirtioSerial) MarshalJSON ¶ added in v0.1.0
func (dev *VirtioSerial) MarshalJSON() ([]byte, error)
func (*VirtioSerial) ToCmdLine ¶ added in v0.1.0
func (dev *VirtioSerial) ToCmdLine() ([]string, error)
type VirtioVsock ¶
type VirtioVsock struct { // Port is the virtio-vsock port used for this device, see `man vsock` for more // details. Port uint // SocketURL is the path to a unix socket on the host to use for the virtio-vsock communication with the guest. SocketURL string // If true, vsock connections will have to be done from guest to host. If false, vsock connections will only be possible // from host to guest Listen bool }
VirtioVsock configures of a virtio-vsock device allowing 2-way communication between the host and the virtual machine type
func (*VirtioVsock) FromOptions ¶
func (dev *VirtioVsock) FromOptions(options []option) error
func (*VirtioVsock) MarshalJSON ¶ added in v0.1.0
func (dev *VirtioVsock) MarshalJSON() ([]byte, error)
func (*VirtioVsock) ToCmdLine ¶ added in v0.1.0
func (dev *VirtioVsock) ToCmdLine() ([]string, error)
type VirtualMachine ¶
type VirtualMachine struct { Vcpus uint `json:"vcpus"` MemoryBytes uint64 `json:"memoryBytes"` Bootloader Bootloader `json:"bootloader"` Devices []VirtioDevice `json:"devices,omitempty"` Timesync *TimeSync `json:"timesync,omitempty"` }
VirtualMachine is the top-level type. It describes the virtual machine configuration (bootloader, devices, ...).
func NewVirtualMachine ¶
func NewVirtualMachine(vcpus uint, memoryBytes uint64, bootloader Bootloader) *VirtualMachine
NewVirtualMachine creates a new VirtualMachine instance. The virtual machine will use vcpus virtual CPUs and it will be allocated memoryBytes bytes of RAM. bootloader specifies which kernel/initrd/kernel args it will be using.
func (*VirtualMachine) AddDevice ¶ added in v0.1.0
func (vm *VirtualMachine) AddDevice(dev VirtioDevice) error
AddDevice adds a dev to vm. This device can be created with one of the VirtioXXXNew methods.
func (*VirtualMachine) AddDevicesFromCmdLine ¶
func (vm *VirtualMachine) AddDevicesFromCmdLine(cmdlineOpts []string) error
func (*VirtualMachine) AddTimeSyncFromCmdLine ¶
func (vm *VirtualMachine) AddTimeSyncFromCmdLine(cmdlineOpts string) error
func (*VirtualMachine) Cmd ¶ added in v0.1.0
func (vm *VirtualMachine) Cmd(vfkitPath string) (*exec.Cmd, error)
Cmd creates an exec.Cmd to start vfkit with the configured devices. In particular it will set ExtraFiles appropriately when mapping a file with a network interface.
func (*VirtualMachine) TimeSync ¶
func (vm *VirtualMachine) TimeSync() *TimeSync
func (*VirtualMachine) ToCmdLine ¶ added in v0.1.0
func (vm *VirtualMachine) ToCmdLine() ([]string, error)
ToCmdLine generates a list of arguments for use with the os/exec package. These arguments will start a virtual machine with the devices/bootloader/... described by vm If the virtual machine configuration described by vm is invalid, an error will be returned.
func (*VirtualMachine) UnmarshalJSON ¶ added in v0.1.0
func (vm *VirtualMachine) UnmarshalJSON(b []byte) error
UnmarshalJSON is a custom deserializer for VirtualMachine. The custom work is needed because VirtualMachine uses interfaces in its struct and JSON cannot determine which implementation of the interface to deserialize to.
func (*VirtualMachine) VirtioGPUDevices ¶ added in v0.1.0
func (vm *VirtualMachine) VirtioGPUDevices() []*VirtioGPU
func (*VirtualMachine) VirtioVsockDevices ¶
func (vm *VirtualMachine) VirtioVsockDevices() []*VirtioVsock