Skip to content

Instantly share code, notes, and snippets.

@lemonlatte
Forked from bussyjd/radospybinddemo.py
Last active December 16, 2015 08:59
Show Gist options
  • Save lemonlatte/5409664 to your computer and use it in GitHub Desktop.
Save lemonlatte/5409664 to your computer and use it in GitHub Desktop.
### Import of the Python Rados library classes
### https://github.com/ceph/ceph/blob/master/src/pybind/rados.py
from rados import Rados,ObjectIterator
### Initialize Rados class
cluster = Rados()
### /etc/ceph/ceph.conf file is readen
cluster.conf_read_file()
print "Configuration file successfully loaded [OK]"
### Connection to the RADOS cluster
cluster.connect()
print "Connection to cluster initialised [OK]"
### Returns an array of the pools present in RADOS
print "The pools present in rados cluster are: \n", cluster.list_pools()
### Here I create a pool
cluster.create_pool("mypool")
### Opens a IO context
mypool = cluster.open_ioctx("mypool")
### I create data
data = 'mydata' * 10
### Object myobject is created with "My data" in it
mypool.write('myobject', data)
### data is outputed out of the RADOS cluster
print mypool.read('myobject')
### Close the IO context
mypool.close()
### The pool is deleted
cluster.delete_pool("mypool")
### Close the connection to RADOS
cluster.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment