Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # This script is a wrapper around ceph-disk to create ceph OSD disk. It can
- # handle creation of OSDs on partitions and whole disks.
- #
- # The companion script 'disk_check.sh' checks if a disk|partition is allready
- # an OSD and does some extra checking.
- #
- # Written by Richard Arends, mainly for puppet-ceph:
- # https://github.com/stackforge/puppet-ceph
- #
- # Exit codes:
- # 100: $DISK_CHECK_PROG returned an exit code other then '0'
- # 101: No arguments received
- # 102: Invalid argument to option -t (type).
- # 103: Invalid argument. Only -d and -t are allowed
- # 999: An error was triggered, but we are not sure where it came from
- #
- TYPE="unknown"
- DEVICE="unknown"
- CLUSTER_NAME="ceph"
- CLUSTER_OPTION=""
- DISK_CHECK_PROG="/path/to/disk_check.sh"
- Usage() {
- echo " "
- echo "Usage: $0 -t [partition|disk] -d [device] -j <journal> -c <cluster>"
- echo " "
- echo "Example:"
- echo " $0 -t disk -d /dev/sdd"
- echo " $0 -t partition -d /dev/sdg"
- }
- Error() {
- ERROR_MESSAGE=$1
- E_CODE=$2
- if [ ! -z "${ERROR_MESSAGE}" ]; then
- echo "ERROR: ${ERROR_MESSAGE}"
- else
- echo "ERROR"
- fi
- if [ $E_CODE ] && [ $E_CODE -gt 0 ]; then
- exit $E_CODE
- else
- exit 999
- fi
- }
- while getopts ":t:d:j:c:" OPT; do
- case "${OPT}" in
- c)
- CLUSTER_NAME="${OPTARG}"
- CLUSTER_OPTION="--cluster ${CLUSTER_NAME}"
- ;;
- j)
- JOURNAL="${OPTARG}"
- ;;
- d)
- DEVICE="${OPTARG}"
- ;;
- t)
- TYPE="${OPTARG}"
- ;;
- \?)
- echo "Invalid option: -$OPTARG" >&2
- exit 103
- ;;
- esac
- done
- if [ "${TYPE}" == "unknown" ] || [ "${DEVICE}" == "unknown" ]; then
- Usage
- exit 101
- fi
- case "${TYPE}" in
- partition)
- case "$(${DISK_CHECK_PROG} ${DEVICE})" in
- 1)
- PARTITION=$(sgdisk --print "${DEVICE}"|tail -1|awk '{print $1+1}')
- OSD_UUID=$(uuidgen -r)
- PTYPE_UUID="4fbd7e29-9d25-41b8-afd0-062c0ceff05d"
- sgdisk --largest-new=${PARTITION} \
- --change-name="${PARTITION}:ceph data" \
- --partition-guid=${PARTITION}:${OSD_UUID} \
- --typecode=${PARTITION}:${PTYPE_UUID} -- "${DEVICE}" || Error
- partprobe || Error
- ceph-disk prepare ${CLUSTER_OPTION} ${DEVICE}${PARTITION} || Error
- ceph-disk activate ${DEVICE}${PARTITION} || Error
- ;;
- 0)
- echo "An 'ceph data' partition is allready present on device ${DEVICE}"
- ;;
- *)
- echo "${DISK_CHECK_PROG} returned an exit code other then '1' or '0'. An error happend?"
- exit 100
- ;;
- esac
- ;;
- disk)
- case "$(${DISK_CHECK_PROG} ${DEVICE})" in
- 1)
- ## ??? mkdir -p ${data}
- ceph-disk prepare ${CLUSTER_OPTION} ${DEVICE} ${JOURNAL} || Error
- ceph-disk activate ${DEVICE} || Error
- ;;
- 0)
- echo "Device ${DEVICE} is allready a ceph OSD"
- ;;
- *)
- echo "${DISK_CHECK_PROG} returned an exit code other then '1' or '0'. An error happend?"
- exit 100
- ;;
- esac
- ;;
- *)
- echo "Invalid argument ${TYPE} to option -t (type). Must be set to <partition> or <disk>"
- Usage
- exit 102
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement