This only works in libvirt >= 1.3.0.  See:
https://bugzilla.redhat.com/show_bug.cgi?id=1075520

Thanks: Michal Privoznik
---
 src/launch-libvirt.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 7653bf9..87ad21a 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -1210,6 +1210,20 @@ construct_libvirt_xml_devices (guestfs_h *g,
       } end_element ();
     } end_element ();
 
+    /* User network using libvirt >= 1.3.0. */
+    if (params->data->version >= 1003000 && g->enable_network) {
+      start_element ("interface") {
+        attribute ("type", "user");
+        start_element ("ip") {
+          attribute ("address", "169.254.0.0");
+          attribute ("prefix", "16");
+        } end_element ();
+        start_element ("model") {
+          attribute ("type", VIRTIO_NET);
+        } end_element ();
+      } end_element ();
+    }
+
   } end_element (); /* </devices> */
 
   return 0;
@@ -1588,10 +1602,11 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
       attribute ("value", tmpdir);
     } end_element ();
 
-    /* Workaround because libvirt user networking cannot specify "net="
-     * parameter.
+    /* Workaround because libvirt user networking cannot specify
+     * "net=" parameter.  We can remove this when the min required
+     * libvirt version is >= 1.3.0.
      */
-    if (g->enable_network) {
+    if (params->data->version < 1003000 && g->enable_network) {
       start_element ("qemu:arg") {
         attribute ("value", "-netdev");
       } end_element ();
-- 
1.8.5.3

_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to