scripts/ceph/new.osd-id.sh

59 lines
1.4 KiB
Bash
Raw Normal View History

2019-11-26 09:53:30 +01:00
#!/bin/sh
# Vars {{{
debug="0"
2019-11-26 10:40:50 +01:00
## Colors {{{
c_redb='\033[1;31m'
c_magentab='\033[1;35m'
c_reset='\033[0m'
## }}}
2019-11-26 09:53:30 +01:00
osd_id_start="0"
osd_id_end=$(sudo ceph osd getmaxosd | cut -d" " -f3)
# }}}
# Functions
# Check if an OSD exists {{{
check_osd() {
_osd_id="${1}"
2019-11-26 10:40:50 +01:00
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: check_osd func OSD ID to check: ${_osd_id}."
2019-11-26 09:53:30 +01:00
sudo ceph osd find "${_osd_id}" > /dev/null 2>&1
return $?
}
# }}}
2019-11-26 10:32:46 +01:00
# Check if an OSD exists {{{
get_osd_host() {
_osd_id="${1}"
osd_id_host=""
2019-11-26 10:40:50 +01:00
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: get_osd_host func OSD ID to check: ${_osd_id}."
2019-11-26 10:32:46 +01:00
osd_id_host=$(sudo ceph osd find "${_osd_id}" | awk -F\" '$2 ~ /host/ {print $4}')
}
# }}}
2019-11-26 09:53:30 +01:00
osd_id="${osd_id_start}"
while [ "${osd_id}" -lt "${osd_id_end}" ]; do
2019-11-26 10:40:50 +01:00
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: Check if OSD ${osd_id} exists."
2019-11-26 09:53:30 +01:00
2019-11-26 09:55:26 +01:00
if check_osd "${osd_id}"
then
2019-11-26 10:32:46 +01:00
get_osd_host "${osd_id}"
2019-11-26 10:40:50 +01:00
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: OSD ${osd_id} exists on ${c_redb}${osd_id_host}."
2019-11-26 09:53:30 +01:00
else
2019-11-26 10:40:50 +01:00
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: !OSD ${osd_id} does exists!"
2019-11-26 09:53:30 +01:00
fi
2019-11-26 10:40:50 +01:00
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "-----------------------------------------------"
2019-11-26 10:32:46 +01:00
2019-11-26 09:53:30 +01:00
## Increment OSD ID
osd_id=$((osd_id+1))
done
exit 0