test next_id
This commit is contained in:
parent
77fc8bec9a
commit
ccb112b383
@ -75,6 +75,23 @@ function error_handler() {
|
|||||||
cleanup_vmid
|
cleanup_vmid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_valid_nextid() {
|
||||||
|
local try_id
|
||||||
|
try_id=$(pvesh get /cluster/nextid)
|
||||||
|
while true; do
|
||||||
|
if [ -f "/etc/pve/qemu-server/${try_id}.conf" ] || [ -f "/etc/pve/lxc/${try_id}.conf" ]; then
|
||||||
|
try_id=$((try_id + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if lvs --noheadings -o lv_name | grep -qE "(^|[-_])${try_id}($|[-_])"; then
|
||||||
|
try_id=$((try_id + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
|
echo "$try_id"
|
||||||
|
}
|
||||||
|
|
||||||
function cleanup_vmid() {
|
function cleanup_vmid() {
|
||||||
if qm status $VMID &>/dev/null; then
|
if qm status $VMID &>/dev/null; then
|
||||||
qm stop $VMID &>/dev/null
|
qm stop $VMID &>/dev/null
|
||||||
@ -161,7 +178,7 @@ function exit-script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_SIZE="8G"
|
DISK_SIZE="8G"
|
||||||
@ -195,9 +212,9 @@ function default_settings() {
|
|||||||
function advanced_settings() {
|
function advanced_settings() {
|
||||||
METHOD="advanced"
|
METHOD="advanced"
|
||||||
while true; do
|
while true; do
|
||||||
if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
|
if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $VMID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
|
||||||
if [ -z "$VMID" ]; then
|
if [ -z "$VMID" ]; then
|
||||||
VMID="$NEXTID"
|
VMID="$$VMID"
|
||||||
fi
|
fi
|
||||||
if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then
|
if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then
|
||||||
echo -e "${CROSS}${RD} ID $VMID is already in use${CL}"
|
echo -e "${CROSS}${RD} ID $VMID is already in use${CL}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user