Package libvirt provides a pure Go interface for interacting with Libvirt. Apache 2.0 Licensed.
Go to file
Ben LeMasurier d473469e69 Merge pull request #11 from digitalocean/migrate-padding
migrate: insert required request structure padding
2016-09-28 11:26:01 -06:00
internal/constants Add note to constants 2016-08-31 13:34:49 -04:00
libvirttest Add support for domain migrations 2016-08-21 09:10:30 -06:00
scripts Initial Commit 2016-05-19 19:40:34 -06:00
.travis.yml travis: use Go 1.7 2016-08-31 16:58:56 -04:00
AUTHORS Add cdrage to authors 2016-08-31 16:30:10 -04:00
CONTRIBUTING.md Initial Commit 2016-05-19 19:40:34 -06:00
doc.go Initial Commit 2016-05-19 19:40:34 -06:00
libvirt_test.go Add support for domain migrations 2016-08-21 09:10:30 -06:00
libvirt.go migrate: insert required request structure padding 2016-09-28 11:07:03 -06:00
LICENSE.md Initial Commit 2016-05-19 19:40:34 -06:00
README.md README: fixes broken go report card link 2016-06-27 12:59:01 -06:00
rpc_test.go Adds test package 2016-05-20 10:50:10 -06:00
rpc.go fixes response overwrite bug 2016-06-27 12:40:39 -06:00

libvirt GoDoc Build Status Report Card

Package libvirt provides a pure Go interface for interacting with Libvirt.

Rather than using Libvirt's C bindings, this package makes use of Libvirt's RPC interface, as documented here. Connections to the libvirt server may be local, or remote. RPC packets are encoded using the XDR standard as defined by RFC 4506.

This should be considered a work in progress. Most functionaly provided by the C bindings have not yet made their way into this library. Pull requests are welcome! The definition of the RPC protocol is in the libvirt source tree under src/rpc/virnetprotocol.x.

Warning

All packages contained in this repository should be treated as pre-production software with an unstable API.

While these package are reasonably well-tested and have seen some use inside of DigitalOcean, there may be subtle bugs which could cause the packages to act in unexpected ways. Use at your own risk!

In addition, the API is not considered stable at this time. If you would like to include package libvirt in a project, we highly recommend vendoring it into your project.

Example

package main

import (
	"fmt"
	"log"
	"net"
	"time"

	"github.com/digitalocean/go-libvirt"
)

func main() {
	//c, err := net.DialTimeout("tcp", "127.0.0.1:16509", 2*time.Second)
	//c, err := net.DialTimeout("tcp", "192.168.1.12:16509", 2*time.Second)
	c, err := net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", 2*time.Second)
	if err != nil {
		log.Fatalf("failed to dial libvirt: %v", err)
	}

	l := libvirt.New(c)
	if err := l.Connect(); err != nil {
		log.Fatalf("failed to connect: %v", err)
	}

	v, err := l.Version()
	if err != nil {
		log.Fatalf("failed to retrieve libvirt version: %v", err)
	}
	fmt.Println("Version:", v)

	domains, err := l.Domains()
	if err != nil {
		log.Fatalf("failed to retrieve domains: %v", err)
	}

	fmt.Println("ID\tName\t\tUUID")
	fmt.Printf("--------------------------------------------------------\n")
	for _, d := range domains {
		fmt.Printf("%d\t%s\t%x\n", d.ID, d.Name, d.UUID)
	}

	if err := l.Disconnect(); err != nil {
		log.Fatal("failed to disconnect: %v", err)
	}
}

Version: 1.3.4
ID	Name		UUID
--------------------------------------------------------
1	Test-1		dc329f87d4de47198cfd2e21c6105b01
2	Test-2		dc229f87d4de47198cfd2e21c6105b01