summaryrefslogtreecommitdiffstats
path: root/create-new-vm.sh
diff options
context:
space:
mode:
Diffstat (limited to 'create-new-vm.sh')
-rwxr-xr-xcreate-new-vm.sh87
1 files changed, 87 insertions, 0 deletions
diff --git a/create-new-vm.sh b/create-new-vm.sh
new file mode 100755
index 0000000..dd4a4ed
--- /dev/null
+++ b/create-new-vm.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+set -e
+
+name=$1
+size=20G
+
+TMPDIR="`mktemp -d "/tmp/fb-client-up.XXXXXX"`"
+trap "rm -rf '${TMPDIR}'" EXIT TERM
+cd "$TMPDIR"
+
+cat <<EOF >vm.xml
+<domain type='kvm'>
+ <name>$name</name>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>4</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-1.7'>hvm</type>
+ <boot dev='hd'/>
+ <boot dev='network'/>
+ <bootmenu enable='no'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/sbin/qemu-system-x86_64</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2'/>
+ <source file='/mnt/data/libvirt/storage/${name}.img'/>
+ <target dev='vda' bus='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+ </disk>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='scsi' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </controller>
+ <controller type='scsi' index='1' model='virtio-scsi'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
+ </controller>
+ <interface type='network'>
+ <source network='mynet'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ <serial type='pty'>
+ <target port='0'/>
+ </serial>
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes'/>
+ <sound model='ich6'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+ </sound>
+ <video>
+ <model type='cirrus' vram='9216' heads='1'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </video>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+ </memballoon>
+ </devices>
+</domain>
+EOF
+
+virsh vol-create-as nfs ${name}.img $size --format qcow2
+virsh define vm.xml
+
+vmmac=$(virsh domiflist $name | grep -oE "[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}")
+echo "$name" > /srv/http/vms/hostnames/"$vmmac"
+
+virsh start $name