[gnome-boxes] installer: Use bridge net if system libvirt is available



commit 414d32419f3d68685fefa824b84f718334da7215
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Jan 3 05:51:02 2013 +0200

    installer: Use bridge net if system libvirt is available
    
    Use bridge networking in new VMs, if available. This network is much
    faster than the user networking.
    
    Unfortunately bridge networking being available implies running system
    libvirtd. However since system libvirtd is typically started on boot when
    libvirt is installed, we can perhaps rely on it being available at
    subsequent launch of the created VM in future?
    
    NB: We don't need to actually connect to system libvirt for this to work.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677688

 src/vm-configurator.vala |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 05b560a..5b5fcba 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -105,10 +105,7 @@ private class Boxes.VMConfigurator {
         console.set_source (new DomainChardevSourcePty ());
         domain.add_device (console);
 
-        var iface = new DomainInterfaceUser ();
-        if (install_media.supports_virtio_net)
-            iface.set_model ("virtio");
-        domain.add_device (iface);
+        add_network_interface (domain, is_libvirt_bridge_net_available (), 
install_media.supports_virtio_net);
 
         return domain;
     }
@@ -400,6 +397,25 @@ private class Boxes.VMConfigurator {
         domain.add_device (controller);
     }
 
+    public static void add_network_interface (Domain domain, bool bridge, bool virtio) {
+        DomainInterface iface;
+
+        if (bridge) {
+            debug ("Adding bridge network to %s", domain.get_name ());
+            var bridge_iface = new DomainInterfaceBridge ();
+            bridge_iface.set_source ("virbr0");
+            iface = bridge_iface;
+        } else {
+            debug ("Adding user network to %s", domain.get_name ());
+            iface = new DomainInterfaceUser ();
+        }
+
+        if (virtio)
+            iface.set_model ("virtio");
+
+        domain.add_device (iface);
+    }
+
     private static DomainControllerUsb create_usb_controller (DomainControllerUsbModel model,
                                                               DomainControllerUsb?     master = null,
                                                               uint                     index = 0,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]