summaryrefslogtreecommitdiff
path: root/roles/vm/guest/create/templates/libvirt-domain.xml.j2
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2022-01-06 19:22:14 +0100
committerChristian Pointner <equinox@spreadspace.org>2022-01-06 19:22:14 +0100
commite3d0be5df3a8a43b19da0bb814c8174048cfc79f (patch)
treeadf9917fb0dbe94328c465da5e46b96317a3870d /roles/vm/guest/create/templates/libvirt-domain.xml.j2
parentMerge branch 'topic/openwrt-deploy' (diff)
split up vm/define into remove and create
Diffstat (limited to 'roles/vm/guest/create/templates/libvirt-domain.xml.j2')
-rw-r--r--roles/vm/guest/create/templates/libvirt-domain.xml.j296
1 files changed, 96 insertions, 0 deletions
diff --git a/roles/vm/guest/create/templates/libvirt-domain.xml.j2 b/roles/vm/guest/create/templates/libvirt-domain.xml.j2
new file mode 100644
index 00000000..96b12a74
--- /dev/null
+++ b/roles/vm/guest/create/templates/libvirt-domain.xml.j2
@@ -0,0 +1,96 @@
+<domain type='kvm'>
+ <name>{{ inventory_hostname }}</name>
+ <memory>{{ ((install.vm.memory | human_to_bytes) / 1024) | int }}</memory>
+ <currentMemory>{{ ((install.vm.memory | human_to_bytes) / 1024) | int }}</currentMemory>
+ <vcpu>{{ install.vm.numcpus }}</vcpu>
+ <os>
+ <type arch='x86_64' machine='q35'>hvm</type>
+{% if vm_create_installer %}
+{% if install_distro == 'debian' or install_distro == 'ubuntu' %}
+ <kernel>{{ installer_tmpdir }}/linux</kernel>
+ <initrd>{{ installer_tmpdir }}/initrd.gz</initrd>
+ <cmdline>console=ttyS0,115200n8 auto</cmdline>
+ <boot dev='hd'/>
+{% elif install_distro == 'openbsd' %}
+ <boot dev='cdrom'/>
+{% endif %}
+{% else %}
+ <boot dev='hd'/>
+{% endif %}
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+{% if vm_create_installer %}
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+{% else %}
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+{% endif %}
+ <devices>
+ <emulator>/usr/bin/kvm</emulator>
+ <!-- Provide a virtualized RNG to the guest -->
+ <rng model='virtio'>
+ <!-- Allow consuming up to 10kb/s, measured over 2s -->
+ <rate period="2000" bytes="20480"/>
+ <backend model='random'>/dev/random</backend>
+ </rng>
+
+{% if vm_create_installer and install_distro == 'openbsd' %}
+ <disk type='file' device='cdrom'>
+ <driver name='qemu'/>
+ <source file='{{ installer_tmpdir }}/{{ inventory_hostname }}.iso'/>
+ <target dev='sdz' bus='sata'/>
+ <readonly/>
+ </disk>
+
+{% endif %}
+{% if install.disks %}
+{% if 'scsi' in install.disks %}
+ <controller type='scsi' index='0' model='virtio-scsi'/>
+{% endif %}
+{% for bus in ['virtio', 'scsi'] %}
+{% for device, src in (install.disks[bus] | default({})).items() %}
+ <disk type='{{ (src.type == 'image') | ternary('file', 'block') }}' device='disk'>
+ <driver name='qemu' type='raw' cache='none' discard='unmap'/>
+{% if src.type == 'lvm' %}
+ <source dev='/dev/mapper/{{ src.vg | replace('-', '--') }}-{{ src.lv | replace('-', '--') }}'/>
+{% elif src.type == 'zfs' %}
+ <source dev='/dev/zvol/{{ vm_host.zfs[src.backend | default('default')].pool }}/{{ vm_host.zfs[src.backend | default('default')].name }}/{{ inventory_hostname }}/{{ src.name }}'/>
+{% elif src.type == 'blockdev' %}
+ <source dev='{{ src.path }}'/>
+{% elif src.type == 'image' %}
+ <source file='{{ src.path }}'/>
+{% endif %}
+ <target dev='{{ device }}' bus='{{ bus }}'/>
+ </disk>
+{% endfor %}
+{% endfor %}
+
+{% endif %}
+{% if install.interfaces %}
+{% for if in install.interfaces %}
+ <interface type='bridge'>
+{% if 'mac' in if %}
+ <mac address='{{ if.mac }}'/>
+{% endif %}
+ <source bridge='{{ if.bridge }}'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x{{ "%02x" | format(loop.index0 + 16) }}' slot='0x00' function='0x0'/>
+ </interface>
+{% endfor %}
+
+{% endif %}
+ <serial type='pty'>
+ <target port='0'/>
+ </serial>
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+ </devices>
+</domain>