Creating Ceph block devices and snapshots based on Go-ceph

Source: Internet
Author: User

First, prepare the code before execution

1. Ceph cluster installed in the system

2. Src/github.com/noahdesu/go-ceph code base exists in Gopath directory

3, under Ubuntu 14.04 also need to Apt-get Librados-dev and Librbd-dev two packs

Second, code example

Package main import ("FMT" "Github.com/noahdesu/go-ceph/rados" "GITHUB.COM/NOAHDESU/GO-CEPH/RBD") const ( Defaultradosconfigfile = "/etc/ceph/ceph.conf" defaultbaseimagesize = ten * 1024x768 * 1024x768 * 1024DefaultPoolName = "RBD") func m Ain () {//Connect to the Clusterconn,_: = Rados. Newconn () If ERR: = conn. Readconfigfile (Defaultradosconfigfile); Err! = Nil {fmt. Printf ("Rbd read config failed:%v", err) return}if ERR: = conn. Connect (); Err! = Nil {fmt. Printf ("RBD Connect failed:%v", err) return}//connect to the POOLIOCTX,ERR: = conn. Openiocontext (defaultpoolname) if err! = Nil {fmt. Printf ("RBD Open pool failed:%v", err) return}//Create base imagebaseimagename: = "Test" _,err = Rbd. Create (IOCTX,BASEIMAGENAME,DEFAULTBASEIMAGESIZE,RBD. rbdfeaturelayering) If err! = Nil {fmt. Printf ("RBD Create image failed:%v", err) return}img: = Rbd. GetImage (Ioctx,baseimagename)//We should open base image firstif ERR: = img. Open (); Err! = Nil {fmt. Printf ("RBD Open image failed:%v", err) return}defer img. Close ()//Create SNAPshotsnapname: = "Test-snap" snapshot,err: = img. CreateSnapshot (snapname) if err! = Nil {fmt. Printf ("RBD Create snapshot failed:%v", err) return}//Protect Snapshot If err: = Snapshot. Protect (); Err! = Nil {fmt. Printf ("RBD Create snapshot failed:%v", err) return}//make a clone image based on the snap shotcloneimagename: = "clone-t EST "_,err = img. Clone (SNAPNAME,IOCTX,CLONEIMAGENAME,RBD. rbdfeaturelayering) If err! = Nil {fmt. Printf ("Rbd clone snapshot failed:%v", err) return}return}

  

Finally, a base image named "Test" is generated and a snapshot based on "test" named "Test-snap", and finally a clone based on snapshot "Test-snap".

Note: When you create the "test", the size parameter cannot be too small, or an error occurs when the snapshot is created.

Creating Ceph block devices and snapshots based on Go-ceph

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.