Skip to content

Instantly share code, notes, and snippets.

@wido
Created July 16, 2014 07:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wido/5d26d88366e28e25e23d to your computer and use it in GitHub Desktop.
Save wido/5d26d88366e28e25e23d to your computer and use it in GitHub Desktop.
Ceph CRUSH Location lookup
#!/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