[gnome-boxes] ovirt: Add oVirt broker



commit 0ac4e22d9a7aebfdf53d7c338f0c2def0ddfe8e5
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Mon Sep 3 15:04:29 2012 +0200

    ovirt: Add oVirt broker
    
    For now, the broker isn't doing much, but more will be added in
    later commits
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681747

 configure.ac          |    3 +--
 po/POTFILES.in        |    1 +
 po/POTFILES.skip      |    1 +
 src/Makefile.am       |    1 +
 src/app.vala          |    2 ++
 src/ovirt-broker.vala |   43 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2524dd2..64a73d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,7 +55,6 @@ LIBXML2_MIN_VERSION=2.7.8
 SPICE_GTK_MIN_VERSION=0.12.101
 GUDEV_MIN_VERSION=165
 OSINFO_MIN_VERSION=0.2.3
-REST_MIN_VERSION=0.7.90
 TRACKER_SPARQL=0.13.1
 UUID_REQUIRED=1.41.3
 LIBSOUP_REQUIRED=2.38
@@ -94,7 +93,7 @@ VALA_ADD_CHECKFILE([src/gnome_boxes_search_provider_vala.stamp])
 
 VALA_ADD_CHECKFILE([libgd/gd-1.0.vapi])
 
-PKG_CHECK_MODULES(OVIRT, [govirt-1.0 >= $GOVIRT_MIN_VERSION rest-0.7 >= $REST_MIN_VERSION],
+PKG_CHECK_MODULES(OVIRT, [govirt-1.0 >= $GOVIRT_MIN_VERSION],
                   [have_govirt=yes], [have_govirt=no])
 if test "x$have_govirt" = "xyes"; then
   AC_DEFINE([HAVE_OVIRT], [1], [Build with oVirt support?])
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8efeb4d..492fdcd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,6 +11,7 @@ src/libvirt-machine.vala
 src/machine.vala
 src/main.vala
 src/notificationbar.vala
+src/ovirt-broker.vala
 src/properties.vala
 src/remote-machine.vala
 src/selectionbar.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index e78722d..5d79bbd 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -11,6 +11,7 @@ src/machine.c
 src/main.c
 src/media-manager.c
 src/notificationbar.c
+src/ovirt-broker.c
 src/properties.c
 src/remote-machine.c
 src/selectionbar.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 502607f..7c914d0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -130,6 +130,7 @@ $(srcdir)/gnome_boxes_vala.stamp: $(libcommon_a_DEPENDENCIES)
 
 AM_VALAFLAGS += --pkg govirt-1.0 --pkg rest-0.7
 if HAVE_OVIRT
+gnome_boxes_SOURCES += ovirt-broker.vala
 gnome_boxes_LDADD += $(OVIRT_LIBS)
 gnome_boxes_CFLAGS += $(OVIRT_CFLAGS)
 endif
diff --git a/src/app.vala b/src/app.vala
index 6d33caa..472f092 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -173,6 +173,8 @@ private class Boxes.App: Boxes.UI {
         });
 
         brokers.insert ("libvirt", LibvirtBroker.get_default ());
+        if (Config.HAVE_OVIRT)
+            brokers.insert ("ovirt", OvirtBroker.get_default ());
 
         setup_sources.begin ((obj, result) => {
             setup_sources.end (result);
diff --git a/src/ovirt-broker.vala b/src/ovirt-broker.vala
new file mode 100644
index 0000000..0e3223e
--- /dev/null
+++ b/src/ovirt-broker.vala
@@ -0,0 +1,43 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Ovirt;
+
+private class Boxes.OvirtBroker : Boxes.Broker {
+    private static OvirtBroker broker;
+    private HashTable<string,Ovirt.Proxy> proxies;
+
+    public static OvirtBroker get_default () {
+        if (broker == null)
+            broker = new OvirtBroker ();
+
+        return broker;
+    }
+
+    private OvirtBroker () {
+        proxies = new HashTable<string, Ovirt.Proxy> (str_hash, str_equal);
+    }
+
+    public override async void add_source (CollectionSource source) {
+        if (proxies.lookup (source.name) != null)
+            return;
+
+        // turn ovirt://host/path into https://host/path/api which
+        // is where the REST API is reachable from
+        Xml.URI uri = Xml.URI.parse (source.uri);
+        return_if_fail (uri.scheme == "ovirt");
+        uri.scheme = "https";
+        if (uri.path == null)
+            uri.path= "/api";
+        else
+            uri.path = GLib.Path.build_filename (uri.path, "api");
+
+        var proxy = new Ovirt.Proxy (uri.save ());
+
+        try {
+            yield proxy.fetch_vms_async (null);
+        } catch (GLib.Error error) {
+            debug ("Failed to connect to broker: %s", error.message);
+            App.app.notificationbar.display_error (_("Connection to oVirt broker failed"));
+        }
+        proxies.insert (source.name, proxy);
+    }
+}



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