Merge "Auto repair libvirt's vnet interfaces"
diff --git a/README.rst b/README.rst
index c32a444..3832eac 100644
--- a/README.rst
+++ b/README.rst
@@ -1962,6 +1962,14 @@
network:
tap_custom_txqueuelen: 10000
+Auto repair/re-attach libvirt's vnet interfaces:
+
+.. code-block:: yaml
+
+ linux:
+ network:
+ libvirt_vnet_repair: true
+
DPDK OVS interfaces
**DPDK OVS NIC**
diff --git a/linux/files/libvirt_vnet_repair.sh b/linux/files/libvirt_vnet_repair.sh
new file mode 100644
index 0000000..0294aac
--- /dev/null
+++ b/linux/files/libvirt_vnet_repair.sh
@@ -0,0 +1,14 @@
+#!/bin/bash -e
+
+for id in $(virsh list --uuid); do
+ IFS=$'\n'
+ for _vnet in $(virsh domiflist "$id" | tail -n+3); do
+ IFS=' '
+ vnet=($_vnet)
+
+ if ! brctl show "${vnet[2]}" | grep -qFw "${vnet[0]}"; then
+ virsh detach-interface "$id" "${vnet[1]}" --mac "${vnet[4]}"
+ virsh attach-interface "$id" "${vnet[1]}" "${vnet[2]}" --model "${vnet[3]}" --mac "${vnet[4]}"
+ fi
+ done
+done
diff --git a/linux/network/interface.sls b/linux/network/interface.sls
index e825d4d..4a1b0b2 100644
--- a/linux/network/interface.sls
+++ b/linux/network/interface.sls
@@ -524,3 +524,12 @@
- udev_reload_rules
{%- endif %}
+
+{%- if network.libvirt_vnet_repair|d(false) %}
+/usr/local/bin/libvirt_vnet_repair:
+ file.managed:
+ - source: salt://linux/files/libvirt_vnet_repair.sh
+ - mode: 755
+ cmd.run:
+ - output_loglevel: debug
+{%- endif %}