blob: 7914c94069ca979db729a612fc46b9864a1acb24 [file] [log] [blame]
alexz1c02cd62018-04-15 22:18:03 +02001#!/bin/bash -xe
2
3VM_MGM_BRIDGE_NAME=${VM_MGM_BRIDGE_NAME:-"br-mgm"}
Richard Felklbe962ed2018-06-14 17:28:08 +02004VM_CTL_BRIDGE_NAME=${VM_CTL_BRIDGE_NAME:-"br-ctl"}
Dennis Dmitriev1b2ccb22018-06-08 20:38:07 +03005VM_MEM_KB=${VM_MEM_KB:-"8388608"}
alexz1c02cd62018-04-15 22:18:03 +02006VM_CPUS=${VM_CPUS:-"4"}
7
8if [[ -z ${VM_NAME} ]]; then
9 echo "ERROR: \$VM_NAME not set!"
10 exit 1
11fi
12if [[ ! -f ${VM_SOURCE_DISK} ]] || [[ -z ${VM_SOURCE_DISK} ]]; then
13 echo "ERROR: \$VM_SOURCE_DISK not set, or file does not exist!"
14 exit 1
15fi
16if [[ ! -f ${VM_CONFIG_DISK} ]] || [[ -z ${VM_CONFIG_DISK} ]]; then
17 echo "ERROR: \$VM_CONFIG_DISK not set, or file does not exist!"
18 exit 1
19fi
20
21# Template definition
22cat <<EOF > $(pwd)/${VM_NAME}-vm.xml
23<domain type='kvm'>
24 <name>$VM_NAME</name>
25 <memory unit='KiB'>$VM_MEM_KB</memory>
26 <currentMemory unit='KiB'>$VM_MEM_KB</currentMemory>
27 <vcpu placement='static'>$VM_CPUS</vcpu>
28 <resource>
29 <partition>/machine</partition>
30 </resource>
31 <os>
32 <type >hvm</type>
33 <boot dev='hd'/>
34 </os>
35 <features>
36 <acpi/>
37 </features>
38 <clock offset='utc'>
39 <timer name='rtc' tickpolicy='catchup'/>
40 <timer name='pit' tickpolicy='delay'/>
41 <timer name='hpet' present='no'/>
42 </clock>
43 <pm>
44 <suspend-to-mem enabled='no'/>
45 <suspend-to-disk enabled='no'/>
46 </pm>
47 <devices>
48 <emulator>/usr/bin/kvm-spice</emulator>
49 <disk type='file' device='disk'>
50 <driver name='qemu' type='qcow2' cache='none'/>
51 <source file='$VM_SOURCE_DISK'/>
52 <target dev='vda' bus='virtio'/>
53 <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
54 </disk>
55 <disk type='file' device='cdrom'>
56 <driver name='qemu' type='raw'/>
57 <source file='$VM_CONFIG_DISK'/>
58 <backingStore/>
59 <target dev='hda' bus='ide'/>
60 <readonly/>
61 <address type='drive' controller='0' bus='0' target='0' unit='0'/>
62 </disk>
63 <interface type='bridge'>
64 <source bridge='$VM_MGM_BRIDGE_NAME'/>
65 <model type='virtio'/>
66 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
67 </interface>
68EOF
Richard Felklbe962ed2018-06-14 17:28:08 +020069if [[ ! ${VM_CTL_BRIDGE_DISABLE} ]]; then
alexz1c02cd62018-04-15 22:18:03 +020070cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
71 <interface type='bridge'>
72 <source bridge='$VM_CTL_BRIDGE_NAME'/>
73 <model type='virtio'/>
74 <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
75 </interface>
76EOF
77fi
78cat <<EOF >> $(pwd)/${VM_NAME}-vm.xml
79 <serial type='pty'>
80 <source path='/dev/pts/1'/>
81 <target port='0'/>
82 </serial>
83 <console type='pty' tty='/dev/pts/1'>
84 <source path='/dev/pts/1'/>
85 <target type='serial' port='0'/>
86 </console>
87 <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
88 <listen type='address' address='127.0.0.1'/>
89 </graphics>
90 </devices>
91</domain>
92EOF
93
94echo "INFO: rendered VM config:"
95cat $(pwd)/${VM_NAME}-vm.xml
96
97virsh define $(pwd)/${VM_NAME}-vm.xml
98virsh autostart ${VM_NAME}