All Projects → pitstopcloud → virtualbox-go

pitstopcloud / virtualbox-go

Licence: other
Most complete golang library for virtualbox

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to virtualbox-go

Xv6 Book Chinese
MIT操作系统工程的教学操作系统Xv6的源码剖析中文翻译项目,使用ANSI标准C重新在riscv架构上实现Unix v6;
Stars: ✭ 223 (+182.28%)
Mutual labels:  virtualbox
packer-centos
Create CentOS images for different hypervisors with Packer
Stars: ✭ 18 (-77.22%)
Mutual labels:  virtualbox
iosxrv-x64-vbox
IOS XR VirtualBox Vagrant Image Generation tools
Stars: ✭ 72 (-8.86%)
Mutual labels:  virtualbox
Awesome Vm Exploit
share some useful archives about vm and qemu escape exploit.
Stars: ✭ 239 (+202.53%)
Mutual labels:  virtualbox
rhino
Agile Sandbox for analyzing Windows, Linux and macOS malware and execution behaviors
Stars: ✭ 49 (-37.97%)
Mutual labels:  virtualbox
development-environment
A development environment for Java, Python, Node.js and Go built using Vagrant
Stars: ✭ 50 (-36.71%)
Mutual labels:  virtualbox
Packer Templates
Scripts and Templates used for generating Vagrant images
Stars: ✭ 219 (+177.22%)
Mutual labels:  virtualbox
packer-windows
Windows Templates for Packer: Windows 11, Windows 10, Windows Server 2022, 2019, 2016, also with Docker
Stars: ✭ 1,116 (+1312.66%)
Mutual labels:  virtualbox
ansible-role-virtualbox
Ansible Role - Installs headless Virtualbox and phpVirtualbox for remote access through Web GUI
Stars: ✭ 14 (-82.28%)
Mutual labels:  virtualbox
hassio-vagrant
Vagrant box running Hass.io / Home Assistant
Stars: ✭ 42 (-46.84%)
Mutual labels:  virtualbox
Terraform Provider Virtualbox
VirtualBox provider for Terraform
Stars: ✭ 239 (+202.53%)
Mutual labels:  virtualbox
Vagrantboxes
Handcrafted Arch Linux Vagrant base box with ❤️
Stars: ✭ 242 (+206.33%)
Mutual labels:  virtualbox
vagrant-boot2docker-swarm
A multi-machine Docker swarm Vagrant environment
Stars: ✭ 16 (-79.75%)
Mutual labels:  virtualbox
Node Virtualbox
A JavaScript Library for Interacting with VirtualBox
Stars: ✭ 231 (+192.41%)
Mutual labels:  virtualbox
nodejs-dev-vm
DEPRECATED Simple Node.js Development VM using Vagrant + VirtualBox + Ansible
Stars: ✭ 25 (-68.35%)
Mutual labels:  virtualbox
Packer Centos 7
This build has been moved - see README.md
Stars: ✭ 223 (+182.28%)
Mutual labels:  virtualbox
guix-vm
Scripts and support necessary to make a GuixSD Virtualbox image
Stars: ✭ 18 (-77.22%)
Mutual labels:  virtualbox
Implementaion-of-Private-Cloud-using-ownCloud
Implementation of Private Cloud using ownCloud. ownCloud is a suite of client–server software for creating and using file hosting services. This repository explains implementing ownCloud on an Ubuntu VM running on top of a Windows host for secure cloud storage
Stars: ✭ 30 (-62.03%)
Mutual labels:  virtualbox
upstream-institute-virtual-environment
A Vagrant-based image creator for OpenStack Upstream Training sessions
Stars: ✭ 18 (-77.22%)
Mutual labels:  virtualbox
game-of-thrones-hacking-ctf
Game of Thrones hacking CTF (Capture the flag)
Stars: ✭ 57 (-27.85%)
Mutual labels:  virtualbox

virtualbox-go

The most complete Golang wrapper for virtualbox for macOS (Not tested on other platforms). This library includes a wide range of support for different virtualbox operations that include dhcp, disk, network, virtualmachines, power, etc. You can use this library to stitch your own network and compute topology using virtualbox. Refer to examples for more details.

What is Virtualbox ?

From here, Oracle VM VirtualBox is a cross-platform virtualization application. What does that mean? For one thing, it installs on your existing Intel or AMD-based computers, whether they are running Windows, Mac OS X, Linux, or Oracle Solaris operating systems (OSes). Secondly, it extends the capabilities of your existing computer so that it can run multiple OSes, inside multiple virtual machines, at the same time. As an example, you can run Windows and Linux on your Mac, run Windows Server 2016 on your Linux server, run Linux on your Windows PC, and so on, all alongside your existing applications. You can install and run as many virtual machines as you like. The only practical limits are disk space and memory.

