Skip to content

Commit 31b18a7

Browse files
committed
Add VM machine and CPU mode support
Machine default is pc-1.0. Perhaps this should be none by default? Mode default is 'host-passthrough' for KVM, 'host-model' otherwise.
1 parent c1c3433 commit 31b18a7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ attempt to auto-detect the correct emulator to use.
2929

3030
`libvirt_vm_arch`: CPU architecture, default is `x86_64`.
3131

32+
`libvirt_vm_machine`: Virtual machine type. Default is `None` if
33+
`libvirt_vm_engine` is `kvm`, otherwise `pc-1.0`.
34+
35+
`libvirt_vm_cpu_mode`: Virtual machine CPU mode. Default is `host-passthrough`
36+
if `libvirt_vm_engine` is `kvm`, otherwise `host-model`.
37+
3238
`libvirt_vm_volumes`: a list of volumes to attach to the VM. Each volume is
3339
defined with the following dict:
3440
- `name`: Name to associate with the volume being created.

defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ libvirt_vm_emulator:
2222
# CPU architecture.
2323
libvirt_vm_arch: x86_64
2424

25+
# Virtual machine type.
26+
libvirt_vm_machine: "{{ None if libvirt_vm_engine == 'kvm' else 'pc-1.0' }}"
27+
28+
# Virtual machine CPU mode.
29+
libvirt_vm_cpu_mode: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}"
30+
2531
# List of volumes.
2632
libvirt_vm_volumes: []
2733

templates/vm.xml.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<vcpu>{{ libvirt_vm_vcpus }}</vcpu>
55
<clock sync="localtime"/>
66
<os>
7-
<type arch='{{ libvirt_vm_arch }}'>hvm</type>
7+
<type arch='{{ libvirt_vm_arch }}'{% if libvirt_vm_machine is not none %} machine='{{ libvirt_vm_machine }}'{% endif %}>hvm</type>
88
</os>
9-
{% if libvirt_vm_engine == 'kvm' %}
10-
<cpu mode='host-passthrough'/>
11-
{% endif %}
9+
<cpu{% if libvirt_vm_cpu_mode is not none %} mode='{{ libvirt_vm_cpu_mode }}'{% endif %}>
10+
<model fallback='allow'/>
11+
</cpu>
1212
<devices>
1313
<emulator>{{ libvirt_vm_emulator }}</emulator>
1414
{% for volume in libvirt_vm_volumes %}

0 commit comments

Comments
 (0)