2019-03-13

Run ceph CLI commands from Python

"mon_command" is a way to run ceph CLI commands via the librados Python API.

Which commands can I run?


https://github.com/ceph/ceph/blob/master/src/mon/MonCommands.h
https://github.com/ceph/ceph/blob/master/src/mgr/MgrCommands.h

Do you have a sample Python script?


#!/usr/bin/python3
import json
import rados

def run_command(cluster_handle, cmd):
    return cluster_handle.mon_command(json.dumps(cmd), b'', timeout=5)

cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
cluster.connect()
print(run_command(cluster, {"prefix": "osd safe-to-destroy", "ids": ["2"], "format": "json"}))
print(run_command(cluster, {"prefix": "osd ok-to-stop", "ids": ["2"], "format": "json"}))

No comments:

Post a Comment