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

[libvirt] [libvirt-glib 3/3] gconfig: Add GVirConfigDomainSnapshot getters/setters



---
 libvirt-gconfig/libvirt-gconfig-domain-snapshot.c | 227 +++++++++++++++++++++-
 libvirt-gconfig/libvirt-gconfig-domain-snapshot.h |  38 +++-
 libvirt-gconfig/libvirt-gconfig.sym               |  15 ++
 3 files changed, 278 insertions(+), 2 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c
index 3d967f1..a3cec0c 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c
@@ -2,7 +2,7 @@
  * libvirt-gconfig-domain-snapshot.c: libvirt domain snapshot configuration
  *
  * Copyright (C) 2008 Daniel P. Berrange
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-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
@@ -19,11 +19,13 @@
  * <http://www.gnu.org/licenses/>.
  *
  * Author: Daniel P. Berrange <berrange redhat com>
+ *         Christophe Fergeau <cfergeau redhat com>
  */
 
 #include <config.h>
 
 #include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
 
 #define GVIR_CONFIG_DOMAIN_SNAPSHOT_GET_PRIVATE(obj)                         \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT, GVirConfigDomainSnapshotPrivate))
@@ -71,3 +73,226 @@ GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new_from_xml(const gchar *
                                     xml, error);
     return GVIR_CONFIG_DOMAIN_SNAPSHOT(object);
 }
