[gnome-boxes] util: API to detect if libvirt bridge net is available



commit 197d53b7892f057e8d674f6a7c3d067545cf71fa
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Jan 11 18:10:06 2013 +0200

    util: API to detect if libvirt bridge net is available
    
    We do this by checking if:
    
    * System libvirtd is running
    * Qemu is allowed to run a helper to access bridge net.
      WARNING: We only look at a hardcoded path currently so it will fail for
      qemu installed in custom prefix.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677688

 src/util-app.vala |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/util-app.vala b/src/util-app.vala
index f4392e3..616442d 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -237,6 +237,34 @@ namespace Boxes {
         return pool.get_volume (domain.get_name ());
     }
 
+    private static bool libvirt_bridge_net_checked = false;
+    private static bool libvirt_bridge_net_available = false;
+
+    public bool is_libvirt_bridge_net_available () {
+        if (libvirt_bridge_net_checked)
+            return libvirt_bridge_net_available;
+
+        var connection = new GVir.Connection ("qemu:///system");
+
+        try {
+            connection.open_read_only ();
+
+            var file = File.new_for_path ("/etc/qemu/bridge.conf");
+            uint8[] contents;
+            file.load_contents (null, out contents, null);
+
+            libvirt_bridge_net_available = (Regex.match_simple ("^allow.*virbr0", (string) contents));
+        } catch (GLib.Error error) {
+            debug ("%s", error.message);
+
+            libvirt_bridge_net_available = false;
+        }
+
+        libvirt_bridge_net_checked = true;
+
+        return libvirt_bridge_net_available;
+    }
+
     private string? get_logo_path (Osinfo.Os os, string[] extensions = {".svg", ".png", ".jpg"}) {
         if (extensions.length == 0)
             return null;


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