Skip to content
Snippets Groups Projects
Commit 7fa64239 authored by Florent Gluck's avatar Florent Gluck
Browse files

Added a bash script, template_creator, to help with the creation of disk images for templates

parent f832d2fd
Branches
No related tags found
No related merge requests found
......@@ -157,13 +157,13 @@ TODO:
### Template management
| Done | Route | Description | Method | Parameters | Required capabilities |
|--- |--- |--- |--- |--- |--- |
| | `/templates` | create a template | POST | vmID/qcow,name,description,access | `CAP_TPL_CREATE` |
| p | `/templates/{name}` | delete a template | DELETE | | `CAP_TPL_DESTROY|CAP_TPL_DESTROY_ANY` |
| p | `/templates` | list templates | GET | | `CAP_TPL_LIST|CAP_TPL_LIST_ANY` |
| p | `/templates/{name}` | list a template | GET | | `CAP_TPL_LIST|CAP_TPL_LIST_ANY` |
| | | | | | |
| Done | Route | Description | Method | Parameters | Required capabilities |
|--- |--- |--- |--- |--- |--- |
| | `/templates` | create a template | POST | vmID/qcow,name,descr,access | `CAP_TPL_CREATE` |
| p | `/templates/{name}` | delete a template | DELETE | | `CAP_TPL_DESTROY|CAP_TPL_DESTROY_ANY` |
| p | `/templates` | list templates | GET | | `CAP_TPL_LIST|CAP_TPL_LIST_ANY` |
| p | `/templates/{name}` | list a template | GET | | `CAP_TPL_LIST|CAP_TPL_LIST_ANY` |
| | | | | | |
Remarks:
......@@ -187,7 +187,7 @@ Remarks:
VM launched with QEMU running a spice server:
```
qemu-system-x86_64 -enable-kvm -smp cpus=$CPU -m $RAM -drive file=$DISK,index=0,media=disk,format=qcow2,if=virtio -vga virtio -device virtio-serial-pci -spice port=$SPICE_PORT,password=$SPICE_PWD -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent -nic user,mac=$MAC,model=virtio-net-pci -soundhw hda
qemu-system-x86_64 -enable-kvm -cpu host -smp cpus=$CPU -m $RAM -drive file=$DISK,index=0,media=disk,format=qcow2,if=virtio -vga virtio -device virtio-serial-pci -spice port=$SPICE_PORT,password=$SPICE_PWD -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent -nic user,mac=$MAC,model=virtio-net-pci -soundhw hda
```
The following parameters are defined at instantiation:
......@@ -212,10 +212,16 @@ The following parameters are defined at instantiation:
```
- At creation time, expose an option to choose whether to feature a network interface or not (typically, for exams)
Remark: to list the baking file of a disk:
```
qemu-img info --backing-chain disk.qcow
```
Remarks:
- To list the baking file of a disk:
```
qemu-img info --backing-chain disk.qcow
```
- To create an empty disk of 200GB:
```
qemu-img create -f qcow2 disk.qcow 200G
```
## File structure
......
#!/bin/bash
CPU=2
RAM=4096
DISK=disk.qcow
DISK_SIZE=200G
overwrite=1
function echoerr {
echo "$@" >&2
}
if [ $# -ne 1 ]; then
appname=`basename $0`
echoerr "$appname, a tool to create a VM template from an ISO image."
echoerr "Upon installation completion, \"$DISK\" can be used in a VM template."
echoerr "Usage: $appname ISO"
echoerr "where ISO is an ISO image file of the OS to install."
exit 1
fi
ISO_IMAGE=$1
if ! [ -f $ISO_IMAGE ]; then
echoerr "ISO image \"$ISO_IMAGE\" not found!"
exit 1
fi
if [ -f $DISK ]; then
echo "Disk image \"$DISK\" already exists."
read -e -p "Overwrite it? [y/N] " choice
[[ "$choice" == [Yy]* ]] && overwrite=1 || overwrite=0
fi
if [ $overwrite -eq 1 ]; then
qemu-img create -f qcow2 $DISK $DISK_SIZE
fi
qemu-system-x86_64 -enable-kvm -cpu host -smp cpus=$CPU -m $RAM -drive file=$DISK,index=0,media=disk,format=qcow2,if=virtio -vga virtio -device virtio-serial-pci -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent -nic user,model=virtio-net-pci -soundhw hda -drive file=$ISO_IMAGE,index=1,media=cdrom,format=raw,read-only
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment