-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-vm
32 lines (27 loc) · 880 Bytes
/
create-vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
## This script is create VM by cloning template (output of create-template script)
# Help script
if [[ $1 == "--help" || $1 == "-h" || $1 == "help" || $# -eq 0 ]]; then
echo "Usage: create-vm | template-id | vmid | name | cpu | memory | disk"
echo " "
echo "Example: create-vm 901 101 debian-vm 4 4 30G"
echo " "
echo "Example: create bulk vm: "
echo "for i in {1..10}; do create-vm 90 100$i nodes$i 4 4 30G; done"
echo "Options:"
echo " --help, -h, help Show this help message"
exit 0
fi
temid=$1
vmid=$2
name=$3
cpu=$4
mem=$(( $5 * 1024 ))
disk=$6
qm clone $temid $vmid --name $name --full > /dev/null 2>&1
##Set Nested VM
qm set $vmid --cpu host > /dev/null 2>&1
## Set CPU/Memory/Disk
qm set $vmid --cores=$cpu > /dev/null 2>&1
qm set $vmid --memory=$mem > /dev/null 2>&1
qm resize $vmid virtio0 $disk > /dev/null 2>&1