+
+
+const char *gvir_config_domain_snapshot_get_name(GVirConfigDomainSnapshot *snapshot)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(snapshot),
+                                               "name");
+}
+
+
+void gvir_config_domain_snapshot_set_name(GVirConfigDomainSnapshot *snapshot,
+                                          const char *name)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+
+    gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(snapshot),
+                                        "name", name);
+}
+
+
+const char *gvir_config_domain_snapshot_get_description(GVirConfigDomainSnapshot *snapshot)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(snapshot),
+                                               "description");
+}
+
+
+void gvir_config_domain_snapshot_set_description(GVirConfigDomainSnapshot *snapshot,
+                                                 const char *description)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+
+    gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(snapshot),
+                                        "description", description);
+}
+
+/*
+const char *gvir_config_domain_snapshot_get_memory(GVirConfigDomainSnapshot *snapshot)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+    return NULL;
+}
+
+
+void gvir_config_domain_snapshot_set_memory(GVirConfigDomainSnapshot *snapshot,
+                                   const char *memory)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+}
+*/
+
+
+/* FIXME: GDateTime is only available since glib 2.26, libvirt-glib depends
+ * on glib 2.22, is the dep ok?
+ */
+GDateTime *gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+    guint64 creation_time;
+
+    creation_time = gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(snapshot),
+                                                               "creationTime");
+    return g_date_time_new_from_unix_utc(creation_time);
+}
+
+
+GVirConfigDomainSnapshotState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot),
+                         GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE);
+
+    return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(snapshot),
+                                                     "state",
+                                                     GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_STATE,
+                                                     GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE);
+}
+
+
+const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot)
+{
+    GVirConfigObject *parent;
+    const char *parent_name;
+
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+    parent = gvir_config_object_get_child(GVIR_CONFIG_OBJECT(snapshot),
+                                          "parent");
+    parent_name = gvir_config_object_get_node_content(parent, "name");
+    g_object_unref(G_OBJECT(parent));
+
+    return parent_name;
+}
+
+
+/**
+ * gvir_config_domain_snapshot_get_domain:
+ * @snapshot: a #GVirConfigDomainSnapshot
+ *
+ * Gets the configuration of the domain @snapshot is a snapshot of.
+ *
+ * Returns: (transfer full): A #GVirConfigDomain. The returned object
+ * should be unreffed with g_object_unref() when no longer needed.
+ */
+GVirConfigDomain *gvir_config_domain_snapshot_get_domain(GVirConfigDomainSnapshot *snapshot)
+{
+    GVirConfigObject *domain;
+
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+    domain = gvir_config_object_get_child_with_type(GVIR_CONFIG_OBJECT(snapshot),
+                                                    "domain",
+                                                    GVIR_CONFIG_TYPE_DOMAIN);
+
+    return GVIR_CONFIG_DOMAIN(domain);
+}
+
+
+/**
+ * gvir_config_domain_snapshot_set_disks:
+ * @snapshot: a #GVirConfigDomainSnapshot
+ * @disks: (in) (element-type LibvirtGConfig.DomainSnapshotDisk):
+ */
+void gvir_config_domain_snapshot_set_disks(GVirConfigDomainSnapshot *snapshot,
+                                           GList *disks)
+{
+    GVirConfigObject *disks_node;
+    GList *it;
+
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+
+    if (disks == NULL) {
+        gvir_config_object_delete_children(GVIR_CONFIG_OBJECT(snapshot),
+                                           "disks",
+                                           NULL);
+        return;
+    }
+
+    disks_node = gvir_config_object_new(GVIR_CONFIG_TYPE_OBJECT,
+                                        "disks", NULL);
+
+    for (it = disks; it != NULL; it = it->next) {
+        if (!GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(it->data)) {
+            g_warn_if_reached();
+            continue;
+        }
+        gvir_config_object_attach_add(disks_node,
+                                      GVIR_CONFIG_OBJECT(it->data));
+    }
+
+    gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(snapshot),
+                                      "disks",
+                                      disks_node);
+    g_object_unref(G_OBJECT(disks_node));
+}
+
+
+void gvir_config_domain_snapshot_add_disk(GVirConfigDomainSnapshot *snapshot,
+                                          GVirConfigDomainSnapshotDisk *disk)
+{
+    GVirConfigObject *disks_node;
+
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk));
+
+    disks_node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(snapshot),
+                                              "disks");
+
+    gvir_config_object_attach_add(disks_node, GVIR_CONFIG_OBJECT(disk));
+    g_object_unref(G_OBJECT(disks_node));
+}
+
+
+struct GetDiskData {
+    GVirConfigXmlDoc *doc;
+    GList *disks;
+};
+
+static gboolean get_disk(xmlNodePtr node, gpointer opaque)
+{
+    struct GetDiskData* data = (struct GetDiskData*)opaque;
+    GVirConfigDomainSnapshotDisk *disk;
+
+    disk = gvir_config_domain_snapshot_disk_new_from_tree(data->doc, node);
+    if (disk != NULL)
+        data->disks = g_list_prepend(data->disks, disk);
+    else
+        g_debug("Failed to parse %s node", node->name);
+
+    return TRUE;
+}
+
+
+/**
+ * gvir_config_domain_snapshot_get_disks:
+ * @snapshot: a #GVirConfigDomainSnapshot
+ *
+ * Gets the list of disks attached to @snapshot.  The returned list should
+ * be freed with g_list_free(), after its elements have been unreffed with
+ * g_object_unref().
+ *
+ * Returns: (element-type LibvirtGConfig.DomainSnapshotDisk) (transfer full):
+ * a newly allocated #GList of #GVirConfigDomainSnapshotDisk.
+ */
+GList *gvir_config_domain_snapshot_get_disks(GVirConfigDomainSnapshot *snapshot)
+{
+    struct GetDiskData data;
+
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+    g_object_get(G_OBJECT(snapshot), "doc", &data.doc, NULL);
+    data.disks = NULL;
+    gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(snapshot), "disks",
+                                     get_disk, &data);
+    if (data.doc != NULL) {
+        g_object_unref(G_OBJECT(data.doc));
+    }
+
+    return g_list_reverse(data.disks);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h
index 49c1d17..7b0884e 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h
@@ -1,7 +1,7 @@
 /*
  * libvirt-gconfig-domain-snapshot.h: libvirt domain snapshot configuration
  *
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-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
@@ -18,6 +18,7 @@
  * <http://www.gnu.org/licenses/>.
  *
  * Author: Daniel P. Berrange <berrange redhat com>
+ *         Christophe Fergeau <cfergeau redhat com>
  */
 
 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
