[libgovirt] storage_domain: Add support for data_center tag



commit 998f42f85514854cad1889f19b4ce6fb96715e5b
Author: Eduardo Lima (Etrunko) <etrunko redhat com>
Date:   Tue Jan 21 10:03:27 2020 -0300

    storage_domain: Add support for data_center tag
    
    Similar to other resources which hold information about other objects
    they are related to.
    
    Signed-off-by: Eduardo Lima (Etrunko) <etrunko redhat com>

 govirt/ovirt-storage-domain.c | 66 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
---
diff --git a/govirt/ovirt-storage-domain.c b/govirt/ovirt-storage-domain.c
index f482f66..a713d89 100644
--- a/govirt/ovirt-storage-domain.c
+++ b/govirt/ovirt-storage-domain.c
@@ -29,6 +29,9 @@ struct _OvirtStorageDomainPrivate {
     OvirtCollection *files;
     GStrv data_center_ids;
 
+    gchar *data_center_href;
+    gchar *data_center_id;
+
     OvirtStorageDomainType type;
     gboolean is_master;
     guint64 available;
@@ -50,8 +53,27 @@ enum {
     PROP_VERSION,
     PROP_STATE,
     PROP_DATA_CENTER_IDS,
+    PROP_DATA_CENTER_HREF,
+    PROP_DATA_CENTER_ID,
 };
 
+static char *ensure_href_from_id(const char *id,
+                                 const char *path)
+{
+    if (id == NULL)
+        return NULL;
+
+    return g_strdup_printf("%s/%s", path, id);
+}
+
+static const char *get_data_center_href(OvirtStorageDomain *domain)
+{
+    if (domain->priv->data_center_href == NULL)
+        domain->priv->data_center_href = ensure_href_from_id(domain->priv->data_center_id, 
"/ovirt-engine/api/datacenters");
+
+    return domain->priv->data_center_href;
+}
+
 static void ovirt_storage_domain_get_property(GObject *object,
                                               guint prop_id,
                                               GValue *value,
@@ -84,6 +106,12 @@ static void ovirt_storage_domain_get_property(GObject *object,
     case PROP_DATA_CENTER_IDS:
         g_value_set_boxed(value, domain->priv->data_center_ids);
         break;
+    case PROP_DATA_CENTER_HREF:
+        g_value_set_string(value, get_data_center_href(domain));
+        break;
+    case PROP_DATA_CENTER_ID:
+        g_value_set_string(value, domain->priv->data_center_id);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -123,6 +151,14 @@ static void ovirt_storage_domain_set_property(GObject *object,
         g_strfreev(domain->priv->data_center_ids);
         domain->priv->data_center_ids = g_value_dup_boxed(value);
         break;
+    case PROP_DATA_CENTER_HREF:
+        g_free(domain->priv->data_center_href);
+        domain->priv->data_center_href = g_value_dup_string(value);
+        break;
+    case PROP_DATA_CENTER_ID:
+        g_free(domain->priv->data_center_id);
+        domain->priv->data_center_id = g_value_dup_string(value);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -137,6 +173,8 @@ ovirt_storage_domain_dispose(GObject *obj)
 
     g_clear_object(&domain->priv->files);
     g_clear_pointer(&domain->priv->data_center_ids, g_strfreev);
+    g_clear_pointer(&domain->priv->data_center_href, g_free);
+    g_clear_pointer(&domain->priv->data_center_id, g_free);
 
     G_OBJECT_CLASS(ovirt_storage_domain_parent_class)->dispose(obj);
 }
@@ -174,6 +212,14 @@ static gboolean ovirt_storage_domain_init_from_xml(OvirtResource *resource,
           .xml_path = "data_centers",
           .xml_attr = "id",
         },
+        { .prop_name = "data-center-href",
+          .xml_path = "data_center",
+          .xml_attr = "href",
+        },
+        { .prop_name = "data-center-id",
+          .xml_path = "data_center",
+          .xml_attr = "id",
+        },
         { NULL , }
     };
 
@@ -286,6 +332,26 @@ static void ovirt_storage_domain_class_init(OvirtStorageDomainClass *klass)
     g_object_class_install_property(object_class,
                                     PROP_DATA_CENTER_IDS,
                                     param_spec);
+
+    param_spec = g_param_spec_string("data-center-href",
+                                     "Data Center href",
+                                     "Data Center href for the Storage Domain",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(object_class,
+                                    PROP_DATA_CENTER_HREF,
+                                    param_spec);
+
+    param_spec = g_param_spec_string("data-center-id",
+                                     "Data Center Id",
+                                     "Data Center Id for the Storage Domain",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(object_class,
+                                    PROP_DATA_CENTER_ID,
+                                    param_spec);
 }
 
 static void ovirt_storage_domain_init(OvirtStorageDomain *domain)


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