Documentation ¶
Overview ¶
Package vboxdriver implements the kutti VMDriver and associated interfaces for VirtualBox.
It requires VirtualBox 6.0 or higher.
Index ¶
- Variables
- type VBoxVMDriver
- func (vd *VBoxVMDriver) CreateHost(hostname string, networkname string, clustername string, k8sversion string) (core.VMHost, error)
- func (vd *VBoxVMDriver) CreateNetwork(netname string) (core.VMNetwork, error)
- func (vd *VBoxVMDriver) DeleteHost(hostname string, networkname string, clustername string) error
- func (vd *VBoxVMDriver) DeleteNetwork(netname string) error
- func (vd *VBoxVMDriver) Description() string
- func (vd *VBoxVMDriver) FetchImageList() error
- func (vd *VBoxVMDriver) GetHost(hostname string, networkname string, clustername string) (core.VMHost, error)
- func (vd *VBoxVMDriver) GetImage(k8sversion string) (core.VMImage, error)
- func (vd *VBoxVMDriver) GetNetwork(netname string) (core.VMNetwork, error)
- func (vd *VBoxVMDriver) ListHosts() ([]core.VMHost, error)
- func (vd *VBoxVMDriver) ListImages() ([]core.VMImage, error)
- func (vd *VBoxVMDriver) ListK8sVersions() ([]string, error)
- func (vd *VBoxVMDriver) ListNetworks() ([]core.VMNetwork, error)
- func (vd *VBoxVMDriver) Name() string
- func (vd *VBoxVMDriver) RequiresPortForwarding() bool
- func (vd *VBoxVMDriver) Status() string
- type VBoxVMHost
- func (vh *VBoxVMHost) ForceStop() error
- func (vh *VBoxVMHost) ForwardPort(hostport int, vmport int) error
- func (vh *VBoxVMHost) ForwardSSHPort(hostport int) error
- func (vh *VBoxVMHost) Name() string
- func (vh *VBoxVMHost) SSHAddress() string
- func (vh *VBoxVMHost) Start() error
- func (vh *VBoxVMHost) Status() string
- func (vh *VBoxVMHost) Stop() error
- func (vh *VBoxVMHost) UnforwardPort(vmport int) error
- func (vh *VBoxVMHost) WaitForStateChange(timeoutinseconds int)
- type VBoxVMImage
- type VBoxVMNetwork
Constants ¶
This section is empty.
Variables ¶
var DefaultNetCIDR = "192.168.125.0/24"
DefaultNetCIDR is the address range used by virtual networks.
var ImagesSourceURL string = "https://github.com/rajch/kutti-images/releases/download/v0.1.13-beta/kutti-images.json"
ImagesSourceURL is the location where the master list of images can be found
Functions ¶
This section is empty.
Types ¶
type VBoxVMDriver ¶
type VBoxVMDriver struct {
// contains filtered or unexported fields
}
VBoxVMDriver implements the VMDriver interface for VirtualBox.
func New ¶
func New() (*VBoxVMDriver, error)
New returns a pointer to a new VBoxVMDriver or an error.
func (*VBoxVMDriver) CreateHost ¶
func (vd *VBoxVMDriver) CreateHost(hostname string, networkname string, clustername string, k8sversion string) (core.VMHost, error)
CreateHost creates a VM, and connects it to a previously created NAT network. It also starts the VM, changes the hostname, saves the IP address, and stops it again. It runs the following two VBoxManage commands, in order:
VBoxManage import <nodeimageovafile> --vsys 0 --vmname "<hostname>" VBoxManage modifyvm "<hostname>" --nic1 natnetwork --nat-network1 <networkname>
The first imports from an .ova file (easiest way to get fully configured VM), while setting the VM name. The second connects the first network interface card to the NAT network.
func (*VBoxVMDriver) CreateNetwork ¶
func (vd *VBoxVMDriver) CreateNetwork(netname string) (core.VMNetwork, error)
CreateNetwork creates a new VirtualBox NAT network. It uses the CIDR common to all Kutti networks, and is dhcp-enabled at start.
func (*VBoxVMDriver) DeleteHost ¶
func (vd *VBoxVMDriver) DeleteHost(hostname string, networkname string, clustername string) error
DeleteHost deletes a VM. It does this by running the command:
VBoxManage unregistervm "<hostname>" --delete
func (*VBoxVMDriver) DeleteNetwork ¶
func (vd *VBoxVMDriver) DeleteNetwork(netname string) error
DeleteNetwork deletes a network. It does this by running the command:
VBoxManage natnetwork remove --netname <networkname>
func (*VBoxVMDriver) Description ¶
func (vd *VBoxVMDriver) Description() string
Description returns the driver description.
func (*VBoxVMDriver) FetchImageList ¶
func (vd *VBoxVMDriver) FetchImageList() error
FetchImageList fetches the latest list of VM images.
func (*VBoxVMDriver) GetHost ¶
func (vd *VBoxVMDriver) GetHost(hostname string, networkname string, clustername string) (core.VMHost, error)
GetHost returns the named host, or an error. It does this by running the command:
VBoxManage guestprorty enumerate <hostname> --patterns "/VirtualBox/GuestInfo/Net/0/*|/kutti/*|/VirtualBox/GuestInfo/OS/LoggedInUsers"
func (*VBoxVMDriver) GetImage ¶
func (vd *VBoxVMDriver) GetImage(k8sversion string) (core.VMImage, error)
GetImage returns an image corresponding to a Kubernetes version, or an error.
func (*VBoxVMDriver) GetNetwork ¶
func (vd *VBoxVMDriver) GetNetwork(netname string) (core.VMNetwork, error)
GetNetwork returns a network, or an error.
func (*VBoxVMDriver) ListHosts ¶
func (vd *VBoxVMDriver) ListHosts() ([]core.VMHost, error)
ListHosts parses the list of VMs returned by
VBoxManage list vms
As of VBoxManage 6.0.8r130520, the format is:
"Matsya" {e3509073-d188-4cca-8eaf-cb9f3be7ac4a} "Krishna" {5d9b1b16-5059-42ae-a160-e93b470f940e} "one" {06748689-7f4e-4915-8fbf-6111596f85a2} "two" {eee169a7-09eb-473e-96be-5d37868c5d5e} "minikube" {5bf78b43-3240-4f50-911b-fbc111d4d085} "Node 1" {53b82a61-ae52-44c2-86d5-4c686502dd64}
func (*VBoxVMDriver) ListImages ¶
func (vd *VBoxVMDriver) ListImages() ([]core.VMImage, error)
ListImages lists the known VM images.
func (*VBoxVMDriver) ListK8sVersions ¶
func (vd *VBoxVMDriver) ListK8sVersions() ([]string, error)
ListK8sVersions lists the known Kubernetes versions.
func (*VBoxVMDriver) ListNetworks ¶
func (vd *VBoxVMDriver) ListNetworks() ([]core.VMNetwork, error)
ListNetworks parses the list of NAT networks returned by
VBoxManage natnetwork list
As of VBoxManage 6.0.8r130520, the format is:
NAT Networks: Name: KubeNet Network: 10.0.2.0/24 Gateway: 10.0.2.1 IPv6: No Enabled: Yes Name: NatNetwork Network: 10.0.2.0/24 Gateway: 10.0.2.1 IPv6: No Enabled: Yes Name: NatNetwork1 Network: 10.0.2.0/24 Gateway: 10.0.2.1 IPv6: No Enabled: Yes 3 networks found
Note the blank lines: one before and after each network. If there are zero networks, the output is:
NAT Networks: 0 networks found
func (*VBoxVMDriver) Name ¶
func (vd *VBoxVMDriver) Name() string
Name returns the driver identifier string.
func (*VBoxVMDriver) RequiresPortForwarding ¶
func (vd *VBoxVMDriver) RequiresPortForwarding() bool
RequiresPortForwarding specifies if the driver's networks use NAT, and therefore require host ports to be forwarded.
func (*VBoxVMDriver) Status ¶
func (vd *VBoxVMDriver) Status() string
Status returns the driver status.
type VBoxVMHost ¶
type VBoxVMHost struct {
// contains filtered or unexported fields
}
VBoxVMHost implements the VMHost interface for VirtualBox
func (*VBoxVMHost) ForceStop ¶
func (vh *VBoxVMHost) ForceStop() error
ForceStop stops a VM host forcibly. It does this by running the command:
VBoxManage controlvm <hostname> poweroff
func (*VBoxVMHost) ForwardPort ¶
func (vh *VBoxVMHost) ForwardPort(hostport int, vmport int) error
ForwardPort creates a rule to forward the specified VM host port to the specified physical host port. It does this by running the command:
VBoxManage natnetwork modify --netname <networkname> --port-forward-4 <rule>
Port forwarding rule format is:
<rule name>:<protocol>:[<host ip>]:<host port>:[<guest ip>]:<guest port>
The brackets [] are to be taken literally. This driver writes the rule name as "Node <nodename> Port <vmport>".
func (*VBoxVMHost) ForwardSSHPort ¶
func (vh *VBoxVMHost) ForwardSSHPort(hostport int) error
ForwardSSHPort forwards the SSH port of a VM host to the specified physical host port. See ForwardPort for details.
func (*VBoxVMHost) SSHAddress ¶
func (vh *VBoxVMHost) SSHAddress() string
SSHAddress returns the address and port number to SSH into this VM host.
func (*VBoxVMHost) Start ¶
func (vh *VBoxVMHost) Start() error
Start starts a VM host. It does this by running the command:
VBoxManage startvm <hostname> --type headless
Note that a VM host may not be ready for further operations at the end of this. See WaitForStateChange.
func (*VBoxVMHost) Status ¶
func (vh *VBoxVMHost) Status() string
Status can be Stopped, Running or Error.
func (*VBoxVMHost) Stop ¶
func (vh *VBoxVMHost) Stop() error
Stop stops a VM host. It does this by running the command:
VBoxManage controlvm <hostname> acpipowerbutton
Note that a VM host may not be ready for further operations at the end of this. See WaitForStateChange.
func (*VBoxVMHost) UnforwardPort ¶
func (vh *VBoxVMHost) UnforwardPort(vmport int) error
UnforwardPort removes the rule which forwarded the specified VM host port. It does this by running the command:
VBoxManage natnetwork modify --netname <networkname> --port-forward-4 delete <rulename>
This driver writes the rule name as "Node <nodename> Port <vmport>".
func (*VBoxVMHost) WaitForStateChange ¶
func (vh *VBoxVMHost) WaitForStateChange(timeoutinseconds int)
WaitForStateChange waits the specified number of seconds, or until the VM host status changes from Stopped to Running or vice versa. It does this by running the command:
VBoxManage guestproperty wait <hostname> /VirtualBox/GuestInfo/OS/LoggedInUsers --timeout <milliseconds> --fail-on-timeout
WaitForStateChange should be called after a call to Start, before any other operation. From observation, it should not be called before Stop.
type VBoxVMImage ¶
type VBoxVMImage struct { ImageK8sVersion string ImageChecksum string ImageSourceURL string ImageStatus string }
VBoxVMImage implements the VMImage interface for VirtualBox.
func (*VBoxVMImage) Fetch ¶
func (i *VBoxVMImage) Fetch() error
Fetch fetches the image from its source URL.
func (*VBoxVMImage) FromFile ¶
func (i *VBoxVMImage) FromFile(filepath string) error
FromFile verifies an image file on a local path, and if valid, copies it to the cache.
func (*VBoxVMImage) K8sVersion ¶
func (i *VBoxVMImage) K8sVersion() string
K8sVersion returns the version of Kubernetes present in the image.
func (*VBoxVMImage) PurgeLocal ¶
func (i *VBoxVMImage) PurgeLocal() error
PurgeLocal removes the local cached copy of an image.
func (*VBoxVMImage) Status ¶
func (i *VBoxVMImage) Status() string
Status returns the status of the image. Status can be Available, meaning the image exists in the local cache and can be used to create hosts, or Unavailable, meaning it has to be downloaded using Fetch.
type VBoxVMNetwork ¶
type VBoxVMNetwork struct {
// contains filtered or unexported fields
}
VBoxVMNetwork implements the VMNetwork interface for VirtualBox.
func (*VBoxVMNetwork) Name ¶
func (vn *VBoxVMNetwork) Name() string
Name is the name of the network.
func (*VBoxVMNetwork) NetCIDR ¶
func (vn *VBoxVMNetwork) NetCIDR() string
NetCIDR is the network's IPv4 address range.