Skip to content

Commit

Permalink
Merge pull request #32 from stackhpc/cpu_mode
Browse files Browse the repository at this point in the history
Allow cpu_mode to be set to none
  • Loading branch information
jovial authored Oct 21, 2019
2 parents d96997c + 5b5141d commit e828b37
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Role Variables
- `libvirt_vm_emulator`: path to emulator binary. If not set, the role will
attempt to auto-detect the correct emulator to use.

- `libvirt_cpu_mode_default`: The default CPU mode if `libvirt_cpu_mode` or
`vm.cpu_mode` is undefined.

- `libvirt_vm_arch`: CPU architecture, default is `x86_64`.

- `libvirt_vm_uri`: Override the libvirt connection URI. See the
Expand All @@ -49,7 +52,8 @@ Role Variables
`libvirt_vm_engine` is `kvm`, otherwise `pc-1.0`.

- `cpu_mode`: Virtual machine CPU mode. Default is `host-passthrough` if
`libvirt_vm_engine` is `kvm`, otherwise `host-model`.
`libvirt_vm_engine` is `kvm`, otherwise `host-model`. Can be set to none
to not configure a cpu mode.

- `volumes`: a list of volumes to attach to the VM. Each volume is
defined with the following dict:
Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ libvirt_vms:
machine: "{{ libvirt_vm_machine }}"

# Virtual machine CPU mode.
cpu_mode: "{{ libvirt_vm_cpu_mode }}"
cpu_mode: "{{ libvirt_vm_cpu_mode | default(libvirt_cpu_mode_default, true) }}"

# List of volumes.
volumes: "{{ libvirt_vm_volumes }}"
Expand All @@ -70,6 +70,9 @@ libvirt_vm_virsh_default_env: "{{ { 'LIBVIRT_DEFAULT_URI': libvirt_vm_uri } if
# Override for the libvirt connection uri. Leave unset to use the default.
libvirt_vm_uri: ""

# Default CPU mode if libvirt_vm_cpu_mode or vm.cpu_mode is undefined
libvirt_cpu_mode_default: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}"

### DEPRECATED ###
# Use the above settings for each item within `libvirt_vms`, instead of the
# below deprecated variables.
Expand Down
3 changes: 1 addition & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
default(libvirt_vm_default_console_log_dir + '/' + vm.name + '-console.log', true) }}
machine_default: "{{ none if libvirt_vm_engine == 'kvm' else 'pc-1.0' }}"
machine: "{{ vm.machine | default(machine_default, true) }}"
cpu_mode_default: "{{ 'host-passthrough' if libvirt_vm_engine == 'kvm' else 'host-model' }}"
cpu_mode: "{{ vm.cpu_mode | default(cpu_mode_default, true) }}"
cpu_mode: "{{ vm.cpu_mode | default(libvirt_cpu_mode_default) }}"
volumes: "{{ vm.volumes | default([], true) }}"
interfaces: "{{ vm.interfaces | default([], true) }}"
start: "{{ vm.start | default(true) }}"
Expand Down
4 changes: 3 additions & 1 deletion templates/vm.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
<boot dev='network'/>
<bios useserial='yes'/>
</os>
<cpu{% if cpu_mode is not none %} mode='{{ cpu_mode }}'{% endif %}>
{% if cpu_mode %}
<cpu mode='{{ cpu_mode }}'>
<model fallback='allow'/>
</cpu>
{% endif %}
<devices>
<emulator>{{ libvirt_vm_emulator }}</emulator>
{% for volume in volumes %}
Expand Down

0 comments on commit e828b37

Please sign in to comment.