参考文章
ceph的python_api文档: http://docs.ceph.com/docs/master/rados/api/python/
import rados
cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
cluster.connect()
# 列出可用的池
pools = cluster.list_pools()
for pool in pools:
print pool
# 创建池test
cluster.create_pool('test')
# 删除池
cluster.delete_pool('test')
# 判断是否存在一个池
cluster.pool_exists('test')
ioctx = cluster.open_ioctx('test')
# 列出test池中的所有文件名
object_iterator = ioctx.list_objects()
while True :
try :
rados_object = object_iterator.next()
print "Object contents = " + rados_object.key
except StopIteration :
break
ioctx.close()
# 连接到test池
ioctx = cluster.open_ioctx('test')
file_name = "yy.mp3"
f = open("yy.mp3", "r")
file_content = f.read()
f.close()
# 将文件写入池
ioctx.write_full(file_name, file_content)
ioctx.close()
# 连接到test池
ioctx = cluster.open_ioctx('test')
f = open("yy.mp3", "w")
# 将文件下载(写入)到本地
f.write(ioctx.read("yy.mp3"))
f.close()
ioctx.close()
ioctx = cluster.open_ioctx('test')
# 删除test池中的yy.mp3文件
ioctx.remove_object("yy.mp3")
ioctx.close()
cluster.shutdown()