From 24cc5a3351d56a9608547822bf0cf2bc2005d463 Mon Sep 17 00:00:00 2001 From: Dmitry Badovsky Date: Sun, 26 Oct 2025 13:27:30 +0000 Subject: [PATCH] Update vmcreate1.sh --- vmcreate1.sh | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/vmcreate1.sh b/vmcreate1.sh index 6705bad..87414de 100644 --- a/vmcreate1.sh +++ b/vmcreate1.sh @@ -109,13 +109,7 @@ if [[ $# -ne 0 ]]; then if [ $? -eq 0 ]; then echo -n "$arg " >> ./hosts.tmp echo -n "vm" >> ./hosts.tmp - vlan=$(echo -n $arg | cut -d '.' -f 3) - if [[ $vlan -eq 0 ]]; then - echo -n "100" >> ./hosts.tmp - else - printf "%02d\n" "$vlan" >> ./hosts.tmp - fi - printf "%03d\n" "$(echo -n $arg | cut -d '.' -f 4)" >> ./hosts.tmp + get_vmid "$arg" >> hosts.tmp echo >> hosts.tmp else echo "Argument `$arg` is not a valid IPv4 address (10.10.*.*). Aborting." @@ -198,7 +192,7 @@ keypair_generate (){ } mksnippet (){ - snippet="${path}${vmnum}_user.yaml" + snippet="${path}${vmid}_user.yaml" cp ./user.yaml "$snippet" sed -i "s/HOSTNAME/$hostname/g" "$snippet" if [[ -n $username ]]; then @@ -224,37 +218,34 @@ do gw="10.10.${vlan}.1" fi hostname=$(echo $line | cut -d ' ' -f 2) - vmnum="$vlan(printf "%03d\n" "$(echo -n $ip | cut -d '.' -f 4)")" - if [[ $vlan -eq 0 ]]; then - $vlan=100 - fi + vmid=$(get_vmid "$ip") mksnippet #### DEBUG 2 echo "IP: $ip" echo "hostname: $hostname" - echo "VMID: $vmnum" + echo "VMID: $vmid" echo "VLAN: $vlan" echo "$snippet:" cat "$snippet" read -p "Press Enter" #### echo -n "Now cloning VM $vmnum from a template....." - qm clone 5000 $vmnum --name $hostname --full &>/dev/null + qm clone 5000 $vmid --name $hostname --full &>/dev/null if [ $? -eq 0 ]; then echo "OK" else echo "ERROR" exit 8 fi - qm set $vmnum --tags $node,$tag - qm resize $vmnum scsi0 +"$size"G - qm set $vmnum --cicustom "user=${storage}:snippets/${vmnum}_user.yaml" - qm set $vmnum --ipconfig0 ip="$ip"/"$mask",gw="$gw" - qm cloudinit update $vmnum - qm start $vmnum + qm set $vmid --tags $node,$tag + qm resize $vmid scsi0 +"$size"G + qm set $vmid --cicustom "user=${storage}:snippets/${vmnum}_user.yaml" + qm set $vmid --ipconfig0 ip="$ip"/"$mask",gw="$gw" + qm cloudinit update $vmid + qm start $vmid if [ -v harule ]; then - ha-manager add vm:$vmnum --state started --max_relocate 2 - ha-manager rules add node-affinity $harule --resources vm:$vmnum --nodes pve1,pve2,pve3 --strict 1 + ha-manager add vm:$vmid --state started --max_relocate 2 + ha-manager rules add node-affinity $harule --resources vm:$vmid --nodes pve1,pve2,pve3 --strict 1 echo "HA rule added" # ОБЯЗАТЕЛЬНО ПРОВЕРИТЬ КОМАНДУ!!! fi