From 419966855f052c3575f7f526fd9f2bf3e1d28725 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Wed, 12 Feb 2025 18:43:32 +0100 Subject: [PATCH] add additional network interface types for domain definition 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. --- manifests/domain.pp | 25 +++++++++++++++++-------- templates/domain/device_interface.epp | 8 ++++++-- types/domain/interface.pp | 14 ++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/manifests/domain.pp b/manifests/domain.pp index e9511cb..390d37b 100644 --- a/manifests/domain.pp +++ b/manifests/domain.pp @@ -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. diff --git a/templates/domain/device_interface.epp b/templates/domain/device_interface.epp index 8aabb7d..b30178d 100644 --- a/templates/domain/device_interface.epp +++ b/templates/domain/device_interface.epp @@ -1,7 +1,7 @@ <%- | Libvirt::Domain::Interface $iface, String $boot, | -%> - + '> <%- if 'mac' in $iface { -%> '/> <%- } -%> @@ -22,7 +22,11 @@ <%- } -%> <%- } -%> - '<% if 'portgroup' in $iface { %> portgroup='<%= $iface['portgroup'] %>'<% } %>/> +<%- if $iface['source'] { -%> + <%= $k %>='<%= $v %>' <% } %>/> +<%- } elsif $iface['network'] { %><%# deprecated, do not use use source above -%> + ='<%= $iface['network'] %>'<% if 'portgroup' in $iface { %> portgroup='<%= $iface['portgroup'] %>'<% } %>/> +<%- } -%> <%= $iface['type'] %><% }else{ %>virtio<% } %>'/> <%- if $boot == 'per-device' and 'boot_order' in $iface { -%> '/> diff --git a/types/domain/interface.pp b/types/domain/interface.pp index 5780667..5ea3822 100644 --- a/types/domain/interface.pp +++ b/types/domain/interface.pp @@ -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], @@ -14,5 +16,5 @@ ]], }], ]], - boot_order => Optional[Integer], + boot_order => Optional[Integer], }]