Blame SOURCES/0048-ovirt-foreign-menu-Fetch-host-cluster-and-data-cente.patch

48c875
From 1ae320d801440c6d7a052013b88031e06d7836d5 Mon Sep 17 00:00:00 2001
48c875
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
48c875
Date: Thu, 3 Aug 2017 18:48:25 -0300
48c875
Subject: [PATCH] ovirt-foreign-menu: Fetch host, cluster and data center
48c875
 information
48c875
48c875
It is possible that the data center the VM is associated with has more
48c875
than one storage domain associated with it as well, when only one is
48c875
active while the others are not.
48c875
48c875
The current ovir-foreign-menu code does not take it into consideration,
48c875
thus the ISO dialog may show invalid results with that scenario. We fix
48c875
this problem by making use of new functions in libgovirt, adding support
48c875
or hosts, clusters and data centers.
48c875
48c875
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1427467
48c875
         https://bugzilla.redhat.com/show_bug.cgi?id=1428401
48c875
48c875
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
48c875
---
48c875
 src/ovirt-foreign-menu.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++
48c875
 1 file changed, 154 insertions(+)
48c875
48c875
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
48c875
index 6d0eab3..bf32773 100644
48c875
--- a/src/ovirt-foreign-menu.c
48c875
+++ b/src/ovirt-foreign-menu.c
48c875
@@ -34,6 +34,11 @@ typedef enum {
48c875
     STATE_0,
48c875
     STATE_API,
48c875
     STATE_VM,
48c875
+#ifdef HAVE_OVIRT_DATA_CENTER
48c875
+    STATE_HOST,
48c875
+    STATE_CLUSTER,
48c875
+    STATE_DATA_CENTER,
48c875
+#endif
48c875
     STATE_STORAGE_DOMAIN,
48c875
     STATE_VM_CDROM,
48c875
     STATE_CDROM_FILE,
48c875
@@ -43,6 +48,11 @@ typedef enum {
48c875
 static void ovirt_foreign_menu_next_async_step(OvirtForeignMenu *menu, GTask *task, OvirtForeignMenuState state);
48c875
 static void ovirt_foreign_menu_fetch_api_async(OvirtForeignMenu *menu, GTask *task);
48c875
 static void ovirt_foreign_menu_fetch_vm_async(OvirtForeignMenu *menu, GTask *task);
48c875
+#ifdef HAVE_OVIRT_DATA_CENTER
48c875
+static void ovirt_foreign_menu_fetch_host_async(OvirtForeignMenu *menu, GTask *task);
48c875
+static void ovirt_foreign_menu_fetch_cluster_async(OvirtForeignMenu *menu, GTask *task);
48c875
+static void ovirt_foreign_menu_fetch_data_center_async(OvirtForeignMenu *menu, GTask *task);
48c875
+#endif
48c875
 static void ovirt_foreign_menu_fetch_storage_domain_async(OvirtForeignMenu *menu, GTask *task);
48c875
 static void ovirt_foreign_menu_fetch_vm_cdrom_async(OvirtForeignMenu *menu, GTask *task);
48c875
 static void ovirt_foreign_menu_refresh_cdrom_file_async(OvirtForeignMenu *menu, GTask *task);
48c875
@@ -55,6 +65,11 @@ struct _OvirtForeignMenuPrivate {
48c875
     OvirtProxy *proxy;
48c875
     OvirtApi *api;
48c875
     OvirtVm *vm;
48c875
+#ifdef HAVE_OVIRT_DATA_CENTER
48c875
+    OvirtHost *host;
48c875
+    OvirtCluster *cluster;
48c875
+    OvirtDataCenter *data_center;
48c875
+#endif
48c875
     char *vm_guid;
48c875
 
48c875
     OvirtCollection *files;
48c875
@@ -184,6 +199,11 @@ ovirt_foreign_menu_dispose(GObject *obj)
48c875
     g_clear_object(&self->priv->proxy);
48c875
     g_clear_object(&self->priv->api);
48c875
     g_clear_object(&self->priv->vm);
48c875
+#ifdef HAVE_OVIRT_DATA_CENTER
48c875
+    g_clear_object(&self->priv->host);
48c875
+    g_clear_object(&self->priv->cluster);
48c875
+    g_clear_object(&self->priv->data_center);
48c875
+#endif
48c875
     g_clear_pointer(&self->priv->vm_guid, g_free);
48c875
     g_clear_object(&self->priv->files);
48c875
     g_clear_object(&self->priv->cdrom);
48c875
@@ -299,6 +319,27 @@ ovirt_foreign_menu_next_async_step(OvirtForeignMenu *menu,
48c875
             ovirt_foreign_menu_fetch_vm_async(menu, task);
48c875
             break;
48c875
         }
48c875
+#ifdef HAVE_OVIRT_DATA_CENTER
48c875
+        /* fall through */
48c875
+    case STATE_HOST:
48c875
+        if (menu->priv->host == NULL) {
48c875
+            ovirt_foreign_menu_fetch_host_async(menu, task);
48c875
+            break;
48c875
+        }
48c875
+        /* fall through */
48c875
+    case STATE_CLUSTER:
48c875
+        if (menu->priv->cluster == NULL) {
48c875
+            ovirt_foreign_menu_fetch_cluster_async(menu, task);
48c875
+            break;
48c875
+        }
48c875
+        /* fall through */
48c875
+    case STATE_DATA_CENTER:
48c875
+        if (menu->priv->data_center == NULL) {
48c875
+            ovirt_foreign_menu_fetch_data_center_async(menu, task);
48c875
+            break;
48c875
+        }
48c875
+#endif
48c875
+        /* fall through */
48c875
     case STATE_STORAGE_DOMAIN:
48c875
         if (menu->priv->files == NULL) {
48c875
             ovirt_foreign_menu_fetch_storage_domain_async(menu, task);
48c875
@@ -646,6 +687,119 @@ static void ovirt_foreign_menu_fetch_storage_domain_async(OvirtForeignMenu *menu
48c875
 }
48c875
 
48c875
 
48c875
+#ifdef HAVE_OVIRT_DATA_CENTER
48c875
+static void data_center_fetched_cb(GObject *source_object,
48c875
+                                   GAsyncResult *result,
48c875
+                                   gpointer user_data)
48c875
+{
48c875
+    GError *error = NULL;
48c875
+    GTask *task = G_TASK(user_data);
48c875
+    OvirtForeignMenu *menu = OVIRT_FOREIGN_MENU(g_task_get_source_object(task));
48c875
+    OvirtResource *resource = OVIRT_RESOURCE(source_object);
48c875
+
48c875
+    ovirt_resource_refresh_finish(resource, result, &error);
48c875
+    if (error != NULL) {
48c875
+        g_debug("failed to fetch Data Center: %s", error->message);
48c875
+        g_task_return_error(task, error);
48c875
+        g_object_unref(task);
48c875
+        return;
48c875
+    }
48c875
+
48c875
+    ovirt_foreign_menu_next_async_step(menu, task, STATE_DATA_CENTER);
48c875
+}
48c875
+
48c875
+
48c875
+static void ovirt_foreign_menu_fetch_data_center_async(OvirtForeignMenu *menu,
48c875
+                                                       GTask *task)
48c875
+{
48c875
+    g_return_if_fail(OVIRT_IS_FOREIGN_MENU(menu));
48c875
+    g_return_if_fail(OVIRT_IS_PROXY(menu->priv->proxy));
48c875
+    g_return_if_fail(OVIRT_IS_CLUSTER(menu->priv->cluster));
48c875
+
48c875
+    menu->priv->data_center = ovirt_cluster_get_data_center(menu->priv->cluster);
48c875
+    ovirt_resource_refresh_async(OVIRT_RESOURCE(menu->priv->data_center),
48c875
+                                 menu->priv->proxy,
48c875
+                                 g_task_get_cancellable(task),
48c875
+                                 data_center_fetched_cb,
48c875
+                                 task);
48c875
+}
48c875
+
48c875
+
48c875
+static void cluster_fetched_cb(GObject *source_object,
48c875
+                               GAsyncResult *result,
48c875
+                               gpointer user_data)
48c875
+{
48c875
+    GError *error = NULL;
48c875
+    GTask *task = G_TASK(user_data);
48c875
+    OvirtForeignMenu *menu = OVIRT_FOREIGN_MENU(g_task_get_source_object(task));
48c875
+    OvirtResource *resource = OVIRT_RESOURCE(source_object);
48c875
+
48c875
+    ovirt_resource_refresh_finish(resource, result, &error);
48c875
+    if (error != NULL) {
48c875
+        g_debug("failed to fetch Cluster: %s", error->message);
48c875
+        g_task_return_error(task, error);
48c875
+        g_object_unref(task);
48c875
+        return;
48c875
+    }
48c875
+
48c875
+    ovirt_foreign_menu_next_async_step(menu, task, STATE_CLUSTER);
48c875
+}
48c875
+
48c875
+
48c875
+static void ovirt_foreign_menu_fetch_cluster_async(OvirtForeignMenu *menu,
48c875
+                                                   GTask *task)
48c875
+{
48c875
+    g_return_if_fail(OVIRT_IS_FOREIGN_MENU(menu));
48c875
+    g_return_if_fail(OVIRT_IS_PROXY(menu->priv->proxy));
48c875
+    g_return_if_fail(OVIRT_IS_HOST(menu->priv->host));
48c875
+
48c875
+    menu->priv->cluster = ovirt_host_get_cluster(menu->priv->host);
48c875
+    ovirt_resource_refresh_async(OVIRT_RESOURCE(menu->priv->cluster),
48c875
+                                 menu->priv->proxy,
48c875
+                                 g_task_get_cancellable(task),
48c875
+                                 cluster_fetched_cb,
48c875
+                                 task);
48c875
+}
48c875
+
48c875
+
48c875
+static void host_fetched_cb(GObject *source_object,
48c875
+                            GAsyncResult *result,
48c875
+                            gpointer user_data)
48c875
+{
48c875
+    GError *error = NULL;
48c875
+    GTask *task = G_TASK(user_data);
48c875
+    OvirtForeignMenu *menu = OVIRT_FOREIGN_MENU(g_task_get_source_object(task));
48c875
+    OvirtResource *resource = OVIRT_RESOURCE(source_object);
48c875
+
48c875
+    ovirt_resource_refresh_finish(resource, result, &error);
48c875
+    if (error != NULL) {
48c875
+        g_debug("failed to fetch Host: %s", error->message);
48c875
+        g_task_return_error(task, error);
48c875
+        g_object_unref(task);
48c875
+        return;
48c875
+    }
48c875
+
48c875
+    ovirt_foreign_menu_next_async_step(menu, task, STATE_HOST);
48c875
+}
48c875
+
48c875
+
48c875
+static void ovirt_foreign_menu_fetch_host_async(OvirtForeignMenu *menu,
48c875
+                                                GTask *task)
48c875
+{
48c875
+    g_return_if_fail(OVIRT_IS_FOREIGN_MENU(menu));
48c875
+    g_return_if_fail(OVIRT_IS_PROXY(menu->priv->proxy));
48c875
+    g_return_if_fail(OVIRT_IS_VM(menu->priv->vm));
48c875
+
48c875
+    menu->priv->host = ovirt_vm_get_host(menu->priv->vm);
48c875
+    ovirt_resource_refresh_async(OVIRT_RESOURCE(menu->priv->host),
48c875
+                                 menu->priv->proxy,
48c875
+                                 g_task_get_cancellable(task),
48c875
+                                 host_fetched_cb,
48c875
+                                 task);
48c875
+}
48c875
+#endif /* HAVE_OVIRT_DATA_CENTER */
48c875
+
48c875
+
48c875
 static void vms_fetched_cb(GObject *source_object,
48c875
                            GAsyncResult *result,
48c875
                            gpointer user_data)
48c875
-- 
48c875
2.13.6
48c875