Skip to content

Instantly share code, notes, and snippets.

@ffledgling
Last active July 10, 2017 14:47
Show Gist options
  • Select an option

  • Save ffledgling/481aabc59e2d4ff81d4bcb43f4096324 to your computer and use it in GitHub Desktop.

Select an option

Save ffledgling/481aabc59e2d4ff81d4bcb43f4096324 to your computer and use it in GitHub Desktop.
ceph-go example: List volumes in a particular pool
func listRBDVols() error {
// Runs the equivalent of rbd --pool ffledgling-pool ls
// Contains basic connection logic that's reusable
log.Println("Function started...") // We have this because connection setup etc take a while.
// If like me, you tried this first and expected it to work, it doesn't:
/*
conn, _ := rados.NewConn()
args := []string{"--name", "client.ffledgling", "--conf", "/home/ffledgling/ceph.conf"}
conn.ParseCmdLineArgs(args)
*/
conn, _ := rados.NewConnWithUser("ffledgling")
conn.ReadConfigFile("/home/ffledgling/ceph.conf")
if err := conn.Connect(); err != nil {
log.Fatalln("Connection Failed.", err)
return err
}
// Get the list of volumes in a particular pool
iox, err := conn.OpenIOContext("ffledgling-pool")
if err != nil {
log.Println("IOX:", err)
return err
}
vols, err := rbd.GetImageNames(iox)
if err != nil {
log.Println("Image list failed.", err)
}
for i, e := range vols {
log.Println(i, e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment