runsisi's

technical notes

RADOS Python API

2019-02-20 runsisi#ceph#python

#!/usr/bin/env python

import rbd
import rados
import json

conf = {'keyring': './keyring'}
with rados.Rados(conffile='./ceph.conf', conf=conf) as cluster:
    out = cluster.mgr_command(
        [json.dumps({
            "prefix": "pg ls-by-pool",
            "poolstr": "rbd",
            "target": ["mgr", ""],
            "format": "json",
        })],
        '',
        0
    )
    print(out)