diff options
author | Christian Pointner <equinox@spreadspace.org> | 2020-07-11 02:58:28 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2020-07-11 02:58:28 +0200 |
commit | 49c58d575f420165f7d8341bccb8b4ba4629e735 (patch) | |
tree | dfbfe6a937ec04fa7d48de8c1d08a1596ba837b2 /roles/vm/guest/define/templates | |
parent | Merge branch 'topic/debian-installer-verification' (diff) | |
parent | ch-gnocchi: remove temporary interface config (diff) |
Merge branch 'topic/vm-host-network'
Diffstat (limited to 'roles/vm/guest/define/templates')
-rw-r--r-- | roles/vm/guest/define/templates/libvirt-domain.xml.j2 | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/roles/vm/guest/define/templates/libvirt-domain.xml.j2 b/roles/vm/guest/define/templates/libvirt-domain.xml.j2 new file mode 100644 index 00000000..ba0dcd5a --- /dev/null +++ b/roles/vm/guest/define/templates/libvirt-domain.xml.j2 @@ -0,0 +1,102 @@ +<domain type='kvm'> + <name>{{ install_hostname }}</name> + <memory>{{ ((hostvars[install_hostname].install_cooked.vm.memory | human_to_bytes) / 1024) | int }}</memory> + <currentMemory>{{ ((hostvars[install_hostname].install_cooked.vm.memory | human_to_bytes) / 1024) | int }}</currentMemory> + <vcpu>{{ hostvars[install_hostname].install_cooked.vm.numcpus }}</vcpu> + <os> + <type arch='x86_64' machine='pc-0.12'>hvm</type> +{% if vm_define_installer %} +{% if install_distro == 'debian' or install_distro == 'ubuntu' %} + <kernel>{{ installer_base_path }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[install_hostname].install_cooked.arch | default('amd64') }}-netboot/linux</kernel> + <initrd>{{ installer_tmpdir }}/initrd.{{ install_hostname }}.gz</initrd> + <cmdline>console=ttyS0,115200n8 DEBCONF_DEBUG=5</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_define_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_define_installer and install_distro == 'openbsd' %} + <disk type='file' device='cdrom'> + <driver name='qemu'/> + <source file='{{ installer_tmpdir }}/{{ install_hostname }}.iso'/> + <target dev='hdc' bus='ide'/> + <readonly/> + </disk> + +{% endif %} +{% if 'virtio' in hostvars[install_hostname].install_cooked.disks %} +{% for device, src in hostvars[install_hostname].install_cooked.disks.virtio.items() %} + <disk type='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_cooked.zfs[src.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[src.backend | default('default')].name }}/{{ install_hostname }}/{{ src.name }}'/> +{% endif %} + <target dev='{{ device }}' bus='virtio'/> + </disk> +{% endfor %} +{% endif %} + +{% if 'scsi' in hostvars[install_hostname].install_cooked.disks %} + <controller type='scsi' index='0' model='virtio-scsi'/> +{% for device, src in hostvars[install_hostname].install_cooked.disks.scsi.items() %} + <disk type='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_cooked.zfs[src.backend | default('default')].pool }}/{{ vm_host_cooked.zfs[src.backend | default('default')].name }}/{{ install_hostname }}/{{ src.name }}'/> +{% endif %} + <target dev='{{ device }}' bus='scsi'/> + </disk> +{% endfor %} +{% endif %} + +{% if hostvars[install_hostname].install_cooked.interfaces %} +{% for if in hostvars[install_hostname].install_cooked.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='0x01' slot='0x0{{ loop.index }}' function='0x0'/> + </interface> +{% endfor %} +{% endif %} + + <serial type='pty'> + <target port='0'/> + </serial> + <console type='pty'> + <target type='serial' port='0'/> + </console> + </devices> +</domain> |