mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-09-11 01:44:38 +00:00
Feature: get correct next VMID (#4292)
fix(vm-creation): ensure whiptail VMID inputbox is pre-filled with a valid and available ID - Replaced hardcoded NEXTID usage with a new get_valid_nextid() function - Ensures no collision with existing VMs, LXCs or orphaned LVM volumes - Improves user experience by properly pre-filling whiptail inputbox - Automatically skips invalid IDs instead of failing on alloc
This commit is contained in:
parent
ebc17e120e
commit
c9aad3a54d
13 changed files with 270 additions and 60 deletions
|
@ -21,15 +21,12 @@ clear
|
|||
header_info
|
||||
echo -e "Loading..."
|
||||
GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
|
||||
NEXTID=$(pvesh get /cluster/nextid)
|
||||
#API VARIABLES
|
||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||
METHOD=""
|
||||
NSAPP="mikrotik-router-os"
|
||||
var_os="mikrotik"
|
||||
var_version=" "
|
||||
DISK_SIZE="1G"
|
||||
#
|
||||
YW=$(echo "\033[33m")
|
||||
BL=$(echo "\033[36m")
|
||||
HA=$(echo "\033[1;34m")
|
||||
|
@ -60,6 +57,24 @@ function error_exit() {
|
|||
[ ! -z ${VMID-} ] && cleanup_vmid
|
||||
exit $EXIT
|
||||
}
|
||||
|
||||
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() {
|
||||
if $(qm status $VMID &>/dev/null); then
|
||||
if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue