[gnome-boxes] ovirt: Implement OvirtMachine
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] ovirt: Implement OvirtMachine
- Date: Fri, 15 Feb 2013 17:14:07 +0000 (UTC)
commit 8413cf33dd67c1d5ef23cad3b4452794d999bf37
Author: Christophe Fergeau <cfergeau redhat com>
Date: Fri Jul 20 23:48:06 2012 +0200
ovirt: Implement OvirtMachine
This is used to control oVirt VMs.
This raises the minimum spice-gtk dependency to be able to make
use of SpiceSession::ca
https://bugzilla.gnome.org/show_bug.cgi?id=681747
configure.ac | 2 +-
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
src/Makefile.am | 2 +-
src/ovirt-broker.vala | 14 ++++++
src/ovirt-machine.vala | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
src/spice-display.vala | 1 +
7 files changed, 123 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 64a73d6..d750f22 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,7 @@ GTK_VNC_MIN_VERSION=0.4.4
LIBVIRT_GLIB_MIN_VERSION=0.1.5
LIBVIRT_GCONFIG_MIN_VERSION=0.1.5
LIBXML2_MIN_VERSION=2.7.8
-SPICE_GTK_MIN_VERSION=0.12.101
+SPICE_GTK_MIN_VERSION=0.15
GUDEV_MIN_VERSION=165
OSINFO_MIN_VERSION=0.2.3
TRACKER_SPARQL=0.13.1
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 492fdcd..cde48dc 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ src/machine.vala
src/main.vala
src/notificationbar.vala
src/ovirt-broker.vala
+src/ovirt-machine.vala
src/properties.vala
src/remote-machine.vala
src/selectionbar.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 5d79bbd..fe17fec 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -12,6 +12,7 @@ src/main.c
src/media-manager.c
src/notificationbar.c
src/ovirt-broker.c
+src/ovirt-machine.c
src/properties.c
src/remote-machine.c
src/selectionbar.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 7c914d0..3c6d140 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -130,7 +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_SOURCES += ovirt-broker.vala ovirt-machine.vala
gnome_boxes_LDADD += $(OVIRT_LIBS)
gnome_boxes_CFLAGS += $(OVIRT_CFLAGS)
endif
diff --git a/src/ovirt-broker.vala b/src/ovirt-broker.vala
index 0e3223e..ed58dad 100644
--- a/src/ovirt-broker.vala
+++ b/src/ovirt-broker.vala
@@ -16,6 +16,15 @@ private class Boxes.OvirtBroker : Boxes.Broker {
proxies = new HashTable<string, Ovirt.Proxy> (str_hash, str_equal);
}
+ private void add_vm (CollectionSource source, Ovirt.Proxy proxy, Ovirt.Vm vm) {
+ try {
+ var machine = new OvirtMachine (source, proxy, vm);
+ App.app.collection.add_item (machine);
+ } catch (GLib.Error error) {
+ warning ("Failed to create source '%s': %s", source.name, error.message);
+ }
+ }
+
public override async void add_source (CollectionSource source) {
if (proxies.lookup (source.name) != null)
return;
@@ -33,11 +42,16 @@ private class Boxes.OvirtBroker : Boxes.Broker {
var proxy = new Ovirt.Proxy (uri.save ());
try {
+ yield proxy.fetch_ca_certificate_async (null);
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);
+
+ foreach (var vm in proxy.get_vms ()) {
+ add_vm (source, proxy, vm);
+ }
}
}
diff --git a/src/ovirt-machine.vala b/src/ovirt-machine.vala
new file mode 100644
index 0000000..c906348
--- /dev/null
+++ b/src/ovirt-machine.vala
@@ -0,0 +1,104 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Ovirt;
+using Gtk;
+
+private class Boxes.OvirtMachine: Boxes.Machine {
+ private Ovirt.Vm vm;
+ private Ovirt.Proxy proxy;
+
+ public OvirtMachine (CollectionSource source,
+ Ovirt.Proxy proxy,
+ Ovirt.Vm vm) throws GLib.Error {
+ base (source, vm.name);
+
+ debug ("New ovirt machine: " + name);
+ create_display_config (vm.uuid);
+ this.proxy = proxy;
+ this.vm = vm;
+
+ this.update_state ();
+
+ load_screenshot ();
+ set_screenshot_enable (false);
+ }
+
+ public override async void connect_display () throws GLib.Error {
+ if (display != null)
+ return;
+
+ if (state == MachineState.STOPPED)
+ try {
+ yield vm.start_async (proxy, null);
+ this.update_state ();
+ } catch (GLib.Error error) {
+ throw new Boxes.Error.INVALID ("Couldn't start oVirt VM '%s': %s", vm.name, error.message);
+ }
+
+ if (state != MachineState.RUNNING)
+ throw new Boxes.Error.INVALID ("oVirt VM '%s' is not RUNNING", vm.name);
+
+ try {
+ display = create_display_connection ();
+ if (vm.display.type == Ovirt.VmDisplayType.SPICE) {
+ yield vm.get_ticket_async (proxy, null);
+ display.password = vm.display.ticket;
+ }
+
+ display.connect_it ();
+ } catch (GLib.Error e) {
+ throw new Boxes.Error.INVALID ("Error opening display: %s", e.message);
+ }
+ }
+
+ public override List<Boxes.Property> get_properties (Boxes.PropertiesPage page, PropertyCreationFlag
flags) {
+ var list = new List<Boxes.Property> ();
+
+ switch (page) {
+ case PropertiesPage.LOGIN:
+ add_string_property (ref list, _("Virtualizer"), source.uri);
+ add_string_property (ref list, _("URI"), display.uri);
+ break;
+
+ case PropertiesPage.DISPLAY:
+ add_string_property (ref list, _("Protocol"), display.protocol);
+ break;
+ }
+
+ list.concat (display.get_properties (page, flags));
+
+ return list;
+ }
+
+ private Display create_display_connection () throws GLib.Error {
+ if (vm.display.address == null || vm.display.address == "")
+ throw new Boxes.Error.INVALID ("empty display address for %s", vm.name);
+
+ switch (vm.display.type) {
+ case Ovirt.VmDisplayType.SPICE:
+ var display = new SpiceDisplay (config, vm.display.address, (int)vm.display.port,
(int)vm.display.secure_port);
+ display.ca_cert = proxy.ca_cert;
+ return display;
+
+ case Ovirt.VmDisplayType.VNC:
+ return new VncDisplay (config, vm.display.address, (int)vm.display.port);
+
+ default:
+ warning ("unsupported display of type %d", vm.display.type);
+ throw new Boxes.Error.INVALID ("unsupported display type %d for %s", vm.display.type, vm.name);
+ }
+ }
+ private void update_state () {
+ switch (vm.state) {
+ case VmState.UP:
+ state = MachineState.RUNNING;
+ break;
+ case VmState.DOWN:
+ state = MachineState.STOPPED;
+ break;
+ default:
+ state = MachineState.UNKNOWN;
+ break;
+ }
+ }
+
+}
diff --git a/src/spice-display.vala b/src/spice-display.vala
index ad55b8e..048f246 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -5,6 +5,7 @@ using Spice;
private class Boxes.SpiceDisplay: Boxes.Display {
public override string protocol { get { return "SPICE"; } }
public override string uri { owned get { return session.uri; } }
+ public GLib.ByteArray ca_cert { owned get { return session.ca; } set { session.ca = value; } }
private Spice.Session session;
private unowned Spice.GtkSession gtk_session;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]