Page MenuHomePhabricator
Paste P68902

ceph_reweight_reset.py
ActivePublic

Authored by ProdPasteBot on Sep 11 2024, 7:53 AM.
Tags
None
Referenced Files
F57499121: ceph_reweight_reset.py
Sep 11 2024, 7:53 AM
Subscribers
None
#!/usr/bin/env python3
import subprocess
import json
tree_json = subprocess.check_output(["ceph", "osd", "tree", "-f=json"])
tree_data = json.loads(tree_json)
osds = []
new_weight = 1
for node in tree_data["nodes"]:
if not node["name"].startswith("osd."):
continue
osd = node["name"]
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}")
if cur_weight == 0:
print(f" SKIPPING as it's out of the cluster")
continue
elif cur_weight == 1:
print(f" SKIPPING as it's already reset")
print(f" new_weight={new_weight}")
osds.append(osd)
print("If that's ok, hit enter")
input()
for osd in osds:
subprocess.check_call(["ceph", "osd", "reweight", osd, str(new_weight)])

Event Timeline

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