Use cases include:

  • Testing new network topology
  • Testing new routing methodologies
  • Testing new container networking
  • Testing new Kubernetes network plugins
  • Testing new software defined firewalls and gateways
  • Local simulation of a datacenter L2/L3/L4 usecases.

Prerequisites

  • MacOS > High Sierra 10.13.1 (Not tested on other OS)
  • Virtualbox > 5.1.28r117968
  • Golang > 1.5

Installation

You can add virtualbox-go to your GOPATH by running:

go get -u github.com/uruddarraju/virtualbox-go

You can then add the following imports to your golang code for you to start using it and having fun:

import (
    vbg "github.com/uruddarraju/virtualbox-go"
)

Examples

Create a Virtual Machine

func CreateVM() {
    // setup temp directory, that will be used to cache different VM related files during the creation of the VM.
    dirName, err := ioutil.TempDir("", "vbm")  
    if err != nil {  
       t.Errorf("Tempdir creation failed %v", err)  
    }
    defer os.RemoveAll(dirName)  
      
    vb := vbg.NewVBox(vbg.Config{  
       BasePath: dirName,  
    })  
      
    disk1 := vbg.Disk{  
      Path:   filepath.Join(dirName, "disk1.vdi"),  
      Format: VDI,  
      SizeMB: 10,  
    }  
      
    err = vb.CreateDisk(&disk1)  
    if err != nil {  
       t.Errorf("CreateDisk failed %v", err)  
    }  
      
    vm := &vbg.VirtualMachine{}  
    vm.Spec.Name = "testvm1"  
    vm.Spec.OSType = Linux64  
    vm.Spec.CPU.Count = 2  
    vm.Spec.Memory.SizeMB = 1000  
    vm.Spec.Disks = []vbg.Disk{disk1}  
      
    err = vb.CreateVM(vm)  
    if err != nil {  
       t.Fatalf("Failed creating vm %v", err)  
    }  
      
    err = vb.RegisterVM(vm)  
    if err != nil {  
       t.Fatalf("Failed registering vm")  
    }
}

Get VM Info

func GetVMInfo(name string) (machine *vbm.VirtualMachine, err error) {
    vb := vbg.NewVBox(vbg.Config{})
    return vb.VMInfo(name)
}

Managing states of a Virtual Machine

func ManageStates(vm *vbg.VirtualMachine) {
    vb := vbg.NewVBox(vbg.Config{})
    ctx := context.Background()  
    context.WithTimeout(ctx, 1*time.Minute)
    // Start a VM, this call is idempotent.
    _, err = vb.Start(vm)  
    if err != nil {  
       t.Fatalf("Failed to start vm %s, error %v", vm.Spec.Name, err)  
    }  
    
    // Reset a VM
    _, err = vb.Reset(vm)  
    if err != nil {  
       t.Fatalf("Failed to reset vm %s, error %v", vm.Spec.Name, err)  
    }
    
    // Pause and Resume VMs
    _, err = vb.Pause(vm)  
    if err != nil {  
       t.Fatalf("Failed to pause vm %s, error %v", vm.Spec.Name, err)  
    }
    _, err = vb.Resume(vm)  
    if err != nil {  
       t.Fatalf("Failed to resume vm %s, error %v", vm.Spec.Name, err)  
    }
    
    // Stop a VM, this call is also idempotent.
    _, err = vb.Stop(vm)  
    if err != nil {  
       t.Fatalf("Failed to stop vm %s, error %v", vm.Spec.Name, err)  
    }
}

Attach New Disk to existing VM

func AttachDisk(vm *vbg.VirtualMachine) error {
    disk2 := &vbg.Disk{  
      Path:   filepath.Join(dirName, "disk2.vdi"),  
      Format: VDI,  
      SizeMB: 100,  
    }  
    vb := vbg.NewVBox(vbg.Config{})
    ctx := context.Background()  
    context.WithTimeout(ctx, 1*time.Minute)
    vb.AttachStorage(vm, disk2)
}

More Documentation

Coming soon....

Why did I build it and not use something else ?

I looked around a lot for clean implementations of virtualbox golang wrappers, but could not find anything with high quality and test coverage, and also most libraries out there only have support for a few operations in virtualbox but not everything. The closest match to my requirements was libmachine from docker, but it had some tight coupling with the rest of docker packages which I definitely did not want to use. Also, it was very difficult finding something that had good documentation and examples. You might not find these to be good enough reasons to start a new project, but I found them compelling enough to start my own.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].