利用ceph的python API接口做ceph简单操作
class radosObj: instance=None cluster=None def __init__(self): self.conf="/etc/ceph/ceph.conf" self.keyring="/etc/ceph/ceph.keyring" self.cephcmd="/usr/bin/ceph" self.cluster=None @classmethod def Inst(cls): if cls.instance is None: cls.instance = radosObj() cls.instance.connect() return cls.instance def connect(self): if self.cluster is None: self.cluster=rados.Rados(conffile=self.conf) self.cluster.connect(timeout=5) return self.cluster def get_fsid(self): return self.cluster.get_fsid() def get_cluster_stats(self): result={} result = self.cluster.get_cluster_stats() return result def get_list_pools(self): result={} result['value'] = self.cluster.list_pools() return result def delete_pool(self,poolname): value=self.cluster.delete_pool(poolname) return value def create_pool(self,poolname): value=self.cluster.create_pool(poolname) return value def isexists(self,poolname): value=self.cluster.pool_exists(poolname) return value
测试程序
print radosObj.Inst().get_fsid() print radosObj.Inst().get_cluster_stats() pools= radosObj.Inst().get_list_pools() for pool in pools['value']: print pool
结果
[root@ceph01 ~]# python ceph_common.py dbb4bf43-7b1d-4641-b0ce-2d667d02b3fe {'kb': 9424876L, 'num_objects': 0L, 'kb_avail': 9390964L, 'kb_used': 33912L} rbd