Python 官方文档:入门教程 => 点击学习
参考文章 ceph的python_api文档 连接ceph集群 import rados cluster = rados.Rados(conffile='/etc/ceph/ceph.conf') cluster.conn
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()
--结束END--
本文标题: 【Python】Ceph的python接
本文链接: https://www.lsjlt.com/news/190150.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0