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

[libvirt] [libvirt-glib 6/7] API to get/set custom metadata from/to domain config



Based on a patch from Zeeshan Ali (Khattak) <zeeshanak gnome org>
---
 libvirt-gconfig/libvirt-gconfig-domain.c |   67 ++++++++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain.h |    7 +++
 libvirt-gconfig/libvirt-gconfig.sym      |    2 +
 3 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index 61af625..d7ac4c6 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -449,3 +449,70 @@ GList *gvir_config_domain_get_devices(GVirConfigDomain *domain)
 
     return data.devices;
 }
+
+gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
+                                           const gchar *xml,
+                                           const gchar *ns,
+                                           const gchar *ns_uri,
+                                           GError **error)
+{
+    GVirConfigObject *metadata;
+    GVirConfigObject *custom_xml;
+
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN(domain), FALSE);
+    g_return_val_if_fail(xml != NULL, FALSE);
+    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+
+    metadata = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(domain),
+                                            "metadata");
+
+    custom_xml = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_OBJECT,
+                                                 NULL, NULL, xml, error);
+    if (custom_xml == NULL) {
+        g_assert_not_reached();
+        g_object_unref(G_OBJECT(metadata));
+        return FALSE;
+    }
+
+    gvir_config_object_set_namespace(custom_xml, ns, ns_uri);
+
+    gvir_config_object_delete_children(metadata, NULL, ns_uri);
+    gvir_config_object_attach_add(metadata, custom_xml);
+    g_object_unref(G_OBJECT(metadata));
+
+    return TRUE;
+}
+
+struct LookupNamespacedNodeData {
+    const char *ns_uri;
+    xmlNodePtr node;
+};
+
+static gboolean lookup_namespaced_node(xmlNodePtr node, gpointer opaque)
+{
+    struct LookupNamespacedNodeData* data = opaque;
+
+    if (node->ns == NULL)
+        return TRUE;
+
+    if (g_strcmp0((char *)node->ns->href, data->ns_uri) == 0) {
+        data->node = node;
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
+                                         const gchar *ns_uri)
+{
+    struct LookupNamespacedNodeData data = { NULL, NULL };
+
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN(domain), NULL);
+    g_return_val_if_fail(ns_uri != NULL, NULL);
+
+    data.ns_uri = ns_uri;
+    gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(domain), "metadata",
+                                     lookup_namespaced_node, &data);
+    return gvir_config_xml_node_to_string(data.node);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
index 6cdaec9..769d2f0 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -126,6 +126,13 @@ GList *gvir_config_domain_get_devices(GVirConfigDomain *domain);
 void gvir_config_domain_set_lifecycle(GVirConfigDomain *domain,
                                       GVirConfigDomainLifecycleEvent event,
                                       GVirConfigDomainLifecycleAction action);
+gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
+                                           const gchar *xml,
+                                           const gchar *ns,
+                                           const gchar *ns_uri,
+                                           GError **error);
+gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
+                                         const gchar *ns_uri);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 88aef57..ab2c7bf 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -14,6 +14,8 @@ LIBVIRT_GCONFIG_0.0.4 {
 	gvir_config_domain_new;
 	gvir_config_domain_new_from_xml;
 	gvir_config_domain_set_clock;
+	gvir_config_domain_set_custom_xml;
+	gvir_config_domain_get_custom_xml;
 	gvir_config_domain_get_description;
 	gvir_config_domain_set_description;
 	gvir_config_domain_get_devices;
-- 
1.7.7.6


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