Skip to content

Commit c4a8479

Browse files
authored
Merge pull request #5 from w-miller/direct-interfaces
Allow configuration of direct interfaces
2 parents c255cb5 + b396f39 commit c4a8479

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,25 @@ Role Variables
5858

5959
- `interfaces`: a list of network interfaces to attach to the VM.
6060
Each network interface is defined with the following dict:
61-
- `network`: Name of the network to which an interface should be attached.
61+
62+
- `type`: The type of the interface. Possible values:
63+
64+
- `network`: Attaches the interface to a named Libvirt virtual
65+
network. This is the default value.
66+
- `direct`: Directly attaches the interface to one of the host's
67+
physical interfaces, using the `macvtap` driver.
68+
- `network`: Name of the network to which an interface should be
69+
attached. Must be specified if and only if the interface `type` is
70+
`network`.
71+
- `source`: A dict defining the host interface to which this
72+
VM interface should be attached. Must be specified if and only if the
73+
interface `type` is `direct`. Includes the following attributes:
74+
75+
- `dev`: The name of the host interface to which this VM interface
76+
should be attached.
77+
- `mode`: options include `vepa`, `bridge`, `private` and
78+
`passthrough`. See `man virsh` for more details. Default is
79+
`vepa`.
6280

6381
- `console_log_enabled`: if `true`, log console output to a file at the
6482
path specified by `console_log_path`, **instead of** to a PTY. If

tasks/check-interface.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: Check network interface has a network name
3+
fail:
4+
msg: >
5+
The interface definition {{ interface }} has type 'network', but does not have
6+
a network name defined.
7+
when:
8+
- interface.type is not defined or
9+
interface.type == 'network'
10+
- interface.network is not defined
11+
12+
- name: Check direct interface has an interface device name
13+
fail:
14+
msg: >
15+
The interface definition {{ interface }} has type 'direct', but does not have
16+
a host source device defined.
17+
when:
18+
- interface.type is defined
19+
- interface.type == 'direct'
20+
- interface.source is not defined or
21+
interface.source.dev is not defined

tasks/vm.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
when: console_log_enabled | bool
1111
become: true
1212

13+
- name: Validate VM interfaces
14+
include_tasks: check-interface.yml
15+
vars:
16+
interface: "{{ item }}"
17+
with_items: "{{ vm.interfaces }}"
18+
1319
- name: Ensure the VM is defined
1420
virt:
1521
name: "{{ vm.name }}"

templates/vm.xml.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@
2626
</disk>
2727
{% endfor %}
2828
{% for interface in interfaces %}
29+
{% if interface.type is defined and interface.type == 'direct' %}
30+
<interface type='direct'>
31+
<source dev='{{ interface.source.dev }}' mode='{{ interface.source.mode | default('vepa') }}'/>
32+
{% else %}
2933
<interface type='network'>
3034
<source network='{{ interface.network }}'/>
35+
{% endif %}
3136
<model type='virtio'/>
3237
</interface>
3338
{% endfor %}

0 commit comments

Comments
 (0)