zoukankan      html  css  js  c++  java
  • Ceph的Python接口

    参考文章

    ceph的python_api文档: http://docs.ceph.com/docs/master/rados/api/python/

    连接ceph集群

    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()

    断开ceph集群连接

    cluster.shutdown()
  • 相关阅读:
    以AO方式给SceneControl控件设置BaseHeight
    TreeView只能选中一个节点
    Excel导出DataTable
    TOCControl右键菜单
    Arcgis Engine符号化相关
    shapefile文件锁定问题
    ArcGIS符号库serverstyle文件编辑注意事项
    CentOS运维常用命令
    常用shell
    javascript浮点数相减、相乘出现一长串小数
  • 原文地址:https://www.cnblogs.com/wangjq19920210/p/12160064.html
Copyright © 2011-2022 走看看