diff options
author | Eduardo Lima (Etrunko) <etrunko@redhat.com> | 2017-07-13 17:44:13 -0300 |
---|---|---|
committer | Eduardo Lima (Etrunko) <etrunko@redhat.com> | 2017-07-24 10:57:38 -0300 |
commit | b2c823fa672ecc7793df9fb745b590bee299a41c (patch) | |
tree | 7738db70b066579f72a2ae3f0c9bdce131e080bc | |
parent | 93937f8eaf52a37a0507ba404a741111b1660ce8 (diff) |
host: Introduce ovirt_host_get_cluster()
Following the same principle as previous commits, this functions can be
used to retrieve the cluster that includes this host.
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
-rw-r--r-- | govirt/govirt.sym | 1 | ||||
-rw-r--r-- | govirt/ovirt-host.c | 35 | ||||
-rw-r--r-- | govirt/ovirt-host.h | 1 |
3 files changed, 36 insertions, 1 deletions
diff --git a/govirt/govirt.sym b/govirt/govirt.sym index 66f334a..99774d9 100644 --- a/govirt/govirt.sym +++ b/govirt/govirt.sym @@ -132,6 +132,7 @@ GOVIRT_0.4.0 { ovirt_data_center_get_type; ovirt_data_center_new; + ovirt_host_get_cluster; ovirt_host_get_type; ovirt_host_get_vms; ovirt_host_new; diff --git a/govirt/ovirt-host.c b/govirt/ovirt-host.c index 2df2a64..191b360 100644 --- a/govirt/ovirt-host.c +++ b/govirt/ovirt-host.c @@ -42,6 +42,19 @@ enum { PROP_CLUSTER_ID, }; + +static const char *get_cluster_href(OvirtHost *host) +{ + if (host->priv->cluster_href == NULL && + host->priv->cluster_id != NULL) { + host->priv->cluster_href = g_strdup_printf("%s/%s", + "/ovirt-engine/api/clusters", + host->priv->cluster_id); + } + + return host->priv->cluster_href; +} + static void ovirt_host_get_property(GObject *object, guint prop_id, GValue *value, @@ -51,7 +64,7 @@ static void ovirt_host_get_property(GObject *object, switch (prop_id) { case PROP_CLUSTER_HREF: - g_value_set_string(value, host->priv->cluster_href); + g_value_set_string(value, get_cluster_href(host)); break; case PROP_CLUSTER_ID: g_value_set_string(value, host->priv->cluster_id); @@ -212,3 +225,23 @@ OvirtCollection *ovirt_host_get_vms(OvirtHost *host) return host->priv->vms; } + + +/** + * ovirt_host_get_cluster: + * @host: a #OvirtHost + * + * Gets a #OvirtCluster representing the cluster the host belongs + * to. This method does not initiate any network activity, the remote host must + * be then be fetched using ovirt_resource_refresh() or + * ovirt_resource_refresh_async(). + * + * Return value: (transfer full): a #OvirtCluster representing cluster the @host + * belongs to. + */ +OvirtCluster *ovirt_host_get_cluster(OvirtHost *host) +{ + g_return_val_if_fail(OVIRT_IS_HOST(host), NULL); + g_return_val_if_fail(host->priv->cluster_id != NULL, NULL); + return ovirt_cluster_new_from_id(host->priv->cluster_id, get_cluster_href(host)); +} diff --git a/govirt/ovirt-host.h b/govirt/ovirt-host.h index 91441f6..cdf702c 100644 --- a/govirt/ovirt-host.h +++ b/govirt/ovirt-host.h @@ -60,6 +60,7 @@ GType ovirt_host_get_type(void); OvirtHost *ovirt_host_new(void); OvirtCollection *ovirt_host_get_vms(OvirtHost *host); +OvirtCluster *ovirt_host_get_cluster(OvirtHost *host); G_END_DECLS |