Documentation
¶
Overview ¶
Package hyperkit provides a Go wrapper around the hyperkit command. It currently shells out to start hyperkit with the provided configuration.
Most of the arguments should be self explanatory, but console handling deserves a mention. If the Console is configured with ConsoleStdio, the hyperkit is started with stdin, stdout, and stderr plumbed through to the VM console. If Console is set to ConsoleFile hyperkit the console output is redirected to a file and console input is disabled. For this mode StateDir has to be set and the interactive console is accessible via a 'tty' file created there.
Currently this module has some limitations: - Only supports zero or one disk image - Only support zero or one network interface connected to VPNKit - Only kexec boot
This package is currently implemented by shelling out a hyperkit process. In the future we may change this to become a wrapper around the hyperkit library.
Index ¶
- Constants
- func SetLogger(l Logger)
- type Disk
- type DiskFormat
- type HyperKit
- type InteractiveConsole
- type Logger
- type QcowDisk
- func (d *QcowDisk) AsArgument() string
- func (d *QcowDisk) Ensure() error
- func (d *QcowDisk) Exists() bool
- func (d *QcowDisk) GetCurrentSize() (int, error)
- func (d *QcowDisk) GetPath() string
- func (d *QcowDisk) GetSize() int
- func (d *QcowDisk) QcowTool(verb string, args ...string) *exec.Cmd
- func (d *QcowDisk) SetPath(p string)
- func (d *QcowDisk) Stop() error
- func (d *QcowDisk) String() string
- type RawDisk
- func (d *RawDisk) AsArgument() string
- func (d *RawDisk) Ensure() error
- func (d *RawDisk) Exists() bool
- func (d *RawDisk) GetCurrentSize() (int, error)
- func (d *RawDisk) GetPath() string
- func (d *RawDisk) GetSize() int
- func (d *RawDisk) SetPath(p string)
- func (d *RawDisk) Stop() error
- func (d *RawDisk) String() string
- type Serial
- type Socket9P
- type StandardLogger
Constants ¶
const ( // ConsoleStdio configures console to use Stdio (deprecated) ConsoleStdio = iota // ConsoleFile configures console to a tty and output to a file (deprecated) ConsoleFile // ConsoleLog configures console to a tty and sends its contents to the logs (deprecated) ConsoleLog )
const ( // NoInteractiveConsole disables the interactive console. NoInteractiveConsole = InteractiveConsole(iota) // StdioInteractiveConsole creates a console on stdio. StdioInteractiveConsole // TTYInteractiveConsole creates a console on a TTY. TTYInteractiveConsole )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Disk ¶
type Disk interface { // GetPath returns the location of the disk image file. GetPath() string // SetPath changes the location of the disk image file. SetPath(p string) // GetSize returns the desired disk size. GetSize() int // GetCurrentSize returns the current disk size in MiB. GetCurrentSize() (int, error) // String returns the path. String() string // Exists iff the disk image file can be stat'd without error. Exists() bool // Ensure creates the disk image if needed, and resizes it if needed. Ensure() error // Stop can be called when hyperkit has quit. It performs sanity checks, compaction, etc. Stop() error // AsArgument returns the command-line option to pass after `-s <slot>:0,` to hyperkit for this disk. AsArgument() string // contains filtered or unexported methods }
Disk in an interface for qcow2 and raw disk images.
type DiskFormat ¶
type DiskFormat int
DiskFormat describes the physical format of the disk data
const ( // DiskFormatQcow means the disk is a qcow2. DiskFormatQcow DiskFormat = iota // DiskFormatRaw means the disk is a raw file. DiskFormatRaw )
func GetDiskFormat ¶
func GetDiskFormat(path string) DiskFormat
GetDiskFormat computes the format based on the path's extensions.
type HyperKit ¶
type HyperKit struct { // HyperKit is the path to the hyperkit binary. HyperKit string `json:"hyperkit"` // Argv0 is the name to declare as argv[0]. If left empty, argv[0] is left untouched. Argv0 string `json:"argv0"` // StateDir is the directory where runtime state is kept. If left empty, no state will be kept. StateDir string `json:"state_dir"` // VPNKitSock is the location of the VPNKit socket used for networking. VPNKitSock string `json:"vpnkit_sock"` // VPNKitUUID is a string containing a UUID, it can be used in conjunction with VPNKit to get consistent IP address. VPNKitUUID string `json:"vpnkit_uuid"` // VPNKitPreferredIPv4 is a string containing an IPv4 address, it can be used to request a specific IP for a UUID from VPNKit. VPNKitPreferredIPv4 string `json:"vpnkit_preferred_ipv4"` // UUID is a string containing a UUID, it sets BIOS DMI UUID for the VM (as found in /sys/class/dmi/id/product_uuid on Linux). UUID string `json:"uuid"` // Disks contains disk images to use/create. Disks []Disk `json:"disks"` // ISOImage is the (optional) path to a ISO image to attach. ISOImages []string `json:"iso"` // VSock enables the virtio-socket device and exposes it on the host. VSock bool `json:"vsock"` // VSockDir specifies where the unix domain sockets will be created. Defaults to StateDir when empty. VSockDir string `json:"vsock_dir"` // VSockPorts is a list of guest VSock ports that should be exposed as sockets on the host. VSockPorts []int `json:"vsock_ports"` // VSock guest CID VSockGuestCID int `json:"vsock_guest_cid"` // VMNet is whether to create vmnet network. VMNet bool `json:"vmnet"` // Sockets9P holds the 9P sockets. Sockets9P []Socket9P `json:"9p_sockets"` // Kernel is the path to the kernel image to boot. Kernel string `json:"kernel"` // Initrd is the path to the initial ramdisk to boot off. Initrd string `json:"initrd"` // Bootrom is the path to a boot rom eg for UEFI boot. Bootrom string `json:"bootrom"` // CPUs is the number CPUs to configure. CPUs int `json:"cpus"` // Memory is the amount of megabytes of memory for the VM. Memory int `json:"memory"` // Console defines where the console of the VM should be connected to. (deprecated) Console int `json:"console"` // Serials defines what happens to the I/O on the serial ports. If this is not nil // it overrides the Console setting. Serials []Serial `json:"serials"` // Pid of the hyperkit process Pid int `json:"pid"` // Arguments used to execute the hyperkit process Arguments []string `json:"arguments"` // CmdLine is a single string of the command line CmdLine string `json:"cmdline"` // contains filtered or unexported fields }
HyperKit contains the configuration of the hyperkit VM
func New ¶
New creates a template config structure.
- If hyperkit can't be found an error is returned.
- If vpnkitsock is empty no networking is configured. If it is set to "auto" it tries to re-use the Docker for Mac VPNKit connection.
- If statedir is "" no state is written to disk.
func (*HyperKit) Remove ¶
Remove deletes all statefiles if present. This also removes the StateDir if empty. If keepDisk is set, the disks will not get removed.
type InteractiveConsole ¶
type InteractiveConsole int
InteractiveConsole is an optional interactive VM console.
type Logger ¶
type Logger interface { // Debugf logs a message with "debug" severity (very verbose). Debugf(format string, v ...interface{}) // Infof logs a message with "info" severity (less verbose). Infof(format string, v ...interface{}) // Warnf logs a message with "warn" (non-fatal) severity. Warnf(format string, v ...interface{}) // Errorf logs an (non-fatal) error. Errorf(format string, v ...interface{}) // Fatalf logs a fatal error message, and exits 1. Fatalf(format string, v ...interface{}) }
Logger is an interface for logging.
type QcowDisk ¶
type QcowDisk struct { // Path specifies where the image file will be. Path string `json:"path"` // Size specifies the size of the disk. Size int `json:"size"` // Format is passed as-is to the driver. Format string `json:"format"` // Trim specifies whether we should trim the image file. Trim bool `json:"trim"` // QcowToolPath is the path to the binary to use to manage this image. // Defaults to "qcow-tool" when empty. QcowToolPath string OnFlush string CompactAfter int KeepErased int RuntimeAsserts bool Stats string }
QcowDisk describes a qcow2 disk image file.
func (*QcowDisk) AsArgument ¶
AsArgument returns the command-line option to pass after `-s <slot>:0,` to hyperkit for this disk.
func (*QcowDisk) GetCurrentSize ¶
GetCurrentSize returns the current disk size in MiB.
type RawDisk ¶
type RawDisk struct { // Path specifies where the image file will be. Path string `json:"path"` // Size specifies the size of the disk. Size int `json:"size"` // Format is passed as-is to the driver. Format string `json:"format"` // Trim specifies whether we should trim the image file. Trim bool `json:"trim"` }
RawDisk describes a raw disk image file.
func (*RawDisk) AsArgument ¶
AsArgument returns the command-line option to pass after `-s <slot>:0,` to hyperkit for this disk.
func (*RawDisk) GetCurrentSize ¶
GetCurrentSize returns the current disk size in MiB.
type Serial ¶
type Serial struct { // InteractiveConsole allows a user to connect to a live VM serial console. InteractiveConsole InteractiveConsole // LogToRingBuffer will write console output to a fixed size ring buffer file. LogToRingBuffer bool // LogToASL will write console output to the Apple System Log. LogToASL bool }
Serial port.
type StandardLogger ¶
type StandardLogger struct{}
StandardLogger makes the go standard logger comply to our Logger interface.
func (*StandardLogger) Debugf ¶
func (*StandardLogger) Debugf(f string, v ...interface{})
Debugf logs a message with "debug" severity.
func (*StandardLogger) Errorf ¶
func (*StandardLogger) Errorf(f string, v ...interface{})
Errorf logs an (non-fatal) error.
func (*StandardLogger) Fatalf ¶
func (*StandardLogger) Fatalf(f string, v ...interface{})
Fatalf logs a fatal error message, and exits 1.
func (*StandardLogger) Infof ¶
func (*StandardLogger) Infof(f string, v ...interface{})
Infof logs a message with "info" severity.
func (*StandardLogger) Warnf ¶
func (*StandardLogger) Warnf(f string, v ...interface{})
Warnf logs a message with "warn" (non-fatal) severity.