Categorygithub.com/sh-agilebot/go-virtualbox
modulepackage
0.0.7
Repository: https://github.com/sh-agilebot/go-virtualbox.git
Documentation: pkg.go.dev

# README

go-virtualbox

This is a wrapper package for Golang to interact with VirtualBox. The API is experimental at the moment and you should expect frequent changes. There is no compatibility guarantee between newer and older versions of Virtualbox.

Table of Contents

  1. Status
  2. Usage
    1. Library
    2. Commands
    3. Documentation
  3. Building
  4. Testing
    1. Preparation
    2. Run tests
    3. Re-generate mock
  5. Caveats

Status

ProjectStatusNotes
Github ActionsContinuous Integration
Go Report CardGo Report Cardscan code with gofmt, go vet, gocyclo, golint, ineffassign, license and misspell.
GoDocGo Doc
ReleaseRelease

Usage

Library

The part of the library that manages guest properties can run both from the Host and the Guest.

    err := virtualbox.SetGuestProperty("MyVM", "test_key", "test_val")
    val, err := GetGuestProperty(VM, "test_key")

See GoDoc for full details.

Commands

The vbhostd commands waits on the vbhostd/* guest-properties pattern.

  • When the guest writes a value on the vbhostd/open, it causes the host to open the given location:
    • Write http://www.hp.com will open the default browser as the given URL
    • Write mailto:[email protected][email protected] opens the default mailer pre-filling the recipient and carbon-copy recipient fields

Documentation

For the released version, see GoDoc:terra-farm/go-virtualbox. To see the local documentation, run godoc -http=:6060 & and then open http://localhost:6060/pkg/github.com/sh-agilebot/go-virtualbox/.

Building

First install dependencies

  • GoLang
  • GNU Make (Windows: via `choco install -y gnuwin32-make.portable)

Get Go dependencies: make deps or:

$ go get -v github.com/golang/dep/cmd/dep
$ dep ensure -v

Then build: make build or:

$ go build -v ./...
  • default run everything in order
  • deps install dependencies (dep and others)
  • build run go build ./...
  • test run go test ./...
  • lint only run gometalinter linter

Testing

Preparation

Tests run using mocked interfaces, unless the TEST_VM environment variable is set, in order to test against real VirtualBox. You either need to have a pre-provisioned VirtualBox VM and to set its name using the TEST_VM environment variable, or use Vagrant.

$ vagrant box add bento/ubuntu-16.04
# select virtualbox as provider

$ vagrant up

Then run the tests

$ export TEST_VM=go-virtualbox
$ go test

...or (on Windows):

> set TEST_VM=go-virtualbox
> go test

Once you are done with testing, run vagrant halt to same resources.

Run tests

As usual, run go test, or go test -v. To run one test in particular, run go test --run TestGuestProperty.

Re-generate mock

go generate ./...

Using local changes with your own project

If you have a project which depends on this library, you probably want to test your local changes of go-virtualbox in your project. See this article on how to set up your environment to do this.

# Packages

No description provided by the author

# Functions

AddHostonlyDHCP adds a DHCP server to a host-only network.
AddInternalDHCP adds a DHCP server to an internal network.
CloneHD virtual harddrive.
CloneMachine clones the given machine name into a new one.
CreateHostonlyNet creates a new host-only network.
CreateMachine creates a new machine.
DeleteGuestProperty deletes a VirtualBox guestproperty.
DelExtra deletes extra data.
DHCPs gets all DHCP server settings in a map keyed by DHCP.NetworkName.
GetGuestProperty reads a VirtualBox guestproperty.
GetMachine finds a machine by its name or UUID.
HostonlyNets gets all host-only networks in a map keyed by HostonlyNet.NetworkName.
ImportOV imports ova or ovf from the given path.
ListMachines lists all registered machines.
Logger allows to override the logger used by the manager.
MakeDiskImage makes a disk image at dest with the given size in MB.
Manage returns the Command to run VBoxManage/VBoxControl.
NATNets gets all NAT networks in a map keyed by NATNet.Name.
New creates a new machine.
NewManager returns a manager capable of managing everything in virtualbox.
NewMockCommand creates a new mock instance.
ParseIPv4Mask parses IPv4 netmask written in IP form (e.g.
Run is a helper method used to execute the commands using the configured VBoxManage path.
SetExtra sets extra data.
SetGuestProperty writes a VirtualBox guestproperty to the given value.
WaitGuestProperties wait for changes in GuestProperties WaitGetProperties wait for changes in the VirtualBox GuestProperties matching the given propsPattern, for the given VM.
WaitGuestProperty blocks until a VirtualBox guestproperty is changed The key to wait for can be a fully defined key or a key wild-card (glob-pattern).
ZeroFill writes n zero bytes into w.

# Constants

Aborted is a MachineState value.
Flag names in lowercases to be consistent with VBoxManage options.
Flag names in lowercases to be consistent with VBoxManage options.
AMDPCNetFASTIII when the NIC emulates a Am79C973 hardware.
AMDPCNetPCIII when the NIC emulates a Am79C970A hardware.
Flag names in lowercases to be consistent with VBoxManage options.
CtrlBusLogic when the storage controller emulates BusLogic hardware.
CtrlI82078 when the storage controller emulates I82078 hardware.
CtrlICH6 when the storage controller emulates ICH6 hardware.
CtrlIntelAHCI when the storage controller emulates IntelAHCI hardware.
CtrlLSILogic when the storage controller emulates LSILogic hardware.
CtrlLSILogicSAS when the storage controller emulates LSILogicSAS hardware.
CtrlNVME storage controller emulates NVME hardware.
CtrlPIIX3 when the storage controller emulates PIIX3 hardware.
CtrlPIIX4 when the storage controller emulates PIIX4 hardware.
CtrlUSB storage controller emulates USB hardware.
CtrlVirtIO storage controller emulates VirtIO hardware.
DriveDVD when the drive is a DVD reader/writer.
DriveFDD when the drive is a floppy.
DriveHDD when the drive is a hard disk or SSD.
Flag names in lowercases to be consistent with VBoxManage options.
Flag names in lowercases to be consistent with VBoxManage options.
No description provided by the author
IntelPro1000MTDesktop when the NIC emulates a 82540EM hardware.
IntelPro1000MTServer when the NIC emulates a 82545EM hardware.
IntelPro1000TServer when the NIC emulates a 82543GC hardware.
Flag names in lowercases to be consistent with VBoxManage options.
No description provided by the author
No description provided by the author
Flag names in lowercases to be consistent with VBoxManage options.
Flag names in lowercases to be consistent with VBoxManage options.
Flag names in lowercases to be consistent with VBoxManage options.
NICNetAbsent when there is no NIC.
NICNetBridged when the NIC is the bridge to the external network.
NICNetDisconnected when the NIC is disconnected.
NICNetGeneric when the NIC behaves like a standard physical one.
NICNetHostonly when the NIC can only access one host-only network.
NICNetInternal when the NIC does not have access to the external network.
NICNetNAT when the NIC is NAT-ed to access the external network.
Flag names in lowercases to be consistent with VBoxManage options.
Paused is a MachineState value.
PFTCP when forwarding a TCP port.
PFUDP when forwarding an UDP port.
Poweroff is a MachineState value.
Flag names in lowercases to be consistent with VBoxManage options.
Running is a MachineState value.
Saved is a MachineState value.
SysBusFloppy when the storage controller provides access to Floppy drives.
SysBusIDE when the storage controller provides an IDE bus.
SysBusPCIE storage controller proveds a PCIe bus.
SysBusSAS storage controller provides a SAS bus.
SysBusSATA when the storage controller provides a SATA bus.
SysBusSCSI when the storage controller provides an SCSI bus.
SysBusUSB storage controller proveds an USB bus.
SysBusVirtio storage controller proveds a Virtio bus.
Flag names in lowercases to be consistent with VBoxManage options.
VirtIO when the NIC emulates a virtio.
Flag names in lowercases to be consistent with VBoxManage options.
Flag names in lowercases to be consistent with VBoxManage options.

# Variables

Debug is the Logger currently in use.
ErrCommandNotFound holds the error message when the VBoxManage commands was not found.
No description provided by the author
ErrHostonlyInterfaceCreation is the error message created when VBoxManaged failed to create a new hostonly interface.
ErrMachineExist holds the error message when the machine already exists.
ErrMachineNotExist holds the error message when the machine does not exist.
Verbose toggles the library in verbose execution mode.

# Structs

DHCP server info.
GuestProperty holds key, value and associated flags.
HostonlyNet defines each host-only network.
Machine information.
Manager of the virtualbox instance.
MockCommand is a mock of Command interface.
MockCommandMockRecorder is the mock recorder for MockCommand.
A NATNet defines a NAT network.
NIC represents a virtualized network interface card.
PFRule represents a port forwarding rule.
StorageController represents a virtualized storage controller.
StorageMedium represents the storage medium attached to a storage controller.

# Interfaces

Command is the mock-able interface to run VirtualBox commands such as VBoxManage (host side) or VBoxControl (guest side).
MachineManager defines the actions that can be performed to manage machines.
Virtualbox interface defines all the actions which can be performed by the Manager.

# Type aliases

DriveType represents the hardware type of a drive.
Flag is an active VM configuration toggle.
No description provided by the author
LogFunc is the signature to log traces.
MachineState stores the last retrieved VM state.
NICHardware represents the type of NIC hardware.
NICNetwork represents the type of NIC networks.
Option modifies the manager options.
PFProto represents the protocol of a port forwarding rule.
StorageControllerChipset represents the hardware of a storage controller.
SystemBus represents the system bus of a storage controller.