Planet Ceph

Aggregated news from external sources

March 13, 2019

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?

Do you have a sample Python script?

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')
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"}))

Source: Nathan Cutler (Run ceph CLI commands from Python)