blob: 6a4f1fe939001bf89c7e8d94b62ef2403c79b327 [file] [log] [blame]
alexz1c02cd62018-04-15 22:18:03 +02001#!/bin/bash -xe
2
3VM_MGM_BRIDGE_NAME=${VM_MGM_BRIDGE_NAME:-"br-mgm"}
Dennis Dmitriev1b2ccb22018-06-08 20:38:07 +03004VM_MEM_KB=${VM_MEM_KB:-"8388608"}
alexz1c02cd62018-04-15 22:18:03 +02005VM_CPUS=${VM_CPUS:-"4"}
6
7if [[ -z ${VM_NAME} ]]; then
8 echo "ERROR: \$VM_NAME not set!"
9 exit 1
10fi
11if [[ ! -f ${VM_SOURCE_DISK} ]] || [[ -z ${VM_SOURCE_DISK} ]]; then
12 echo "ERROR: \$VM_SOURCE_DISK not set, or file does not exist!"
13 exit 1
14fi
15if [[ ! -f ${VM_CONFIG_DISK} ]] || [[ -z ${VM_CONFIG_DISK} ]]; then
16 echo "ERROR: \$VM_CONFIG_DISK not set, or file does not exist!"
17 exit 1
18fi
19
20# Template definition
21cat <<EOF > $(pwd)/${VM_NAME}-vm.xml
22<domain type='kvm'>
23 <name>$VM_NAME</name>
24 <memory unit='KiB'>$VM_MEM_KB</memory>
25 <currentMemory unit='KiB'>$VM_MEM_KB</currentMemory>
26 <vcpu placement='static'>$VM_CPUS</vcpu>
27 <resource>
28 <partition>/machine</partition>
29 </resource>
30 <os>
31 <type >hvm</type>
32 <boot dev='hd'/>
33 </os>
34 <features>
35 <acpi/>
36 </features>
37 <clock offset='utc'>
38 <timer name='rtc' tickpolicy='catchup'/>
39 <timer name='pit' tickpolicy='delay'/>
40 <timer name='hpet' present='no'/>
41 </clock>
42 <pm>
43 <suspend-to-mem enabled='no'/>
44 <suspend-to-disk enabled='no'/>
45 </pm>
46 <devices>
47 <emulator>/usr/bin/kvm-spice</emulator>
48 <disk type='file' device='disk'>
49 <driver name='qemu' type='qcow2' cache='none'/>
50 <source file='$VM_SOURCE_DISK'/>
51 <target dev='vda' bus='virtio'/>
52 <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
53 </disk>
54 <disk type='file' device='cdrom'>
55 <driver name='qemu' type='raw'/>
56 <source file='$VM_CONFIG_DISK'/>
57 <backingStore/>
58 <target dev='hda' bus='ide'/>
59 <readonly/>
60 <address type='drive' controller='0' bus='0' target='0' unit='0'/>
61 </disk>
62 <interface type='bridge'>
63 <source bridge='$VM_MGM_BRIDGE_NAME'/>
64 <model type='virtio'/>
65 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
66 </interface>
67EOF
68if [[ -n ${VM_CTL_BRIDGE_NAME} ]]; then
69echo "\$VM_CTL_BRIDGE_NAME detected, adding one more nic to VM"
70cat <<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}