Add usage/help message and CLI argument parsing
Added comprehensive command-line interface with: - -h, --help: Show usage information - -v, --version: Show version - -d, --debug: Enable debug output - -s, --skip-smart: Skip SMART data collection (faster) - --no-ceph: Skip Ceph OSD information - --show-pci: Display PCI paths for debugging The script now properly respects these flags throughout execution. Fixes: #10 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
150
driveAtlas.sh
150
driveAtlas.sh
@@ -5,6 +5,84 @@
|
|||||||
# Maps physical drive bays to logical device names using PCI paths
|
# Maps physical drive bays to logical device names using PCI paths
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|
||||||
|
VERSION="1.1.0"
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# show_usage
|
||||||
|
#
|
||||||
|
# Displays help message with usage information and available options.
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
show_usage() {
|
||||||
|
cat << EOF
|
||||||
|
Drive Atlas v${VERSION} - Server Drive Mapping Tool
|
||||||
|
|
||||||
|
Maps physical drive bays to logical device names using PCI paths.
|
||||||
|
Displays visual chassis layouts and comprehensive drive information.
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
$(basename "$0") [OPTIONS]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help Show this help message and exit
|
||||||
|
-v, --version Show version information
|
||||||
|
-d, --debug Enable debug output (show drive mappings)
|
||||||
|
-s, --skip-smart Skip SMART data collection (faster)
|
||||||
|
--no-ceph Skip Ceph OSD information
|
||||||
|
--show-pci Show PCI paths in output
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
$(basename "$0") # Normal run with all features
|
||||||
|
$(basename "$0") --skip-smart # Fast run without SMART data
|
||||||
|
$(basename "$0") --debug # Show mapping debug info
|
||||||
|
|
||||||
|
ENVIRONMENT VARIABLES:
|
||||||
|
DEBUG=1 Same as --debug flag
|
||||||
|
|
||||||
|
For more information, see: https://code.lotusguild.org/LotusGuild/driveAtlas
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# Command Line Argument Parsing
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
SKIP_SMART=false
|
||||||
|
SKIP_CEPH=false
|
||||||
|
SHOW_PCI=false
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
show_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-v|--version)
|
||||||
|
echo "Drive Atlas v${VERSION}"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-d|--debug)
|
||||||
|
DEBUG=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-s|--skip-smart)
|
||||||
|
SKIP_SMART=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-ceph)
|
||||||
|
SKIP_CEPH=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--show-pci)
|
||||||
|
SHOW_PCI=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1" >&2
|
||||||
|
echo "Use --help for usage information." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Dependency Checks
|
# Dependency Checks
|
||||||
# Verifies required commands are available before running
|
# Verifies required commands are available before running
|
||||||
@@ -313,21 +391,27 @@ get_storage_controllers() {
|
|||||||
# Builds a global associative array mapping physical bay numbers to device names.
|
# Builds a global associative array mapping physical bay numbers to device names.
|
||||||
# Uses PCI paths from SERVER_MAPPINGS to resolve current device assignments.
|
# Uses PCI paths from SERVER_MAPPINGS to resolve current device assignments.
|
||||||
#
|
#
|
||||||
# Sets: DRIVE_MAP (global associative array)
|
# Sets:
|
||||||
# Keys: Bay identifiers (1, 2, ..., m2-1, m2-2, etc.)
|
# DRIVE_MAP (global associative array)
|
||||||
# Values: Device names (sda, nvme0n1, etc.)
|
# Keys: Bay identifiers (1, 2, ..., m2-1, m2-2, etc.)
|
||||||
|
# Values: Device names (sda, nvme0n1, etc.)
|
||||||
|
# BAY_TO_PCI_PATH (global associative array)
|
||||||
|
# Keys: Bay identifiers
|
||||||
|
# Values: PCI path strings (for --show-pci option)
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
build_drive_map() {
|
build_drive_map() {
|
||||||
local host="$(hostname)"
|
local host="$(hostname)"
|
||||||
local mapping="${SERVER_MAPPINGS[$host]}"
|
local mapping="${SERVER_MAPPINGS[$host]}"
|
||||||
|
|
||||||
# Declare global array directly instead of copying from local
|
# Declare global arrays directly
|
||||||
declare -g -A DRIVE_MAP=()
|
declare -g -A DRIVE_MAP=()
|
||||||
|
declare -g -A BAY_TO_PCI_PATH=()
|
||||||
|
|
||||||
if [[ -n "$mapping" ]]; then
|
if [[ -n "$mapping" ]]; then
|
||||||
while read -r path slot; do
|
while read -r path slot; do
|
||||||
[[ -z "$path" || -z "$slot" ]] && continue
|
[[ -z "$path" || -z "$slot" ]] && continue
|
||||||
|
|
||||||
|
BAY_TO_PCI_PATH[$slot]="$path"
|
||||||
if [[ -L "/dev/disk/by-path/$path" ]]; then
|
if [[ -L "/dev/disk/by-path/$path" ]]; then
|
||||||
local drive="$(readlink -f "/dev/disk/by-path/$path" | sed 's/.*\///')"
|
local drive="$(readlink -f "/dev/disk/by-path/$path" | sed 's/.*\///')"
|
||||||
DRIVE_MAP[$slot]="$drive"
|
DRIVE_MAP[$slot]="$drive"
|
||||||
@@ -509,11 +593,18 @@ esac
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Build Ceph OSD cache (single query instead of per-device)
|
# Build Ceph OSD cache (single query instead of per-device)
|
||||||
build_ceph_cache
|
if [[ "$SKIP_CEPH" != true ]]; then
|
||||||
|
build_ceph_cache
|
||||||
|
fi
|
||||||
|
|
||||||
printf "\n=== Drive Details with SMART Status (by Bay Position) ===\n"
|
printf "\n=== Drive Details with SMART Status (by Bay Position) ===\n"
|
||||||
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s\n" "BAY" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL" "CEPH OSD" "STATUS" "USAGE"
|
if [[ "$SHOW_PCI" == true ]]; then
|
||||||
echo "----------------------------------------------------------------------------------------------------------------------------------------------------"
|
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s %-40s\n" "BAY" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL" "CEPH OSD" "STATUS" "USAGE" "PCI PATH"
|
||||||
|
echo "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
|
||||||
|
else
|
||||||
|
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s\n" "BAY" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL" "CEPH OSD" "STATUS" "USAGE"
|
||||||
|
echo "----------------------------------------------------------------------------------------------------------------------------------------------------"
|
||||||
|
fi
|
||||||
|
|
||||||
# Build reverse map: device -> bay
|
# Build reverse map: device -> bay
|
||||||
declare -A DEVICE_TO_BAY
|
declare -A DEVICE_TO_BAY
|
||||||
@@ -530,22 +621,34 @@ all_bays=$(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n; prin
|
|||||||
for bay in $all_bays; do
|
for bay in $all_bays; do
|
||||||
device="${DRIVE_MAP[$bay]}"
|
device="${DRIVE_MAP[$bay]}"
|
||||||
if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then
|
if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then
|
||||||
size=$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)
|
size="$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)"
|
||||||
smart_info=$(get_drive_smart_info "$device")
|
|
||||||
IFS='|' read -r type temp health model serial <<< "$smart_info"
|
# Get SMART info (or defaults if skipped)
|
||||||
|
if [[ "$SKIP_SMART" == true ]]; then
|
||||||
|
type="-"
|
||||||
|
temp="-"
|
||||||
|
health="-"
|
||||||
|
model="-"
|
||||||
|
serial="-"
|
||||||
|
else
|
||||||
|
smart_info="$(get_drive_smart_info "$device")"
|
||||||
|
IFS='|' read -r type temp health model serial <<< "$smart_info"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check for Ceph OSD using cached data
|
# Check for Ceph OSD using cached data
|
||||||
osd_id="${CEPH_DEVICE_TO_OSD[$device]:-}"
|
osd_id="-"
|
||||||
ceph_status="-"
|
ceph_status="-"
|
||||||
|
if [[ "$SKIP_CEPH" != true ]]; then
|
||||||
if [[ -n "$osd_id" ]]; then
|
osd_id="${CEPH_DEVICE_TO_OSD[$device]:-}"
|
||||||
# Get status from cached OSD tree data
|
if [[ -n "$osd_id" ]]; then
|
||||||
osd_num="${osd_id#osd.}"
|
# Get status from cached OSD tree data
|
||||||
up_status="${CEPH_OSD_STATUS[$osd_num]:-unknown}"
|
osd_num="${osd_id#osd.}"
|
||||||
in_status="${CEPH_OSD_IN[$osd_num]:-out}"
|
up_status="${CEPH_OSD_STATUS[$osd_num]:-unknown}"
|
||||||
ceph_status="${up_status}/${in_status}"
|
in_status="${CEPH_OSD_IN[$osd_num]:-out}"
|
||||||
else
|
ceph_status="${up_status}/${in_status}"
|
||||||
osd_id="-"
|
else
|
||||||
|
osd_id="-"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check mount points using lsblk (includes partitions)
|
# Check mount points using lsblk (includes partitions)
|
||||||
@@ -566,7 +669,12 @@ for bay in $all_bays; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s\n" "$bay" "/dev/$device" "$size" "$type" "$temp" "$health" "$model" "$serial" "$osd_id" "$ceph_status" "$usage"
|
if [[ "$SHOW_PCI" == true ]]; then
|
||||||
|
pci_path="${BAY_TO_PCI_PATH[$bay]:-}"
|
||||||
|
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s %-40s\n" "$bay" "/dev/$device" "$size" "$type" "$temp" "$health" "$model" "$serial" "$osd_id" "$ceph_status" "$usage" "$pci_path"
|
||||||
|
else
|
||||||
|
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s\n" "$bay" "/dev/$device" "$size" "$type" "$temp" "$health" "$model" "$serial" "$osd_id" "$ceph_status" "$usage"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user