Created
July 10, 2017 14:44
-
-
Save ffledgling/114f631f6d07ede0f07fd715ded75d94 to your computer and use it in GitHub Desktop.
ceph-go example: create rbd volume with image features
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func createRBDStorage() 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 | |
| } | |
| /* | |
| * We also pass rbd image options set to 1, which enables *only* layering. | |
| * Follow up reading: | |
| * Explanation of features: http://tracker.ceph.com/issues/15000 | |
| * Slightly user-friendly blog post: https://www.sebastien-han.fr/blog/2015/07/06/ceph-enable-the-object-map-feature/ | |
| */ | |
| iox, err := conn.OpenIOContext("ffledgling-pool") | |
| image, err := rbd.Create(iox, "go-test-vol", 1024*1024*1024*100, 22, 1) | |
| if err != nil { | |
| log.Println("RBD image creation failed", err) | |
| return err | |
| } | |
| // Check the volume was created. | |
| vols, err = rbd.GetImageNames(iox) | |
| if err != nil { | |
| log.Println("IOX:", err) | |
| return err | |
| } | |
| for i, e := range vols { | |
| log.Println(i, e) | |
| } | |
| // Clean up after ourselves. | |
| image.Close() | |
| iox.Destroy() | |
| conn.Shutdown() | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment