[libgovirt] Implement ovirt_storage_domain_new_from_xml()



commit 5be75be3323a9514e9944bcc40fa2d63d0ae271c
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Tue Aug 20 21:20:16 2013 +0200

    Implement ovirt_storage_domain_new_from_xml()

 govirt/Makefile.am                    |    1 +
 govirt/govirt-private.h               |    1 +
 govirt/govirt.sym                     |    1 +
 govirt/ovirt-storage-domain-private.h |   35 +++++++++++
 govirt/ovirt-storage-domain.c         |  102 +++++++++++++++++++++++++++++++++
 govirt/ovirt-storage-domain.h         |    2 +
 6 files changed, 142 insertions(+), 0 deletions(-)
---
diff --git a/govirt/Makefile.am b/govirt/Makefile.am
index 4d40b8c..4a57487 100644
--- a/govirt/Makefile.am
+++ b/govirt/Makefile.am
@@ -35,6 +35,7 @@ noinst_HEADERS =                                              \
        ovirt-proxy-private.h                                   \
        ovirt-resource-private.h                                \
        ovirt-rest-call.h                                       \
+       ovirt-storage-domain-private.h                          \
        ovirt-utils.h                                           \
        ovirt-vm-private.h                                      \
        $(NULL)
diff --git a/govirt/govirt-private.h b/govirt/govirt-private.h
index 474388e..cd6c3f7 100644
--- a/govirt/govirt-private.h
+++ b/govirt/govirt-private.h
@@ -28,6 +28,7 @@
 #include <govirt/ovirt-proxy-private.h>
 #include <govirt/ovirt-resource-private.h>
 #include <govirt/ovirt-rest-call.h>
+#include <govirt/ovirt-storage-domain-private.h>
 #include <govirt/ovirt-utils.h>
 #include <govirt/ovirt-vm-private.h>
 #include <govirt/glib-compat.h>
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
index 62fb8b1..578ff0a 100644
--- a/govirt/govirt.sym
+++ b/govirt/govirt.sym
@@ -67,6 +67,7 @@ GOVIRT_0.2.1 {
         ovirt_storage_domain_state_get_type;
         ovirt_storage_domain_format_version_get_type;
         ovirt_storage_domain_type_get_type;
+        ovirt_storage_domain_new;
 } GOVIRT_0.2.0;
 
 
diff --git a/govirt/ovirt-storage-domain-private.h b/govirt/ovirt-storage-domain-private.h
new file mode 100644
index 0000000..5db27a0
--- /dev/null
+++ b/govirt/ovirt-storage-domain-private.h
@@ -0,0 +1,35 @@
+/*
+ * ovirt-storage-domain-private.h: oVirt storage domain resource
+ *
+ * Copyright (C) 2012, 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Christophe Fergeau <cfergeau redhat com>
+ */
+#ifndef __OVIRT_STORAGE_DOMAIN_PRIVATE_H__
+#define __OVIRT_STORAGE_DOMAIN_PRIVATE_H__
+
+#include <ovirt-storage-domain.h>
+#include <rest/rest-xml-node.h>
+
+G_BEGIN_DECLS
+
+OvirtStorageDomain *ovirt_storage_domain_new_from_xml(RestXmlNode *node,
+                                                      GError **error);
+
+G_END_DECLS
+
+#endif /* __OVIRT_STORAGE_DOMAIN_PRIVATE_H__ */
diff --git a/govirt/ovirt-storage-domain.c b/govirt/ovirt-storage-domain.c
index 10159ad..916e94a 100644
--- a/govirt/ovirt-storage-domain.c
+++ b/govirt/ovirt-storage-domain.c
@@ -23,6 +23,7 @@
 #include <config.h>
 #include "ovirt-enum-types.h"
 #include "ovirt-storage-domain.h"
+#include "govirt-private.h"
 
 #define OVIRT_STORAGE_DOMAIN_GET_PRIVATE(obj)                         \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), OVIRT_TYPE_STORAGE_DOMAIN, OvirtStorageDomainPrivate))
@@ -50,6 +51,10 @@ enum {
     PROP_STATE
 };
 
+static gboolean
+ovirt_storage_domain_refresh_from_xml(OvirtStorageDomain *domain,
+                                      RestXmlNode *node);
+
 static void ovirt_storage_domain_get_property(GObject *object,
                                               guint prop_id,
                                               GValue *value,
@@ -120,13 +125,33 @@ static void ovirt_storage_domain_set_property(GObject *object,
     }
 }
 
