-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-template
55 lines (49 loc) · 1.52 KB
/
create-template
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
## Created by Arya Pramudika
vmid=$1
name=$2
cpu=$3
memory=$4
net=$5
disk=$6
image=$7
Help()
{
# Display Help
echo "Proxmox Create Template Cloud-Image & Cloud-Init"
echo
echo "Syntax: create-template [vmid|name|cpu|memory|net|disk|image-file]"
echo "options:"
echo "vmid | vmid for template example: (9001)"
echo "name | name of template."
echo "cpu | total cores of template"
echo "memory | total memory of template(in MB)"
echo "net | network for template (vmbr0/vmbr1/etc)"
echo "disk | disk location for template (local-lvm/other storage)"
echo "image-file | cloud-image-file"
echo ""
echo "Full example command: "
echo "create-template 1001 template-ubuntu-20 2 4096 vmbr0 local-lvm focal-ubuntu.img"
echo
}
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
esac
done
echo "Creating $name template..."
qm create $vmid --cores $cpu --memory $memory --name $name --net0 virtio,bridge=$net > /dev/null 2>&1
qm set $vmid --virtio0 local:0,import-from=$image > /dev/null 2>&1
qm set $vmid --boot c --bootdisk virtio0 > /dev/null 2>&1
qm set $vmid --ide2 local:cloudinit > /dev/null 2>&1
qm set $vmid --serial0 socket --vga serial0 > /dev/null 2>&1
qm set $vmid --ipconfig0 ip=dhcp > /dev/null 2>&1
qm template $vmid > /dev/null 2>&1
##Check command
if [ $? -eq 0 ]; then
echo "Template $name created successfully"
else
echo "Failed to create $name template (Please check -help command)"
fi