-
-
Save mainframe/c78183e6cc6cb3d0dc3454a9c12c56e3 to your computer and use it in GitHub Desktop.
Ceph CRUSH Location lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Generates a CRUSH location based on the machine's hostname. | |
# This Gist was written for a customer who has mixed SSDs and HDDs in a a chassis. | |
# Hostname example in this case: dc2-rk01-ceph01 (Datacenter 2, rack 01, Ceph machine 01) | |
# It checks if the backing disk is a SSD or not and then comes up with the CRUSH location | |
while :; do | |
case $1 in | |
--cluster) | |
CLUSTER=$2 | |
shift | |
;; | |
--type) | |
TYPE=$2 | |
shift | |
;; | |
--id) | |
ID=$2 | |
shift | |
;; | |
*) | |
break | |
esac | |
command shift | |
done | |
if [ -z "$CLUSTER" ]; then | |
echo "No cluster was specified" | |
exit 1 | |
fi | |
if [ -z "$TYPE" ]; then | |
echo "No type was specified" | |
exit 1 | |
fi | |
if [ -z "$ID" ]; then | |
echo "No id was specified" | |
exit 1 | |
fi | |
HOST=$(hostname) | |
RACK=$(hostname|cut -d '-' -f 2) | |
DEV=$(df /var/lib/ceph/$TYPE/${CLUSTER}-${ID}|tail -1|awk '{print $1}'|cut -d '/' -f 3|sed -r 's/[0-9]{1,10}$//') | |
ROTATIONAL=$(cat /sys/block/$DEV/queue/rotational) | |
if [ $ROTATIONAL -eq 1 ]; then | |
echo "root=hdd rack=${RACK}-hdd host=${HOST}-hdd" | |
else | |
echo "root=ssd rack=${RACK}-ssd host=${HOST}-ssd" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment