Ceph Client
Introduction
Ceph 提供了有三種儲存介面:
Object Storage
Block Storage
Filesystem
無論哪一種儲存方法都是透過 RADOS 所提供的介面去跟 RADOS 做溝通, 這層介面就是 LIBRADOS
NOTE: 講 RADOS 這名詞可能有點不直覺, 可以把他想成就是整個 Ceph Storage Cluster 就好, 裡面包含了 OSD 和 MON
LIBRADOS
要透過 librados
對 Ceph Storage Cluster 做操作之前必須有下列東西:
The Ceph configuration file (include monitor address)
The pool name
The user name and secret key.
就可以直接透過 LIBRADOS 對 MON 跟 OSD 做溝通!!目前 LIBDRADO 提供 C/C++, Python, JAVA, PHP 這幾種API
Sample Code (Python)
import rados, sys
#跟RADOS建立連線
cluster = rados.Rados(conffile = 'ceph.conf', conf = dict(keyring = '/etc/ceph/ceph.client.admin.keyring'))
cluster.connect()
#取得Ceph Cluster 的狀態
cluster_stats = cluster.get_cluster_stats()
#列出所有的pool
pools = cluster.list_pools()
#建立pool: test_pool
cluster.create_pool('test_pool')
#Reading from and writing to the Ceph Storage Cluster requries an input/output context (ioctx).
#跟test pool之間建立 input/output context
ioctx = cluster.open_ioctx('test_pool')
#寫入一個內容為Hello World!的hw object到test pool中
ioctx.write_full("hw", "Hello World!")
#讀取hw object 的內容
ioctx.read("hw")
#列出 test_pool 裡面所有的object
object_iterator = ioctx.list_objects()
#close connection
ioctx.close()