@@ -27,6 +28,9 @@
 #ifndef __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__
 #define __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__
 
+#include <libvirt-gconfig/libvirt-gconfig-domain.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h>
+
 G_BEGIN_DECLS
 
 #define GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT            (gvir_config_domain_snapshot_get_type ())
@@ -56,6 +60,19 @@ struct _GVirConfigDomainSnapshotClass
     gpointer padding[20];
 };
 
+typedef enum {
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE = 0,     /* no state */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_RUNNING = 1,     /* the domain is running */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_BLOCKED = 2,     /* the domain is blocked on resource */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_PAUSED  = 3,     /* the domain is paused by user */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_SHUTDOWN= 4,     /* the domain is being shut down */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_SHUTOFF = 5,     /* the domain is shut off */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_CRASHED = 6,     /* the domain is crashed */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_PMSUSPENDED = 7, /* the domain is suspended by guest
+                                                          power management */
+    GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_DISK_SNAPSHOT = 100
+} GVirConfigDomainSnapshotState;
+
 
 GType gvir_config_domain_snapshot_get_type(void);
 
@@ -63,6 +80,25 @@ GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new(void);
 GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new_from_xml(const gchar *xml,
                                                                    GError **error);
 
+const char *gvir_config_domain_snapshot_get_name(GVirConfigDomainSnapshot *snapshot);
+void gvir_config_domain_snapshot_set_name(GVirConfigDomainSnapshot *snapshot,
+                                          const char *name);
+const char *gvir_config_domain_snapshot_get_description(GVirConfigDomainSnapshot *snapshot);
+void gvir_config_domain_snapshot_set_description(GVirConfigDomainSnapshot *snapshot,
+                                                 const char *description);
+/*const char *gvir_config_domain_snapshot_get_memory(GVirConfigDomainSnapshot *snapshot);
+void gvir_config_domain_snapshot_set_memory(GVirConfigDomainSnapshot *snapshot,
+                                   const char *memory);*/
+GDateTime *gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot);
+GVirConfigDomainSnapshotState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot);
+const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot);
+GVirConfigDomain *gvir_config_domain_snapshot_get_domain(GVirConfigDomainSnapshot *snapshot);
+void gvir_config_domain_snapshot_set_disks(GVirConfigDomainSnapshot *snapshot,
+                                           GList *disks);
+void gvir_config_domain_snapshot_add_disk(GVirConfigDomainSnapshot *snapshot,
+                                          GVirConfigDomainSnapshotDisk *disk);
+GList *gvir_config_domain_snapshot_get_disks(GVirConfigDomainSnapshot *snapshot);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index e8b4efe..16228fb 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -558,6 +558,21 @@ LIBVIRT_GCONFIG_0.1.7 {
 	gvir_config_storage_pool_target_get_path;
 	gvir_config_storage_pool_target_get_permissions;
 
+	gvir_config_domain_snapshot_state_get_type;
+	gvir_config_domain_snapshot_get_creation_time;
+	gvir_config_domain_snapshot_get_description;
+	gvir_config_domain_snapshot_set_description;
+	gvir_config_domain_snapshot_get_domain;
+	gvir_config_domain_snapshot_get_memory;
+	gvir_config_domain_snapshot_set_memory;
+	gvir_config_domain_snapshot_get_name;
+	gvir_config_domain_snapshot_set_name;
+	gvir_config_domain_snapshot_get_parent;
+	gvir_config_domain_snapshot_get_state;
+	gvir_config_domain_snapshot_get_disks;
+	gvir_config_domain_snapshot_add_disk;
+	gvir_config_domain_snapshot_set_disks;
+
 	gvir_config_domain_snapshot_disk_get_type;
 	gvir_config_domain_snapshot_disk_new;
 	gvir_config_domain_snapshot_disk_new_from_xml;
-- 
1.8.1.4


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