dev create_lxc performance & stabl.
This commit is contained in:
parent
21f7b6a63a
commit
2741ef8498
@ -49,58 +49,64 @@ fi
|
|||||||
|
|
||||||
# This function is used to select the storage class and determine the corresponding storage content type and label.
|
# This function is used to select the storage class and determine the corresponding storage content type and label.
|
||||||
function select_storage() {
|
function select_storage() {
|
||||||
local CLASS=$1
|
local CLASS="$1"
|
||||||
local CONTENT
|
local CONTENT
|
||||||
local CONTENT_LABEL
|
local CONTENT_LABEL
|
||||||
case $CLASS in
|
|
||||||
|
case "$CLASS" in
|
||||||
container)
|
container)
|
||||||
CONTENT='rootdir'
|
CONTENT='rootdir'
|
||||||
CONTENT_LABEL='Container'
|
CONTENT_LABEL='Container'
|
||||||
;;
|
;;
|
||||||
template)
|
template)
|
||||||
CONTENT='vztmpl'
|
CONTENT='vztmpl'
|
||||||
CONTENT_LABEL='Container template'
|
CONTENT_LABEL='Container Template'
|
||||||
;;
|
;;
|
||||||
*) false || {
|
*)
|
||||||
msg_error "Invalid storage class."
|
msg_error "Invalid storage class: $CLASS"
|
||||||
exit 201
|
exit 201
|
||||||
} ;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# This Queries all storage locations
|
# Collect storage options
|
||||||
local -a MENU
|
local -a MENU
|
||||||
|
local MSG_MAX_LENGTH=0
|
||||||
|
|
||||||
while read -r TAG TYPE _ _ _ FREE _; do
|
while read -r TAG TYPE _ _ _ FREE _; do
|
||||||
local TYPE_PADDED=$(printf "%-10s" "$TYPE")
|
local TYPE_PADDED
|
||||||
local FREE_FMT=$(numfmt --to=iec --from-unit=K --format %.2f <<<"$FREE")
|
local FREE_FMT
|
||||||
local ITEM="Type: $TYPE_PADDED Free: ${FREE_FMT}B"
|
|
||||||
local OFFSET=2
|
TYPE_PADDED=$(printf "%-10s" "$TYPE")
|
||||||
if [[ -z "${MSG_MAX_LENGTH:-}" || $((${#ITEM} + OFFSET)) -gt MSG_MAX_LENGTH ]]; then
|
FREE_FMT=$(numfmt --to=iec --from-unit=K --format %.2f <<<"$FREE")B
|
||||||
MSG_MAX_LENGTH=$((${#ITEM} + OFFSET))
|
local ITEM="Type: $TYPE_PADDED Free: $FREE_FMT"
|
||||||
fi
|
|
||||||
|
((${#ITEM} + 2 > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=$((${#ITEM} + 2))
|
||||||
MENU+=("$TAG" "$ITEM" "OFF")
|
MENU+=("$TAG" "$ITEM" "OFF")
|
||||||
done < <(pvesm status -content "$CONTENT" | awk 'NR>1')
|
done < <(pvesm status -content "$CONTENT" | awk 'NR>1')
|
||||||
|
|
||||||
# Select storage location
|
local OPTION_COUNT=$((${#MENU[@]} / 3))
|
||||||
if [ $((${#MENU[@]} / 3)) -eq 1 ]; then
|
|
||||||
printf ${MENU[0]}
|
# Auto-select if only one option available
|
||||||
else
|
if [[ "$OPTION_COUNT" -eq 1 ]]; then
|
||||||
local STORAGE
|
echo "${MENU[0]}"
|
||||||
while [ -z "${STORAGE:+x}" ]; do
|
return 0
|
||||||
STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \
|
|
||||||
"Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\nTo make a selection, use the Spacebar.\n" \
|
|
||||||
16 $(($MSG_MAX_LENGTH + 23)) 6 \
|
|
||||||
"${MENU[@]}" 3>&1 1>&2 2>&3) || {
|
|
||||||
msg_error "Menu aborted."
|
|
||||||
exit 202
|
|
||||||
}
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "${CROSS}${RD} Menu aborted by user.${CL}"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
printf "%s" "$STORAGE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Display selection menu
|
||||||
|
local STORAGE
|
||||||
|
while [[ -z "${STORAGE:+x}" ]]; do
|
||||||
|
STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \
|
||||||
|
"Select the storage pool to use for the ${CONTENT_LABEL,,}.\nUse the spacebar to make a selection.\n" \
|
||||||
|
16 $((MSG_MAX_LENGTH + 23)) 6 \
|
||||||
|
"${MENU[@]}" 3>&1 1>&2 2>&3) || {
|
||||||
|
msg_error "Storage selection cancelled."
|
||||||
|
exit 202
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$STORAGE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if required variables are set
|
# Test if required variables are set
|
||||||
[[ "${CTID:-}" ]] || {
|
[[ "${CTID:-}" ]] || {
|
||||||
msg_error "You need to set 'CTID' variable."
|
msg_error "You need to set 'CTID' variable."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user