Skip to content

Instantly share code, notes, and snippets.

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

  • Save ffledgling/7cab94c297ed23b3dfb425692d5a775c to your computer and use it in GitHub Desktop.

Select an option

Save ffledgling/7cab94c297ed23b3dfb425692d5a775c to your computer and use it in GitHub Desktop.
ceph-go example: Connect to cluster, list osd pools
func listOSDPools() {
// Runs the equivalent of ceph osd lspools
// Contains basic connection logic that's reusable
log.Println("Function started...") // We have this because connection 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)
}
// Get the list of pools
list, err := conn.ListPools()
if err != nil {
log.Println(err)
}
for i, e := range list {
log.Println(i, e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment