---
libvirt-gconfig/libvirt-gconfig-domain-snapshot.c | 252 +++++++++++++++++++++-
libvirt-gconfig/libvirt-gconfig-domain-snapshot.h | 48 ++++-
libvirt-gconfig/libvirt-gconfig.sym | 18 ++
3 files changed, 316 insertions(+), 2 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c
b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c
index 3d967f1..fc9a130 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(a)redhat.com>
+ * Christophe Fergeau <cfergeau(a)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,251 @@ 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);
+}
+
+
+GVirConfigDomainSnapshotMemoryState
gvir_config_domain_snapshot_get_memory_state(GVirConfigDomainSnapshot *snapshot)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot),
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_NONE);
+
+ return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(snapshot),
+ "memory",
"snapshot",
+
GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_MEMORY_STATE,
+
GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_NONE);
+}
+
+
+void gvir_config_domain_snapshot_set_memory_state(GVirConfigDomainSnapshot *snapshot,
+ GVirConfigDomainSnapshotMemoryState
state)
+{
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+
+ gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(snapshot),
+ "memory",
"snapshot",
+
GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_MEMORY_STATE,
+ state);
+}
+
+
+const char *gvir_config_domain_snapshot_get_memory_file(GVirConfigDomainSnapshot
*snapshot)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL);
+
+ return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(snapshot),
+ "memory", "file");
+}
+
+
+void gvir_config_domain_snapshot_set_memory_file(GVirConfigDomainSnapshot *snapshot,
+ const char *filename)
+{
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot));
+
+ gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(snapshot),
+ "memory", "file",
filename);
+}
+
+
+time_t gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), 0);
+
+ return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(snapshot),
+ "creationTime");
+}
+
+
+GVirConfigDomainSnapshotDomainState
gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot),
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_NOSTATE);
+
+ return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(snapshot),
+ "state",
+
GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DOMAIN_STATE,
+
GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_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");
+ if (parent == NULL)
+ return NULL;
+
+ 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..00d7019 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(a)redhat.com>
+ * Christophe Fergeau <cfergeau(a)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,26 @@ struct _GVirConfigDomainSnapshotClass
gpointer padding[20];
};
+typedef enum {
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_NOSTATE = 0, /* no state */
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_RUNNING = 1, /* the domain is running
*/
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_BLOCKED = 2, /* the domain is blocked on
resource */
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_PAUSED = 3, /* the domain is paused by
user */
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_SHUTDOWN= 4, /* the domain is being shut
down */
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_SHUTOFF = 5, /* the domain is shut off
*/
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_CRASHED = 6, /* the domain is crashed
*/
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_PMSUSPENDED = 7, /* the domain is suspended
by guest
+ power management */
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_DISK_SNAPSHOT = 100
+} GVirConfigDomainSnapshotDomainState;
+
+
+typedef enum {
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_NONE,
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_INTERNAL,
+ GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_EXTERNAL,
+} GVirConfigDomainSnapshotMemoryState;
+
GType gvir_config_domain_snapshot_get_type(void);
@@ -63,6 +87,28 @@ 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);
+GVirConfigDomainSnapshotMemoryState
gvir_config_domain_snapshot_get_memory_state(GVirConfigDomainSnapshot *snapshot);
+void gvir_config_domain_snapshot_set_memory_state(GVirConfigDomainSnapshot *snapshot,
+ GVirConfigDomainSnapshotMemoryState
state);
+const char *gvir_config_domain_snapshot_get_memory_file(GVirConfigDomainSnapshot
*snapshot);
+void gvir_config_domain_snapshot_set_memory_file(GVirConfigDomainSnapshot *snapshot,
+ const char *filename);
+time_t gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot
*snapshot);
+GVirConfigDomainSnapshotDomainState
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 a318e9e..0197f46 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -562,6 +562,24 @@ LIBVIRT_GCONFIG_0.1.7 {
gvir_config_storage_pool_target_get_path;
gvir_config_storage_pool_target_get_permissions;
+ gvir_config_domain_snapshot_domain_state_get_type;
+ gvir_config_domain_snapshot_memory_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_state;
+ gvir_config_domain_snapshot_set_memory_state;
+ gvir_config_domain_snapshot_get_memory_file;
+ gvir_config_domain_snapshot_set_memory_file;
+ 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.2.1