client

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package client provides a go API to generate a vfkit commandline.

After creating a `VirtualMachine` object, use its `ToCmdLine()` method to get a list of arguments which can be used with the os/exec package. package client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootloader

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

Bootloader determines which kernel/initrd/kernel args to use when starting the virtual machine. It is mandatory to set a Bootloader or the virtual machine won't start.

func NewBootloader

func NewBootloader(vmlinuzPath, kernelCmdLine, initrdPath string) *Bootloader

NewBootloader 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. The kernel must be uncompressed otherwise the VM will fail to boot.

func (*Bootloader) ToCmdLine

func (bootloader *Bootloader) ToCmdLine() ([]string, error)

type VMComponent

type VMComponent interface {
	ToCmdLine() ([]string, error)
}

The VMComponent interface represents a VM element (device, bootloader, ...) which can be converted to commandline parameters

func TimeSyncNew

func TimeSyncNew(vsockPort uint) (VMComponent, error)

type VirtioDevice

type VirtioDevice VMComponent

The VirtioDevice interface is an interface which is implemented by all devices.

func VirtioBlkNew

func VirtioBlkNew(imagePath string) (VirtioDevice, error)

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 VirtioFsNew

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 VirtioNetNew

func VirtioNetNew(macAddress string) (VirtioDevice, error)

VirtioNetNew creates a new network device for the virtual machine. It will use macAddress as its MAC address.

func VirtioRNGNew

func VirtioRNGNew() (VirtioDevice, error)

VirtioRNGNew creates a new random number generator device to feed entropy into the virtual machine.

func VirtioSerialNew

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 VirtioVsockNew

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 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) ToCmdLine

func (dev *VirtioVsock) ToCmdLine() ([]string, error)

type VirtualMachine

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

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

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) ToCmdLine

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.

Jump to

Keyboard shortcuts

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