Skip to content

Instantly share code, notes, and snippets.

@nailgun
Last active May 9, 2017 07:17
Show Gist options
  • Save nailgun/b3d05265762c2746dccda5b37cbc7622 to your computer and use it in GitHub Desktop.
Save nailgun/b3d05265762c2746dccda5b37cbc7622 to your computer and use it in GitHub Desktop.
Utility to interactively edit Ceph CRUSH map
#!/bin/bash
set -e
original_bin=$(mktemp)
original_src=${original_bin}.src
new_bin=$(mktemp)
new_src=${new_bin}.src
cleanup () {
rm -f "$original_bin" "$original_src" "$new_bin" "$new_src"
}
trap cleanup EXIT
ceph osd getcrushmap -o "$original_bin"
crushtool -d "$original_bin" -o "$original_src"
cp "$original_src" "$new_src"
while true; do
${EDITOR:-${VISUAL:-/usr/bin/vi}} "$new_src"
if crushtool -c "$new_src" -o "$new_bin"; then
break
else
read
fi
done
if cmp -s "$new_bin" "$original_bin"; then
echo "No changes in CRUSH map detected, skipping install"
else
ceph osd setcrushmap -i "$new_bin"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment