Skip to content

Commit a803654

Browse files
authored
Merge pull request #70 from stackhpc/block-devices
Support passthrough block devices
2 parents 9fab5e6 + deaafb9 commit a803654

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Role Variables
2727
stored. Default is '/var/lib/libvirt/images'.
2828

2929
- `libvirt_volume_default_type`: What type of backing volume does the instance
30-
use? Default is `volume`. Options include `file`, `network` and `volume`.
30+
use? Default is `volume`. Options include `block`, `file`, `network` and
31+
`volume`.
3132

3233
- `libvirt_volume_default_format`: Format for volumes created by the role.
3334
Default is `qcow2`. Options include `raw`, `qcow2`, `vmdk`. See `man virsh`
@@ -116,6 +117,7 @@ Role Variables
116117
- `backing_image`: (optional) name of the backing volume which is assumed to already be the same pool (copy-on-write).
117118
- `image` and `backing_image` are mutually exclusive options.
118119
- `target`: (optional) Manually influence type and order of volumes
120+
- `dev`: (optional) Block device path when type is `block`.
119121

120122
- `interfaces`: a list of network interfaces to attach to the VM.
121123
Each network interface is defined with the following dict:
@@ -219,6 +221,9 @@ Example Playbook
219221
- 'mon1.example.org'
220222
- 'mon2.example.org'
221223
- 'mon3.example.org'
224+
- type: 'block'
225+
format: 'raw'
226+
dev: '/dev/sda'
222227

223228
interfaces:
224229
- network: 'br-datacentre'

tasks/volumes.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
src: "{{ item.image }}"
1313
dest: "{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}"
1414
checksum: "{{ item.checksum | default(omit) }}"
15+
remote_src: true
1516
with_items: "{{ volumes | selectattr('image', 'defined') | list }}"
1617
when: "'http' not in item.image"
1718

templates/vm.xml.j2

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,21 @@
4040
<driver name='qemu' type='{{ volume.format | default(libvirt_volume_default_format) }}'/>
4141
{% if volume.type | default(libvirt_volume_default_type) == 'file' %}
4242
<source file='{{ volume.file_path |default(libvirt_volume_default_images_path) }}/{{ volume.name}}'/>
43-
{% elif volume.type is defined and volume.type == 'network' %}
43+
{% elif volume.type | default(libvirt_volume_default_type) == 'network' %}
4444
{% if volume.auth.username is defined %}
45-
<auth username='{{ volume.auth.username }}'>
46-
<secret type='{{ volume.auth.type }}' {% if volume.auth.uuid is defined and volume.auth.uuid is not none %} uuid='{{ volume.auth.uuid }}' {% else %} usage='{{ volume.auth.usage }}' {% endif %}/>
47-
</auth>
45+
<auth username='{{ volume.auth.username }}'>
46+
<secret type='{{ volume.auth.type }}' {% if volume.auth.uuid is defined and volume.auth.uuid is not none %} uuid='{{ volume.auth.uuid }}' {% else %} usage='{{ volume.auth.usage }}' {% endif %}/>
47+
</auth>
4848
{% endif %} {# End volume.auth.username check #}
4949
{% if volume.source.name is defined %}
50-
<source protocol='{{ volume.source.protocol }}' name='{{ volume.source.name }}'>
50+
<source protocol='{{ volume.source.protocol }}' name='{{ volume.source.name }}'>
5151
{% for host in volume.source.hosts_list %}
52-
<host name='{{ host }}' {% if volume.source.port is defined and volume.source.port is not none %} port='{{ volume.source.port }}' {% endif %}/>
52+
<host name='{{ host }}' {% if volume.source.port is defined and volume.source.port is not none %} port='{{ volume.source.port }}' {% endif %}/>
5353
{% endfor %}
54-
</source>
54+
</source>
5555
{% endif %} {# End volume.source.name check #}
56+
{% elif volume.type | default(libvirt_volume_default_type) == 'block' %}
57+
<source dev='{{ volume.dev }}'/>
5658
{% else %} {# End elif volume.type is defined #}
5759
<source pool='{{ volume.pool }}' volume='{{ volume.name }}'/>
5860
{% endif %}

0 commit comments

Comments
 (0)