Skip to content

Instantly share code, notes, and snippets.

@dvanders
Last active September 25, 2024 13:13
Show Gist options
  • Save dvanders/19dbca517ccd93d0176280c907c28c9a to your computer and use it in GitHub Desktop.
Save dvanders/19dbca517ccd93d0176280c907c28c9a to your computer and use it in GitHub Desktop.
reweight_osds.py
import json
import argparse
# Define the weight calculation function
def calculate_weight(bluestore_bdev_size):
return max(0.00001, float(bluestore_bdev_size) / float(1 << 40))
def main(input_file):
# Read the OSD metadata from the input file
with open(input_file, 'r') as file:
osd_metadata = json.load(file)
# Iterate over the OSD metadata and print the reweight commands
num = 0
print('ceph osd set norebalance')
print('while ceph status | grep -q "peering\|activating\|laggy"; do sleep 2; done')
for osd in osd_metadata:
if num == 100:
#print('wait; while ceph status | grep -q "peering\|activating\|laggy"; do sleep 2; done')
print('wait; sleep 5')
num = 0
num += 1
osd_id = osd["id"]
bluestore_bdev_size = osd["bluestore_bdev_size"]
weight = calculate_weight(bluestore_bdev_size)
# Print the ceph reweight command
print(f"ceph osd crush reweight osd.{osd_id} {weight:.5f}")
if __name__ == "__main__":
# Set up argument parsing with usage and help descriptions
parser = argparse.ArgumentParser(
description="Calculate and generate Ceph OSD crush reweight commands based on OSD metadata.",
usage="python reweight_osds.py <input_file>",
epilog="Example: python reweight_osds.py osd_metadata.json"
)
parser.add_argument(
"input_file",
help="Path to the input JSON file containing OSD metadata"
)
# Parse the arguments
args = parser.parse_args()
# Run the main function
main(args.input_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment