Not under active development.
This provides facilities to Create, Delete, Map, and Unmap RBD Images. It
communicates with the librados/librbd C bindings and the krbd kernel module
directly. Most programs that leverage this library will wish to run as root
.
This code will:
- Open a connection to the
rbd
pool - Creates an image called
test
(Removing it before if necessary) - Maps it to a block device on the local host
- Creates a snapshot of the image, called
test-snap
. - Lists and prints the snapshots available.
package main
import (
"fmt"
"github.com/contiv/librbd"
)
func main() {
config := librbd.RBDConfig{
MonitorIP: "86.75.30.9",
UserName: "admin",
Secret: "s3kr1t",
}
pool, err := GetPool(config, "rbd")
if err != nil {
panic(err)
}
// it's ok if it fails, we just don't want the next call to unless stuff is
// broken.
pool.RemoveImage("test")
if err := pool.CreateImage("test", 10000000); err != nil {
panic(err)
}
img, err := pool.GetImage("test")
if err != nil {
panic(err)
}
device, err := img.MapDevice()
if err != nil {
panic(err)
}
if err := img.CreateSnapshot("test-snap"); err != nil {
panic(err)
}
list, err := img.ListSnapshots(100)
if err != nil {
panic(err)
}
fmt.Println(list)
}
Project Contiv: github.com/contiv
Apache 2.0.