Skip to content

Commit

Permalink
add additional network interface types for domain definition
Browse files Browse the repository at this point in the history
This is based on the idea of @sebastianrakel and @bastelfreak
in pull request #81. Besides adding bridges this also adds additional
network types.

This deprecates the 'network' and 'portgroup' parameters in favor
of the more flexible 'source' parameter in the network interface hash.
The deprecated parameters will remain functional until next major release.
  • Loading branch information
trefzer committed Feb 12, 2025
1 parent f47b5db commit 4199668
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
25 changes: 17 additions & 8 deletions manifests/domain.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@
# Array of hashes defining the network interfaces of this domain. Defaults to
# no network interfaces.
# The hashes support the following keys:
# * mac: MAC address of the interface. Without a mac key, a random
# address will be assigned by libvirt. The MAC address should
# start with 52:54:00.
# * network: libvirt network to attach to (mandatory).
# * portgroup: portgroup to attach to (optional).
# * type: Type of network card. Defaults to 'virtio'.
# * boot_order: Integer starting at 1 for the highest priority (shared with
# disks).
# * interface_type: the type of the interface, currently supported:
# 'network', 'bridge', 'vdpa', 'mcast', 'server', 'client', 'null', 'vds',
# defaults to 'network' if unset.
# * mac: MAC address of the interface. Without a mac key, a random
# address will be assigned by libvirt. The MAC address should
# start with 52:54:00.
# * source: Hash of the source (network/bridge to attach to) (optional)
# this will translate to keyX = valueX for all key value pairs
# in the hash added as attributes to the source tag in the resulting XML
# * type: Type of network card. Defaults to 'virtio'.
# * boot_order: Integer starting at 1 for the highest priority (shared with
# disks).
# Deprecated keys:
# * network: libvirt network to attach to (optional, depracated, use source).
# instead of this parameter, use source = { '[network|bridge]' => NETWORK }
# * portgroup: portgroup to attach to (optional, deprecated, use source).
# instead of this parameter, use source = { '[network|bridge]' => NETWORK, 'portgroup' => 'GROUP }
# @param autostart
# Wheter the libvirt autostart flag should be set. Defaults to true. Autostart
# domains are started if the host is booted.
Expand Down
8 changes: 6 additions & 2 deletions templates/domain/device_interface.epp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%- | Libvirt::Domain::Interface $iface,
String $boot,
| -%>
<interface type='network'>
<interface type='<%= pick($iface['interface_type'],'network') %>'>
<%- if 'mac' in $iface { -%>
<mac address='<%= $iface['mac'] %>'/>
<%- } -%>
Expand All @@ -22,7 +22,11 @@
</filterref>
<%- } -%>
<%- } -%>
<source network='<%= $iface['network'] %>'<% if 'portgroup' in $iface { %> portgroup='<%= $iface['portgroup'] %>'<% } %>/>
<%- if $iface['source'] { -%>
<source <% $iface['source'].each |String $k, String $v| { %><%= $k %>='<%= $v %>' <% } %>/>
<%- } elsif $iface['network'] { %><%# deprecated, do not use use source above -%>
<source <%= pick($iface['interface_type'],'network') %>='<%= $iface['network'] %>'<% if 'portgroup' in $iface { %> portgroup='<%= $iface['portgroup'] %>'<% } %>/>
<%- } -%>
<model type='<% if 'type' in $iface { %><%= $iface['type'] %><% }else{ %>virtio<% } %>'/>
<%- if $boot == 'per-device' and 'boot_order' in $iface { -%>
<boot order='<%= $iface['boot_order'] %>'/>
Expand Down
14 changes: 8 additions & 6 deletions types/domain/interface.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# A interface of a Domain
type Libvirt::Domain::Interface = Struct[{
type => Optional[String[1]],
network => String[1],
portgroup => Optional[String[1]],
mac => Optional[String[1]],
filter => Optional[Variant[
type => Optional[String[1]],
interface_type => Optional[Enum['network','bridge', 'vdpa', 'mcast', 'server', 'client', 'null', 'vds']],
network => Optional[String[1]], # deprecated, do not use
source => Optional[Hash[String[1],String[1]]],
portgroup => Optional[String[1]], # deprecated, do not use, use source hash instead
mac => Optional[String[1]],
filter => Optional[Variant[
String[1],
Struct[{
filterref => String[1],
Expand All @@ -14,5 +16,5 @@
]],
}],
]],
boot_order => Optional[Integer],
boot_order => Optional[Integer],
}]

0 comments on commit 4199668

Please sign in to comment.