Page MenuHomePhabricator
Paste P68901

ceph_reweight_rack.py
ActivePublic

Authored by ProdPasteBot on Sep 11 2024, 7:53 AM.
Tags
None
Referenced Files
F57499120: ceph_reweight_rack.py
Sep 11 2024, 7:53 AM
Subscribers
None
#!/usr/bin/env python3
import subprocess
import json
import click
@click.command()
@click.argument("RACK")
def main(rack: str) -> None:
rack_json = subprocess.check_output(["ceph", "osd", "df", rack, "-f=json"])
rack_data = json.loads(rack_json)
to_reweight: list[tuple[str, float]] = []
for node_data in rack_data["nodes"]:
osd = node_data["name"]
osd_variance = node_data["var"]
if osd_variance < 1.1:
print(f"Skipping osd {osd}, not too full (var={osd_variance})")
continue
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}")
to_reweight.append((osd, new_weight))
print(f"Reweighting a total of {len(to_reweight)} osds")
print("If that's ok, hit enter")
input()
for osd, new_weight in to_reweight:
print(f"Reweighting osd {osd}")
subprocess.check_call(["ceph", "osd", "reweight", osd, str(new_weight)])
if __name__ == "__main__":
main()

Event Timeline

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