#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import json
from rados import Rados
from rados import Error as RadosError
class CephClusterCommand(dict):
"""
Issue a ceph command on the given cluster and provide the returned json
"""
def __init__(self, cluster, **kwargs):
dict.__init__(self)
ret, buf, err = cluster.mon_command(json.dumps(kwargs), '', timeout=5)
if ret != 0:
self['err'] = err
else:
self.update(json.loads(buf))
config={'conffile': '/etc/ceph/ceph.conf', 'conf': {}}
with Rados(**config) as cluster:
cluster_status = CephClusterCommand(cluster, prefix='status', format='json')
print cluster_status