Page MenuHomePhabricator
Paste P68900

ceph_reweight_dc.py
ActivePublic

Authored by ProdPasteBot on Sep 11 2024, 7:53 AM.
Tags
None
Referenced Files
F57499119: ceph_reweight_dc.py
Sep 11 2024, 7:53 AM
Subscribers
None
#!/usr/bin/env python3
import subprocess
import json
health_json = subprocess.check_output(["ceph", "health", "detail", "-f=json"])
health_data = json.loads(health_json)
for message_data in health_data["checks"]["OSD_NEARFULL"]["detail"]:
message = message_data["message"]
osd = message.split(" ", 1)[0]
print(f"Reweighting osd {osd}")
weight_json = subprocess.check_output(["ceph", "osd", "df", "-f=json", osd])
weight_data = json.loads(weight_json)
cur_weight = weight_data["nodes"][0]["reweight"]
print(f" cur_weight={cur_weight}")
new_weight = cur_weight - 0.05
if new_weight < 0.5:
print(f"WARNING: weight of {osd} will go under 0.5 -> {new_weight}")
print(f" new_weight={new_weight}")
print("If that's ok, hit enter")
input()
for message_data in health_data["checks"]["OSD_NEARFULL"]["detail"]:
message = message_data["message"]
osd = message.split(" ", 1)[0]
print(f"Reweighting osd {osd}")
weight_json = subprocess.check_output(["ceph", "osd", "df", "-f=json", osd])
weight_data = json.loads(weight_json)
cur_weight = weight_data["nodes"][0]["reweight"]
print(f" cur_weight={cur_weight}")
new_weight = cur_weight - 0.05
print(f" new_weight={new_weight}")
subprocess.check_call(["ceph", "osd", "reweight", osd, str(new_weight)])

Event Timeline

ProdPasteBot changed the title of this paste from untitled to ceph_reweight_dc.py.