Update khlcreate.sh
This commit is contained in:
98
khlcreate.sh
98
khlcreate.sh
@@ -1,56 +1,56 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
remove=false
|
remove=false
|
||||||
while getopts "R" opt; do
|
while getopts "R" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
R) remove=true;;
|
R) remove=true;;
|
||||||
\?) echo "Invalid option."; exit 1;;
|
\?) echo "Invalid option."; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if $remove; then
|
|
||||||
# Сначала запрашиваем остановку ВСЕХ тачек, чтобы сэкономить время
|
|
||||||
for line in $(cat khl_hosts)
|
|
||||||
do
|
|
||||||
ip=$(echo $line | cut -d ';' -f 1)
|
|
||||||
vmid=$(echo $ip | cut -d '.' -f 3,4 | sed 's/\.// ')
|
|
||||||
qm stop $vmid
|
|
||||||
done
|
|
||||||
# А теперь проверяем, что остановлена, и удаляем
|
|
||||||
for line in $(cat khl_hosts)
|
|
||||||
do
|
|
||||||
ip=$(echo $line | cut -d ';' -f 1)
|
|
||||||
vmid=$(echo $ip | cut -d '.' -f 3,4 | sed 's/\.// ')
|
|
||||||
status=$(qm status $vmid | cut -d ' ' -f 2)
|
|
||||||
until [[ $status -eq "stopped" ]]
|
|
||||||
do
|
|
||||||
echo "Waiting for VM $vmid become stopped..."
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
qm destroy $vmid --destroy-unreferenced-disks --purge
|
|
||||||
done
|
|
||||||
echo "Specified VMs REMOVED."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
if $remove; then
|
||||||
|
# Сначала запрашиваем остановку ВСЕХ тачек, чтобы сэкономить время
|
||||||
for line in $(cat khl_hosts)
|
for line in $(cat khl_hosts)
|
||||||
do
|
do
|
||||||
ip=$(echo $line | cut -d ';' -f 1)
|
ip=$(echo $line | cut -d ';' -f 1)
|
||||||
hostname=$(echo $line | cut -d ';' -f 2)
|
|
||||||
vmid=$(echo $ip | cut -d '.' -f 3,4 | sed 's/\.// ')
|
vmid=$(echo $ip | cut -d '.' -f 3,4 | sed 's/\.// ')
|
||||||
qm clone 5000 $vmid --name $hostname --full
|
qm stop $vmid
|
||||||
if [ $? -eq 0 ]
|
|
||||||
then echo "clone OK"
|
|
||||||
else "clone ERROR"; exit 1
|
|
||||||
fi
|
|
||||||
qm set $vmid --tags 3,gfx
|
|
||||||
echo "args: -virtfs local,id=khl,path=/mnt/pve/syno-tigra/shared/KHL,security_model=passthrough,mount_tag=khl" >> /etc/pve/qemu-server/${vmid}.conf
|
|
||||||
## preparing custom CloudInit snippets
|
|
||||||
cp ./khl.yaml /mnt/pve/syno-tigra/snippets/${vmid}_user.yaml
|
|
||||||
sed -i "s/HOSTNAME/$hostname/g" /mnt/pve/syno-tigra/snippets/${vmid}_user.yaml
|
|
||||||
qm resize $vmid scsi0 +50G
|
|
||||||
qm set $vmid --cicustom "user=syno-tigra:snippets/${vmid}_user.yaml"
|
|
||||||
qm set $vmid --ipconfig0 ip=$ip/24,gw=10.10.35.1
|
|
||||||
qm cloudinit update $vmid
|
|
||||||
qm start $vmid
|
|
||||||
done
|
done
|
||||||
echo "VMs from 'khl_hosts' successfully created"
|
# А теперь проверяем, что остановлена, и удаляем
|
||||||
|
for line in $(cat khl_hosts)
|
||||||
|
do
|
||||||
|
ip=$(echo $line | cut -d ';' -f 1)
|
||||||
|
vmid=$(echo $ip | cut -d '.' -f 3,4 | sed 's/\.// ')
|
||||||
|
status=$(qm status $vmid | cut -d ' ' -f 2)
|
||||||
|
until [[ $status -eq "stopped" ]]
|
||||||
|
do
|
||||||
|
echo "Waiting for VM $vmid become stopped..."
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
qm destroy $vmid --destroy-unreferenced-disks --purge
|
||||||
|
done
|
||||||
|
echo "Specified VMs REMOVED."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for line in $(cat khl_hosts)
|
||||||
|
do
|
||||||
|
ip=$(echo $line | cut -d ';' -f 1)
|
||||||
|
hostname=$(echo $line | cut -d ';' -f 2)
|
||||||
|
vmid=$(echo $ip | cut -d '.' -f 3,4 | sed 's/\.// ')
|
||||||
|
qm clone 5000 $vmid --name $hostname --full
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then echo "clone OK"
|
||||||
|
else "clone ERROR"; exit 1
|
||||||
|
fi
|
||||||
|
qm set $vmid --tags 3,gfx
|
||||||
|
echo "args: -virtfs local,id=khl,path=/mnt/pve/syno-tigra/shared/KHL,security_model=passthrough,mount_tag=khl" >> /etc/pve/qemu-server/${vmid}.conf
|
||||||
|
## preparing custom CloudInit snippets
|
||||||
|
cp ./khl.yaml /mnt/pve/syno-tigra/snippets/${vmid}_user.yaml
|
||||||
|
sed -i "s/HOSTNAME/$hostname/g" /mnt/pve/syno-tigra/snippets/${vmid}_user.yaml
|
||||||
|
qm resize $vmid scsi0 +50G
|
||||||
|
qm set $vmid --cicustom "user=syno-tigra:snippets/${vmid}_user.yaml"
|
||||||
|
qm set $vmid --ipconfig0 ip=$ip/24,gw=10.10.35.1
|
||||||
|
qm cloudinit update $vmid
|
||||||
|
qm start $vmid
|
||||||
|
done
|
||||||
|
echo "VMs from 'khl_hosts' successfully created"
|
||||||
Reference in New Issue
Block a user