+static gboolean ovirt_storage_domain_init_from_xml(OvirtResource *resource,
+                                                   RestXmlNode *node,
+                                                   GError **error)
+{
+    gboolean parsed_ok;
+    OvirtResourceClass *parent_class;
+    OvirtStorageDomain *domain;
+
+    domain = OVIRT_STORAGE_DOMAIN(resource);
+    parsed_ok = ovirt_storage_domain_refresh_from_xml(domain, node);
+    if (!parsed_ok) {
+        return FALSE;
+    }
+    parent_class = OVIRT_RESOURCE_CLASS(ovirt_storage_domain_parent_class);
+
+    return parent_class->init_from_xml(resource, node, error);
+}
+
 static void ovirt_storage_domain_class_init(OvirtStorageDomainClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
+    OvirtResourceClass *resource_class = OVIRT_RESOURCE_CLASS(klass);
     GParamSpec *param_spec;
 
     g_type_class_add_private(klass, sizeof(OvirtStorageDomainPrivate));
 
+    resource_class->init_from_xml = ovirt_storage_domain_init_from_xml;
     object_class->get_property = ovirt_storage_domain_get_property;
     object_class->set_property = ovirt_storage_domain_set_property;
 
@@ -214,3 +239,80 @@ static void ovirt_storage_domain_init(OvirtStorageDomain *domain)
 {
     domain->priv = OVIRT_STORAGE_DOMAIN_GET_PRIVATE(domain);
 }
+
+G_GNUC_INTERNAL
+OvirtStorageDomain *ovirt_storage_domain_new_from_xml(RestXmlNode *node,
+                                                      GError **error)
+{
+    GObject *domain;
+
+    domain = g_initable_new(OVIRT_TYPE_STORAGE_DOMAIN, NULL, error,
+                            "xml-node", node, NULL);
+
+    return OVIRT_STORAGE_DOMAIN(domain);
+}
+
+OvirtStorageDomain *ovirt_storage_domain_new(void)
+{
+    GObject *domain;
+
+    domain = g_initable_new(OVIRT_TYPE_STORAGE_DOMAIN, NULL, NULL, NULL);
+
+    return OVIRT_STORAGE_DOMAIN(domain);
+}
+
+static gboolean
+ovirt_storage_domain_refresh_from_xml(OvirtStorageDomain *domain,
+                                      RestXmlNode *node)
+{
+    const char *available;
+    const char *committed;
+    const char *master;
+    const char *state;
+    const char *type;
+    const char *used;
+    const char *version;
+
+    type = ovirt_rest_xml_node_get_content(node, "type", NULL);
+    if (type != NULL) {
+        domain->priv->state = ovirt_utils_genum_get_value(OVIRT_TYPE_STORAGE_DOMAIN_TYPE,
+                                                          type,
+                                                          OVIRT_STORAGE_DOMAIN_TYPE_DATA);
+    }
+
+    master = ovirt_rest_xml_node_get_content(node, "master", NULL);
+    if (master != NULL) {
+        domain->priv->is_master = ovirt_utils_boolean_from_string(master);
+    }
+
+    available = ovirt_rest_xml_node_get_content(node, "available", NULL);
+    if (available != NULL) {
+        domain->priv->available = g_ascii_strtoull(available, NULL, 0);
+    }
+
+    used = ovirt_rest_xml_node_get_content(node, "used", NULL);
+    if (used != NULL) {
+        domain->priv->used = g_ascii_strtoull(used, NULL, 0);
+    }
+
+    committed = ovirt_rest_xml_node_get_content(node, "committed", NULL);
+    if (committed != NULL) {
+        domain->priv->committed = g_ascii_strtoull(committed, NULL, 0);
+    }
+
+    version = ovirt_rest_xml_node_get_content(node, "storage_format", NULL);
+    if (version != NULL) {
+        domain->priv->version = ovirt_utils_genum_get_value(OVIRT_TYPE_STORAGE_DOMAIN_FORMAT_VERSION,
+                                                           version,
+                                                           OVIRT_STORAGE_DOMAIN_FORMAT_VERSION_V1);
+    }
+
+    state = ovirt_rest_xml_node_get_content(node, "storage_domain_state", NULL);
+    if (state != NULL)  {
+        domain->priv->state = ovirt_utils_genum_get_value(OVIRT_TYPE_STORAGE_DOMAIN_STATE,
+                                                          state,
+                                                          OVIRT_STORAGE_DOMAIN_STATE_UNKNOWN);
+    }
+
+    return TRUE;
+}
diff --git a/govirt/ovirt-storage-domain.h b/govirt/ovirt-storage-domain.h
index 2967f9d..ddd78c0 100644
--- a/govirt/ovirt-storage-domain.h
+++ b/govirt/ovirt-storage-domain.h
@@ -80,6 +80,8 @@ struct _OvirtStorageDomainClass
 
 GType ovirt_storage_domain_get_type(void);
 
+OvirtStorageDomain *ovirt_storage_domain_new(void);
+
 G_END_DECLS
 
 #endif /* __OVIRT_STORAGE_DOMAIN_H__ */


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