Documentation ¶
Overview ¶
Package virtualbox implements wrappers to interact with VirtualBox.
VirtualBox Machine State Transition ¶
A VirtualBox machine can be in one of the following states:
poweroff: The VM is powered off and no previous running state saved. running: The VM is running. paused: The VM is paused, but its state is not saved to disk. If you quit VirtualBox, the state will be lost. saved: The VM is powered off, and the previous state is saved on disk. aborted: The VM process crashed. This should happen very rarely.
VBoxManage supports the following transitions between states:
startvm <VM>: poweroff|saved --> running controlvm <VM> pause: running --> paused controlvm <VM> resume: paused --> running controlvm <VM> savestate: running -> saved controlvm <VM> acpipowerbutton: running --> poweroff controlvm <VM> poweroff: running --> poweroff (unsafe) controlvm <VM> reset: running --> poweroff --> running (unsafe)
Poweroff and reset are unsafe because they will lose state and might corrupt the disk image.
To make things simpler, the following transitions are used instead:
start: poweroff|saved|paused|aborted --> running stop: [paused|saved -->] running --> poweroff save: [paused -->] running --> saved restart: [paused|saved -->] running --> poweroff --> running poweroff: [paused|saved -->] running --> poweroff (unsafe) reset: [paused|saved -->] running --> poweroff --> running (unsafe)
The takeaway is we try our best to transit the virtual machine into the state you want it to be, and you only need to watch out for the potentially unsafe poweroff and reset.
Index ¶
- Variables
- func AddHostonlyDHCP(ifname string, d driver.DHCP) error
- func AddInternalDHCP(netname string, d driver.DHCP) error
- func ConfigFlags(B2D *driver.MachineConfig, flags *flag.FlagSet) error
- func DHCPs() (map[string]*driver.DHCP, error)
- func DelExtra(name, key string) error
- func HostonlyNets() (map[string]*HostonlyNet, error)
- func InitFunc(mc *driver.MachineConfig) (driver.Machine, error)
- func ListMachines() ([]string, error)
- func MakeDiskImage(dest string, size uint, r io.Reader) error
- func NATNets() (map[string]NATNet, error)
- func ParseIPv4Mask(s string) net.IPMask
- func SetExtra(name, key, val string) error
- func ZeroFill(w io.Writer, n int64) error
- type Flag
- type HostonlyNet
- type Machine
- func (m *Machine) AddNATPF(n int, name string, rule driver.PFRule) error
- func (m *Machine) AddStorageCtl(name string, ctl driver.StorageController) error
- func (m *Machine) AttachStorage(ctlName string, medium driver.StorageMedium) error
- func (m *Machine) DelNATPF(n int, name string) error
- func (m *Machine) DelStorageCtl(name string) error
- func (m *Machine) Delete() error
- func (m *Machine) GetDockerPort() uint
- func (m *Machine) GetName() string
- func (m *Machine) GetSSHPort() uint
- func (m *Machine) GetSerialFile() string
- func (m *Machine) GetState() driver.MachineState
- func (m *Machine) Modify() error
- func (m *Machine) Pause() error
- func (m *Machine) Poweroff() error
- func (m *Machine) Refresh() error
- func (m *Machine) Reset() error
- func (m *Machine) Restart() error
- func (m *Machine) Save() error
- func (m *Machine) SetNIC(n int, nic driver.NIC) error
- func (m *Machine) Start() error
- func (m *Machine) Stop() error
- type NATNet
Constants ¶
This section is empty.
Variables ¶
var ( VBM string // Path to VBoxManage utility. VMDK string // base VMDK to use as persistent disk. )
var ( ErrMachineExist = errors.New("machine already exists") ErrMachineNotExist = errors.New("machine does not exist") ErrVBMNotFound = errors.New("VBoxManage not found") )
var (
ErrHostonlyInterfaceCreation = errors.New("failed to create hostonly interface")
)
Functions ¶
func AddHostonlyDHCP ¶
AddHostonlyDHCP adds a DHCP server to a host-only network.
func AddInternalDHCP ¶
AddInternalDHCP adds a DHCP server to an internal network.
func ConfigFlags ¶ added in v1.2.0
func ConfigFlags(B2D *driver.MachineConfig, flags *flag.FlagSet) error
func HostonlyNets ¶
func HostonlyNets() (map[string]*HostonlyNet, error)
HostonlyNets gets all host-only networks in a map keyed by HostonlyNet.NetworkName.
func InitFunc ¶ added in v1.2.0
func InitFunc(mc *driver.MachineConfig) (driver.Machine, error)
Initialize the Machine.
func ListMachines ¶
ListMachines lists all registered machines.
func MakeDiskImage ¶
MakeDiskImage makes a disk image at dest with the given size in MB. If r is not nil, it will be read as a raw disk image to convert from.
func ParseIPv4Mask ¶
ParseIPv4Mask parses IPv4 netmask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.
Types ¶
type Flag ¶
type Flag int
type HostonlyNet ¶
type HostonlyNet struct { Name string GUID string DHCP bool IPv4 net.IPNet IPv6 net.IPNet HwAddr net.HardwareAddr Medium string Status string NetworkName string // referenced in DHCP.NetworkName }
Host-only network.
func CreateHostonlyNet ¶
func CreateHostonlyNet() (*HostonlyNet, error)
CreateHostonlyNet creates a new host-only network.
func (*HostonlyNet) Config ¶
func (n *HostonlyNet) Config() error
Config changes the configuration of the host-only network.
type Machine ¶
type Machine struct { Name string UUID string State driver.MachineState CPUs uint Memory uint // main memory (in MB) VRAM uint // video memory (in MB) CfgFile string BaseFolder string OSType string Flag Flag BootOrder []string // max 4 slots, each in {none|floppy|dvd|disk|net} DockerPort uint SSHPort uint SerialFile string }
Machine information.
func CreateMachine ¶
func CreateMachine(mc *driver.MachineConfig) (*Machine, error)
CreateMachine creates a new machine. If basefolder is empty, use default.
func GetMachine ¶
GetMachine finds a machine by its name or UUID.
func (*Machine) AddNATPF ¶
AddNATPF adds a NAT port forarding rule to the n-th NIC with the given name.
func (*Machine) AddStorageCtl ¶
func (m *Machine) AddStorageCtl(name string, ctl driver.StorageController) error
AddStorageCtl adds a storage controller with the given name.
func (*Machine) AttachStorage ¶
func (m *Machine) AttachStorage(ctlName string, medium driver.StorageMedium) error
AttachStorage attaches a storage medium to the named storage controller.
func (*Machine) DelNATPF ¶
DelNATPF deletes the NAT port forwarding rule with the given name from the n-th NIC.
func (*Machine) DelStorageCtl ¶
DelStorageCtl deletes the storage controller with the given name.
func (*Machine) GetDockerPort ¶ added in v1.2.0
Get Docker port
func (*Machine) GetSerialFile ¶ added in v1.2.0
Get serial file
func (*Machine) GetState ¶ added in v1.2.0
func (m *Machine) GetState() driver.MachineState
Get current state
func (*Machine) Poweroff ¶
Poweroff forcefully stops the machine. State is lost and might corrupt the disk image.
func (*Machine) Reset ¶
Reset forcefully restarts the machine. State is lost and might corrupt the disk image.