azvyagintsev | 6bb49a7 | 2018-03-27 14:37:03 +0300 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
| 3 | MIRROR_VM_MGM_BRIDGE_NAME=${MIRROR_VM_MGM_BRIDGE_NAME:-"br-mgm"} |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 4 | MIRROR_VM_MEM_KB=${MIRROR_VM_MEM_KB:-"4194304"} |
| 5 | MIRROR_VM_CPUS=${MIRROR_VM_CPUS:-"4"} |
azvyagintsev | 6bb49a7 | 2018-03-27 14:37:03 +0300 | [diff] [blame] | 6 | |
| 7 | if [[ -z ${MIRROR_VM_NAME} ]]; then |
| 8 | echo "ERROR: \$MIRROR_VM_NAME not set!" |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | cat <<EOF > $(pwd)/mirror-vm.xml |
| 13 | <domain type='kvm'> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 14 | <name>$MIRROR_VM_NAME</name> |
| 15 | <memory unit='KiB'>$MIRROR_VM_MEM_KB</memory> |
| 16 | <currentMemory unit='KiB'>$MIRROR_VM_MEM_KB</currentMemory> |
| 17 | <vcpu placement='static'>$MIRROR_VM_CPUS</vcpu> |
| 18 | <resource> |
| 19 | <partition>/machine</partition> |
| 20 | </resource> |
| 21 | <os> |
| 22 | <type >hvm</type> |
| 23 | <boot dev='hd'/> |
| 24 | </os> |
| 25 | <features> |
| 26 | <acpi/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 27 | </features> |
| 28 | <clock offset='utc'> |
| 29 | <timer name='rtc' tickpolicy='catchup'/> |
| 30 | <timer name='pit' tickpolicy='delay'/> |
| 31 | <timer name='hpet' present='no'/> |
| 32 | </clock> |
| 33 | <pm> |
| 34 | <suspend-to-mem enabled='no'/> |
| 35 | <suspend-to-disk enabled='no'/> |
| 36 | </pm> |
| 37 | <devices> |
| 38 | <emulator>/usr/bin/kvm-spice</emulator> |
| 39 | <disk type='file' device='disk'> |
| 40 | <driver name='qemu' type='qcow2' cache='none'/> |
| 41 | <source file='$MIRROR_VM_SOURCE_DISK'/> |
| 42 | <target dev='vda' bus='virtio'/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 43 | <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> |
| 44 | </disk> |
| 45 | <disk type='file' device='cdrom'> |
| 46 | <driver name='qemu' type='raw'/> |
| 47 | <source file='$MIRROR_VM_CONFIG_DISK'/> |
| 48 | <backingStore/> |
| 49 | <target dev='hda' bus='ide'/> |
| 50 | <readonly/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 51 | <address type='drive' controller='0' bus='0' target='0' unit='0'/> |
| 52 | </disk> |
| 53 | <interface type='bridge'> |
| 54 | <source bridge='$MIRROR_VM_MGM_BRIDGE_NAME'/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 55 | <model type='virtio'/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 56 | <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> |
| 57 | </interface> |
| 58 | <serial type='pty'> |
| 59 | <source path='/dev/pts/1'/> |
| 60 | <target port='0'/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 61 | </serial> |
| 62 | <console type='pty' tty='/dev/pts/1'> |
| 63 | <source path='/dev/pts/1'/> |
| 64 | <target type='serial' port='0'/> |
Richard Felkl | dc2ecf6 | 2018-03-23 13:09:41 +0100 | [diff] [blame] | 65 | </console> |
| 66 | <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'> |
| 67 | <listen type='address' address='127.0.0.1'/> |
| 68 | </graphics> |
| 69 | </devices> |
azvyagintsev | 6bb49a7 | 2018-03-27 14:37:03 +0300 | [diff] [blame] | 70 | </domain> |
| 71 | EOF |
| 72 | |
| 73 | echo "INFO: rendered VM config:" |
| 74 | cat $(pwd)/mirror-vm.xml |
| 75 | |
| 76 | virsh define $(pwd)/mirror-vm.xml |
| 77 | virsh autostart ${MIRROR_VM_NAME} |