Skip to content

Golang interface to the QEMU hypervisor

License

Notifications You must be signed in to change notification settings

blacknut/go-qemu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-qemu

Golang interface to the QEMU hypervisor

Installation

go get github.com/quadrifoglio/go-qemu

You obviously need QEMU to use this tool.

Usage

Create an image

img := qemu.NewImage("vm.qcow2", qemu.ImageFormatQCOW2, 5*GiB)
img.SetBackingFile("debian.qcow2")

err := img.Create()
if err != nil {
	log.Fatal(err)
}

Open an existing image

img, err := qemu.OpenImage("debian.qcow2")
if err != nil {
	log.Fatal(err)
}

fmt.Println("image", img.Path, "format", img.Format, "size", img.Size)

Snapshots

err = img.CreateSnapshot("backup")
if err != nil {
	log.Fatal(err)
}

snaps, err := img.Snapshots()
if err != nil {
	log.Fatal(err)
}

for _, snapshot := range snaps {
	fmt.Println(snapshot.Name, snapshot.Date)
}

Start a virtual machine

img, err := qemu.OpenImage("debian.qcow2")
if err != nil {
	log.Fatal(err)
}

m := qemu.NewMachine(1, 512) // 1 CPU, 512MiB RAM
m.AddDrive(img)

// x86_64 arch (using qemu-system-x86_64), with kvm
pid, err := m.Start("x86_64", true, func(stderr string) {
        log.Println("QEMU stderr:", stderr)
})

if err != nil {
	log.Fatal(err)
}

fmt.Println("QEMU started on PID", pid)

License

WTFPL (Public Domain)

About

Golang interface to the QEMU hypervisor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%