Blame SOURCES/0024-host-Introduce-ovirt_host_get_cluster.patch

546e1e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
546e1e
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
546e1e
Date: Thu, 13 Jul 2017 17:44:13 -0300
546e1e
Subject: [PATCH] host: Introduce ovirt_host_get_cluster()
546e1e
546e1e
Following the same principle as previous commits, this functions can be
546e1e
used to retrieve the cluster that includes this host.
546e1e
546e1e
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
546e1e
---
546e1e
 govirt/govirt.sym   |  1 +
546e1e
 govirt/ovirt-host.c | 35 ++++++++++++++++++++++++++++++++++-
546e1e
 govirt/ovirt-host.h |  1 +
546e1e
 3 files changed, 36 insertions(+), 1 deletion(-)
546e1e
546e1e
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
546e1e
index bbfbd79..243ce0b 100644
546e1e
--- a/govirt/govirt.sym
546e1e
+++ b/govirt/govirt.sym
546e1e
@@ -130,6 +130,7 @@ GOVIRT_0.3.2 {
546e1e
         ovirt_data_center_get_type;
546e1e
         ovirt_data_center_new;
546e1e
 
546e1e
+        ovirt_host_get_cluster;
546e1e
         ovirt_host_get_type;
546e1e
         ovirt_host_get_vms;
546e1e
         ovirt_host_new;
546e1e
diff --git a/govirt/ovirt-host.c b/govirt/ovirt-host.c
546e1e
index 2df2a64..191b360 100644
546e1e
--- a/govirt/ovirt-host.c
546e1e
+++ b/govirt/ovirt-host.c
546e1e
@@ -42,6 +42,19 @@ enum {
546e1e
     PROP_CLUSTER_ID,
546e1e
 };
546e1e
 
546e1e
+
546e1e
+static const char *get_cluster_href(OvirtHost *host)
546e1e
+{
546e1e
+    if (host->priv->cluster_href == NULL &&
546e1e
+        host->priv->cluster_id != NULL) {
546e1e
+        host->priv->cluster_href = g_strdup_printf("%s/%s",
546e1e
+                                                   "/ovirt-engine/api/clusters",
546e1e
+                                                   host->priv->cluster_id);
546e1e
+    }
546e1e
+
546e1e
+    return host->priv->cluster_href;
546e1e
+}
546e1e
+
546e1e
 static void ovirt_host_get_property(GObject *object,
546e1e
                                     guint prop_id,
546e1e
                                     GValue *value,
546e1e
@@ -51,7 +64,7 @@ static void ovirt_host_get_property(GObject *object,
546e1e
 
546e1e
     switch (prop_id) {
546e1e
     case PROP_CLUSTER_HREF:
546e1e
-        g_value_set_string(value, host->priv->cluster_href);
546e1e
+        g_value_set_string(value, get_cluster_href(host));
546e1e
         break;
546e1e
     case PROP_CLUSTER_ID:
546e1e
         g_value_set_string(value, host->priv->cluster_id);
546e1e
@@ -212,3 +225,23 @@ OvirtCollection *ovirt_host_get_vms(OvirtHost *host)
546e1e
 
546e1e
     return host->priv->vms;
546e1e
 }
546e1e
+
546e1e
+
546e1e
+/**
546e1e
+ * ovirt_host_get_cluster:
546e1e
+ * @host: a #OvirtHost
546e1e
+ *
546e1e
+ * Gets a #OvirtCluster representing the cluster the host belongs
546e1e
+ * to. This method does not initiate any network activity, the remote host must
546e1e
+ * be then be fetched using ovirt_resource_refresh() or
546e1e
+ * ovirt_resource_refresh_async().
546e1e
+ *
546e1e
+ * Return value: (transfer full): a #OvirtCluster representing cluster the @host
546e1e
+ * belongs to.
546e1e
+ */
546e1e
+OvirtCluster *ovirt_host_get_cluster(OvirtHost *host)
546e1e
+{
546e1e
+    g_return_val_if_fail(OVIRT_IS_HOST(host), NULL);
546e1e
+    g_return_val_if_fail(host->priv->cluster_id != NULL, NULL);
546e1e
+    return ovirt_cluster_new_from_id(host->priv->cluster_id, get_cluster_href(host));
546e1e
+}
546e1e
diff --git a/govirt/ovirt-host.h b/govirt/ovirt-host.h
546e1e
index 91441f6..cdf702c 100644
546e1e
--- a/govirt/ovirt-host.h
546e1e
+++ b/govirt/ovirt-host.h
546e1e
@@ -60,6 +60,7 @@ GType ovirt_host_get_type(void);
546e1e
 
546e1e
 OvirtHost *ovirt_host_new(void);
546e1e
 OvirtCollection *ovirt_host_get_vms(OvirtHost *host);
546e1e
+OvirtCluster *ovirt_host_get_cluster(OvirtHost *host);
546e1e
 
546e1e
 G_END_DECLS
546e1e